-
Notifications
You must be signed in to change notification settings - Fork 14.3k
AMDGPU: Do not assert on unhandled types when demangling libcalls #120068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 4 commits into
main
from
users/arsenm/amdgpu-simplify-libcall-check-unknown-types
Dec 16, 2024
Merged
AMDGPU: Do not assert on unhandled types when demangling libcalls #120068
arsenm
merged 4 commits into
main
from
users/arsenm/amdgpu-simplify-libcall-check-unknown-types
Dec 16, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/120068.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
index 9f192a9d50c318..264b4d43248c69 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
@@ -957,8 +957,15 @@ static Type* getIntrinsicParamType(
case AMDGPULibFunc::EVENT:
T = PointerType::getUnqual(C);
break;
- default:
- llvm_unreachable("Unhandled param type");
+ case AMDGPULibFunc::B8:
+ case AMDGPULibFunc::B16:
+ case AMDGPULibFunc::B32:
+ case AMDGPULibFunc::B64:
+ case AMDGPULibFunc::SIZE_MASK:
+ case AMDGPULibFunc::FLOAT:
+ case AMDGPULibFunc::INT:
+ case AMDGPULibFunc::UINT:
+ case AMDGPULibFunc::DUMMY:
return nullptr;
}
if (P.VectorSize > 1)
@@ -974,8 +981,13 @@ FunctionType *AMDGPUMangledLibFunc::getFunctionType(const Module &M) const {
std::vector<Type*> Args;
ParamIterator I(Leads, manglingRules[FuncId]);
Param P;
- while ((P=I.getNextParam()).ArgType != 0)
- Args.push_back(getIntrinsicParamType(C, P, true));
+ while ((P = I.getNextParam()).ArgType != 0) {
+ Type *ParamTy = getIntrinsicParamType(C, P, true);
+ if (!ParamTy)
+ return nullptr;
+
+ Args.push_back(ParamTy);
+ }
return FunctionType::get(
getIntrinsicParamType(C, getRetType(FuncId, Leads), true),
@@ -1001,10 +1013,15 @@ bool AMDGPULibFunc::isCompatibleSignature(const Module &M,
const FunctionType *CallTy) const {
const FunctionType *FuncTy = getFunctionType(M);
- // FIXME: UnmangledFuncInfo does not have any type information other than the
- // number of arguments.
- if (!FuncTy)
+ if (!FuncTy) {
+ // Give up on mangled functions with unexpected types.
+ if (AMDGPULibFuncBase::isMangled(getId()))
+ return false;
+
+ // FIXME: UnmangledFuncInfo does not have any type information other than
+ // the number of arguments.
return getNumArgs() == CallTy->getNumParams();
+ }
// Normally the types should exactly match.
if (FuncTy == CallTy)
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll
new file mode 100644
index 00000000000000..96e6a457948b4f
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-simplifylib -amdgpu-prelink %s | FileCheck %s
+; Make sure there are no crashes on unexpected types
+
+%struct.vfloat3 = type { float, float, float }
+
+declare hidden %struct.vfloat3 @_Z3mix7vfloat3S_f(float, float, float, float, float, float, float) #1
+
+define %struct.vfloat3 @_Z8test_mix7vfloat3S_f(float %x.coerce0, float %x.coerce1, float %x.coerce2, float %y.coerce0, float %y.coerce1, float %y.coerce2, float %t) {
+; CHECK-LABEL: define %struct.vfloat3 @_Z8test_mix7vfloat3S_f(
+; CHECK-SAME: float [[X_COERCE0:%.*]], float [[X_COERCE1:%.*]], float [[X_COERCE2:%.*]], float [[Y_COERCE0:%.*]], float [[Y_COERCE1:%.*]], float [[Y_COERCE2:%.*]], float [[T:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[CALL:%.*]] = call [[STRUCT_VFLOAT3:%.*]] @[[_Z3MIX7VFLOAT3S_F:[a-zA-Z0-9_$\"\\.-]*[a-zA-Z_$\"\\.-][a-zA-Z0-9_$\"\\.-]*]](float [[X_COERCE0]], float [[X_COERCE1]], float [[X_COERCE2]], float [[Y_COERCE0]], float [[Y_COERCE1]], float [[Y_COERCE2]], float [[T]])
+; CHECK-NEXT: ret [[STRUCT_VFLOAT3]] [[CALL]]
+;
+entry:
+ %call = call %struct.vfloat3 @_Z3mix7vfloat3S_f(float %x.coerce0, float %x.coerce1, float %x.coerce2, float %y.coerce0, float %y.coerce1, float %y.coerce2, float %t)
+ ret %struct.vfloat3 %call
+}
+
+
+
|
Thanks for the quick response |
arsenm
commented
Dec 16, 2024
llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll
Outdated
Show resolved
Hide resolved
arsenm
commented
Dec 16, 2024
llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll
Outdated
Show resolved
Hide resolved
arsenm
commented
Dec 16, 2024
llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-unexpected-types.ll
Outdated
Show resolved
Hide resolved
shiltian
approved these changes
Dec 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.