Skip to content

Commit b07be69

Browse files
Leonid Pauzinvmaksimo
authored andcommitted
Fix umul.with.overflow.ll test fails
Original commit: KhronosGroup/SPIRV-LLVM-Translator@28a37e6
1 parent 18c9264 commit b07be69

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,8 +2777,19 @@ Function *SPIRVToLLVM::transFunction(SPIRVFunction *BF) {
27772777
F = cast<Function>(mapValue(BF, F));
27782778
mapFunction(BF, F);
27792779

2780-
if (F->isIntrinsic())
2781-
return F;
2780+
if (F->isIntrinsic()) {
2781+
if (F->getIntrinsicID() != Intrinsic::umul_with_overflow)
2782+
return F;
2783+
std::string Name = F->getName().str();
2784+
auto *ST = dyn_cast<StructType>(F->getReturnType());
2785+
auto *FT = F->getFunctionType();
2786+
auto *NewST = StructType::get(ST->getContext(), ST->elements());
2787+
auto *NewFT = FunctionType::get(NewST, FT->params(), FT->isVarArg());
2788+
F->setName("old_" + Name);
2789+
auto *NewFn = Function::Create(NewFT, F->getLinkage(), F->getAddressSpace(),
2790+
Name, F->getParent());
2791+
return NewFn;
2792+
}
27822793

27832794
F->setCallingConv(IsKernel ? CallingConv::SPIR_KERNEL
27842795
: CallingConv::SPIR_FUNC);

llvm-spirv/test/llvm-intrinsics/umul.with.overflow.ll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
1616
target triple = "spir"
1717

18-
; CHECK-LLVM: [[UMUL_8_TY:%structtype]] = type { i8, i1 }
19-
; CHECK-LLVM: [[UMUL_32_TY:%structtype.[0-9]+]] = type { i32, i1 }
20-
; CHECK-LLVM: [[UMUL_VEC64_TY:%structtype.[0-9]+]] = type { <2 x i64>, <2 x i1> }
21-
2218
; Function Attrs: nofree nounwind writeonly
2319
define dso_local spir_func void @_Z4foo8hhPh(i8 zeroext %a, i8 zeroext %b, i8* nocapture %c) local_unnamed_addr #0 {
2420
entry:
25-
; CHECK-LLVM: call [[UMUL_8_TY]] @llvm.umul.with.overflow.i8
21+
; CHECK-LLVM: call { i8, i1 } @llvm.umul.with.overflow.i8
2622
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_8]]
2723
%umul = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 %b)
2824
%cmp = extractvalue { i8, i1 } %umul, 1
@@ -45,7 +41,7 @@ entry:
4541
; Function Attrs: nofree nounwind writeonly
4642
define dso_local spir_func void @_Z5foo32jjPj(i32 %a, i32 %b, i32* nocapture %c) local_unnamed_addr #0 {
4743
entry:
48-
; CHECK-LLVM: call [[UMUL_32_TY]] @llvm.umul.with.overflow.i32
44+
; CHECK-LLVM: call { i32, i1 } @llvm.umul.with.overflow.i32
4945
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_32]]
5046
%umul = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %b, i32 %a)
5147
%umul.val = extractvalue { i32, i1 } %umul, 0
@@ -57,7 +53,7 @@ entry:
5753

5854
; Function Attrs: nofree nounwind writeonly
5955
define dso_local spir_func void @umulo_v2i64(<2 x i64> %a, <2 x i64> %b, <2 x i64>* %p) nounwind {
60-
; CHECK-LLVM: call [[UMUL_VEC64_TY]] @llvm.umul.with.overflow.v2i64
56+
; CHECK-LLVM: call { <2 x i64>, <2 x i1> } @llvm.umul.with.overflow.v2i64
6157
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_VEC_I64]]
6258
%umul = call {<2 x i64>, <2 x i1>} @llvm.umul.with.overflow.v2i64(<2 x i64> %a, <2 x i64> %b)
6359
%umul.val = extractvalue {<2 x i64>, <2 x i1>} %umul, 0

0 commit comments

Comments
 (0)