Skip to content

Commit d866005

Browse files
authored
AMDGPU: Do not assert on unhandled types when demangling libcalls (#120068)
1 parent 93fab6e commit d866005

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,15 @@ static Type* getIntrinsicParamType(
957957
case AMDGPULibFunc::EVENT:
958958
T = PointerType::getUnqual(C);
959959
break;
960-
default:
961-
llvm_unreachable("Unhandled param type");
960+
case AMDGPULibFunc::B8:
961+
case AMDGPULibFunc::B16:
962+
case AMDGPULibFunc::B32:
963+
case AMDGPULibFunc::B64:
964+
case AMDGPULibFunc::SIZE_MASK:
965+
case AMDGPULibFunc::FLOAT:
966+
case AMDGPULibFunc::INT:
967+
case AMDGPULibFunc::UINT:
968+
case AMDGPULibFunc::DUMMY:
962969
return nullptr;
963970
}
964971
if (P.VectorSize > 1)
@@ -974,8 +981,13 @@ FunctionType *AMDGPUMangledLibFunc::getFunctionType(const Module &M) const {
974981
std::vector<Type*> Args;
975982
ParamIterator I(Leads, manglingRules[FuncId]);
976983
Param P;
977-
while ((P=I.getNextParam()).ArgType != 0)
978-
Args.push_back(getIntrinsicParamType(C, P, true));
984+
while ((P = I.getNextParam()).ArgType != 0) {
985+
Type *ParamTy = getIntrinsicParamType(C, P, true);
986+
if (!ParamTy)
987+
return nullptr;
988+
989+
Args.push_back(ParamTy);
990+
}
979991

980992
return FunctionType::get(
981993
getIntrinsicParamType(C, getRetType(FuncId, Leads), true),
@@ -1001,10 +1013,15 @@ bool AMDGPULibFunc::isCompatibleSignature(const Module &M,
10011013
const FunctionType *CallTy) const {
10021014
const FunctionType *FuncTy = getFunctionType(M);
10031015

1004-
// FIXME: UnmangledFuncInfo does not have any type information other than the
1005-
// number of arguments.
1006-
if (!FuncTy)
1016+
if (!FuncTy) {
1017+
// Give up on mangled functions with unexpected types.
1018+
if (AMDGPULibFuncBase::isMangled(getId()))
1019+
return false;
1020+
1021+
// FIXME: UnmangledFuncInfo does not have any type information other than
1022+
// the number of arguments.
10071023
return getNumArgs() == CallTy->getNumParams();
1024+
}
10081025

10091026
// Normally the types should exactly match.
10101027
if (FuncTy == CallTy)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-simplifylib -amdgpu-prelink %s | FileCheck %s
3+
; Make sure there are no crashes on unexpected types
4+
5+
%struct.vfloat3 = type { float, float, float }
6+
7+
declare hidden %struct.vfloat3 @_Z3mix7vfloat3S_f(float, float, float, float, float, float, float)
8+
9+
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) {
10+
; CHECK-LABEL: define %struct.vfloat3 @_Z8test_mix7vfloat3S_f(
11+
; CHECK-SAME: float [[X_COERCE0:%.*]], float [[X_COERCE1:%.*]], float [[X_COERCE2:%.*]], float [[Y_COERCE0:%.*]], float [[Y_COERCE1:%.*]], float [[Y_COERCE2:%.*]], float [[T:%.*]]) {
12+
; CHECK-NEXT: [[ENTRY:.*:]]
13+
; 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]])
14+
; CHECK-NEXT: ret [[STRUCT_VFLOAT3]] [[CALL]]
15+
;
16+
entry:
17+
%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)
18+
ret %struct.vfloat3 %call
19+
}

0 commit comments

Comments
 (0)