1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3 ; CHECK-SPIRV: OpName %[[#NAME_UMUL_FUNC_8:]] "spirv.llvm_umul_with_overflow_i8"
4 ; CHECK-SPIRV: OpName %[[#NAME_UMUL_FUNC_32:]] "spirv.llvm_umul_with_overflow_i32"
5 ; CHECK-SPIRV: OpName %[[#NAME_UMUL_FUNC_VEC_I64:]] "spirv.llvm_umul_with_overflow_v2i64"
7 define dso_local spir_func void @_Z4foo8hhPh(i8 zeroext %a, i8 zeroext %b, i8* nocapture %c) local_unnamed_addr {
9 ; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#]] %[[#NAME_UMUL_FUNC_8]]
10 %umul = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 %b)
11 %cmp = extractvalue { i8, i1 } %umul, 1
12 %umul.value = extractvalue { i8, i1 } %umul, 0
13 %storemerge = select i1 %cmp, i8 0, i8 %umul.value
14 store i8 %storemerge, i8* %c, align 1
18 define dso_local spir_func void @_Z5foo32jjPj(i32 %a, i32 %b, i32* nocapture %c) local_unnamed_addr {
20 ; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#]] %[[#NAME_UMUL_FUNC_32]]
21 %umul = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %b, i32 %a)
22 %umul.val = extractvalue { i32, i1 } %umul, 0
23 %umul.ov = extractvalue { i32, i1 } %umul, 1
24 %spec.select = select i1 %umul.ov, i32 0, i32 %umul.val
25 store i32 %spec.select, i32* %c, align 4
29 define dso_local spir_func void @umulo_v2i64(<2 x i64> %a, <2 x i64> %b, <2 x i64>* %p) nounwind {
30 ; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#]] %[[#NAME_UMUL_FUNC_VEC_I64]]
31 %umul = call {<2 x i64>, <2 x i1>} @llvm.umul.with.overflow.v2i64(<2 x i64> %a, <2 x i64> %b)
32 %umul.val = extractvalue {<2 x i64>, <2 x i1>} %umul, 0
33 %umul.ov = extractvalue {<2 x i64>, <2 x i1>} %umul, 1
34 %zero = alloca <2 x i64>, align 16
35 %spec.select = select <2 x i1> %umul.ov, <2 x i64> <i64 0, i64 0>, <2 x i64> %umul.val
36 store <2 x i64> %spec.select, <2 x i64>* %p
40 ; CHECK-SPIRV: %[[#NAME_UMUL_FUNC_8]] = OpFunction %[[#]]
41 ; CHECK-SPIRV: %[[#VAR_A:]] = OpFunctionParameter %[[#]]
42 ; CHECK-SPIRV: %[[#VAR_B:]] = OpFunctionParameter %[[#]]
43 ; CHECK-SPIRV: %[[#MUL_RES:]] = OpIMul %[[#]] %[[#VAR_A]] %[[#VAR_B]]
44 ; CHECK-SPIRV: %[[#DIV_RES:]] = OpUDiv %[[#]] %[[#MUL_RES]] %[[#VAR_A]]
45 ; CHECK-SPIRV: %[[#CMP_RES:]] = OpINotEqual %[[#]] %[[#VAR_A]] %[[#DIV_RES]]
46 ; CHECK-SPIRV: %[[#INSERT_RES:]] = OpCompositeInsert %[[#]] %[[#MUL_RES]]
47 ; CHECK-SPIRV: %[[#INSERT_RES_1:]] = OpCompositeInsert %[[#]] %[[#CMP_RES]] %[[#INSERT_RES]]
48 ; CHECK-SPIRV: OpReturnValue %[[#INSERT_RES_1]]
50 declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8)
52 declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32)
54 declare {<2 x i64>, <2 x i1>} @llvm.umul.with.overflow.v2i64(<2 x i64>, <2 x i64>)