| 1 |
; RUN: llvm-as %s -o %t.bc |
| 2 |
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV |
| 3 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 4 |
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc |
| 5 |
|
| 6 |
; On LLVM level, we'll check that the intrinsics were generated again in reverse |
| 7 |
; translation, replacing the SPIR-V level implementations. |
| 8 |
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM \ |
| 9 |
; RUN: "--implicit-check-not=declare {{.*}} @spirv.llvm_umul_with_overflow_{{.*}}" \ |
| 10 |
; RUN: "--implicit-check-not=old_llvm.umul.with.overflow.{{.*}}" |
| 11 |
|
| 12 |
; CHECK-SPIRV: Name [[NAME_UMUL_FUNC_8:[0-9]+]] "spirv.llvm_umul_with_overflow_i8" |
| 13 |
; CHECK-SPIRV: Name [[NAME_UMUL_FUNC_32:[0-9]+]] "spirv.llvm_umul_with_overflow_i32" |
| 14 |
; CHECK-SPIRV: Name [[NAME_UMUL_FUNC_VEC_I64:[0-9]+]] "spirv.llvm_umul_with_overflow_v2i64" |
| 15 |
|
| 16 |
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" |
| 17 |
target triple = "spir" |
| 18 |
|
| 19 |
; Function Attrs: nofree nounwind writeonly |
| 20 |
define dso_local spir_func void @_Z4foo8hhPh(i8 zeroext %a, i8 zeroext %b, i8* nocapture %c) local_unnamed_addr #0 { |
| 21 |
entry: |
| 22 |
; CHECK-LLVM: call { i8, i1 } @llvm.umul.with.overflow.i8 |
| 23 |
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_8]] |
| 24 |
%umul = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 %b) |
| 25 |
%cmp = extractvalue { i8, i1 } %umul, 1 |
| 26 |
%umul.value = extractvalue { i8, i1 } %umul, 0 |
| 27 |
%storemerge = select i1 %cmp, i8 0, i8 %umul.value |
| 28 |
store i8 %storemerge, i8* %c, align 1, !tbaa !2 |
| 29 |
; This test case verifies we don't leave any artifact calls behind (e.g. old_llvm.umul.with.overflow.i8). |
| 30 |
%umul2 = tail call { i8, i1 } @llvm.umul.with.overflow.i8(i8 %a, i8 %b) |
| 31 |
ret void |
| 32 |
} |
| 33 |
|
| 34 |
; CHECK-SPIRV: Function [[#]] [[NAME_UMUL_FUNC_8]] |
| 35 |
; CHECK-SPIRV: FunctionParameter [[#]] [[VAR_A:[0-9]+]] |
| 36 |
; CHECK-SPIRV: FunctionParameter [[#]] [[VAR_B:[0-9]+]] |
| 37 |
; CHECK-SPIRV: IMul [[#]] [[MUL_RES:[0-9]+]] [[VAR_A]] [[VAR_B]] |
| 38 |
; CHECK-SPIRV: UDiv [[#]] [[DIV_RES:[0-9]+]] [[MUL_RES]] [[VAR_A]] |
| 39 |
; CHECK-SPIRV: INotEqual [[#]] [[CMP_RES:[0-9]+]] [[VAR_A]] [[DIV_RES]] |
| 40 |
; CHECK-SPIRV: CompositeInsert [[#]] [[INSERT_RES:[0-9]+]] [[MUL_RES]] |
| 41 |
; CHECK-SPIRV: CompositeInsert [[#]] [[INSERT_RES_1:[0-9]+]] [[CMP_RES]] [[INSERT_RES]] |
| 42 |
; CHECK-SPIRV: ReturnValue [[INSERT_RES_1]] |
| 43 |
|
| 44 |
; Function Attrs: nofree nounwind writeonly |
| 45 |
define dso_local spir_func void @_Z5foo32jjPj(i32 %a, i32 %b, i32* nocapture %c) local_unnamed_addr #0 { |
| 46 |
entry: |
| 47 |
; CHECK-LLVM: call { i32, i1 } @llvm.umul.with.overflow.i32 |
| 48 |
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_32]] |
| 49 |
%umul = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %b, i32 %a) |
| 50 |
%umul.val = extractvalue { i32, i1 } %umul, 0 |
| 51 |
%umul.ov = extractvalue { i32, i1 } %umul, 1 |
| 52 |
%spec.select = select i1 %umul.ov, i32 0, i32 %umul.val |
| 53 |
store i32 %spec.select, i32* %c, align 4, !tbaa !5 |
| 54 |
ret void |
| 55 |
} |
| 56 |
|
| 57 |
; Function Attrs: nofree nounwind writeonly |
| 58 |
define dso_local spir_func void @umulo_v2i64(<2 x i64> %a, <2 x i64> %b, <2 x i64>* %p) nounwind { |
| 59 |
; CHECK-LLVM: call { <2 x i64>, <2 x i1> } @llvm.umul.with.overflow.v2i64 |
| 60 |
; CHECK-SPIRV: FunctionCall [[#]] [[#]] [[NAME_UMUL_FUNC_VEC_I64]] |
| 61 |
%umul = call {<2 x i64>, <2 x i1>} @llvm.umul.with.overflow.v2i64(<2 x i64> %a, <2 x i64> %b) |
| 62 |
%umul.val = extractvalue {<2 x i64>, <2 x i1>} %umul, 0 |
| 63 |
%umul.ov = extractvalue {<2 x i64>, <2 x i1>} %umul, 1 |
| 64 |
%zero = alloca <2 x i64>, align 16 |
| 65 |
%spec.select = select <2 x i1> %umul.ov, <2 x i64> <i64 0, i64 0>, <2 x i64> %umul.val |
| 66 |
store <2 x i64> %spec.select, <2 x i64>* %p |
| 67 |
ret void |
| 68 |
} |
| 69 |
|
| 70 |
; Function Attrs: nounwind readnone speculatable willreturn |
| 71 |
declare { i8, i1 } @llvm.umul.with.overflow.i8(i8, i8) #1 |
| 72 |
|
| 73 |
; Function Attrs: nounwind readnone speculatable willreturn |
| 74 |
declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32) #1 |
| 75 |
|
| 76 |
; Function Attrs: nounwind readnone speculatable willreturn |
| 77 |
declare {<2 x i64>, <2 x i1>} @llvm.umul.with.overflow.v2i64(<2 x i64>, <2 x i64>) #1 |
| 78 |
|
| 79 |
attributes #0 = { nofree nounwind writeonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 80 |
attributes #1 = { nounwind readnone speculatable willreturn } |
| 81 |
|
| 82 |
!llvm.module.flags = !{!0} |
| 83 |
!llvm.ident = !{!1} |
| 84 |
|
| 85 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 86 |
!1 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git ddcc7ce59150c9ebc6b0b2d61e7ef4f2525c11f4)"} |
| 87 |
!2 = !{!3, !3, i64 0} |
| 88 |
!3 = !{!"omnipotent char", !4, i64 0} |
| 89 |
!4 = !{!"Simple C++ TBAA"} |
| 90 |
!5 = !{!6, !6, i64 0} |
| 91 |
!6 = !{!"int", !3, i64 0} |