Debian Codegraph @

llvm/test/CodeGen/SPIRV/optimizations/add-check-overflow.ll

raw
1 ; This test aims to check ability to support "Arithmetic with Overflow" intrinsics
2 ; in the special case when those intrinsics are being generated by the CodeGenPrepare;
3 ; pass during translations with optimization (note -disable-lsr, to inhibit
4 ; strength reduction pre-empting with a more preferable match for this pattern
5 ; in llc arguments).
6
7 ; RUN: llc -O3 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
8 ; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
9
10 ; RUN: llc -O3 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
11 ; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
12
13 ; RUN: llc -O3 -disable-lsr -mtriple=spirv32-unknown-unknown %s -o - | FileCheck --check-prefix=NOLSR %s
14 ; RUN: %if spirv-tools %{ llc -O3 -disable-lsr -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
15
16 ; RUN: llc -O3 -disable-lsr -mtriple=spirv64-unknown-unknown %s -o - | FileCheck --check-prefix=NOLSR %s
17 ; RUN: %if spirv-tools %{ llc -O3 -disable-lsr -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
18
19 ; CHECK-DAG: %[[Int:.*]] = OpTypeInt 32 0
20 ; CHECK-DAG: %[[Char:.*]] = OpTypeInt 8 0
21 ; CHECK-DAG: %[[PtrChar:.*]] = OpTypePointer Generic %[[Char]]
22 ; CHECK-DAG: %[[Bool:.*]] = OpTypeBool
23 ; CHECK-DAG: %[[Const1:.*]] = OpConstant %[[Int]] 1{{$}}
24 ; CHECK-DAG: %[[Zero:.*]] = OpConstantNull %[[Int]]
25 ; CHECK-DAG: %[[Const42:.*]] = OpConstant %[[Char]] 42{{$}}
26
27 ; CHECK: OpFunction
28 ; CHECK: %[[A:.*]] = OpFunctionParameter %[[Int]]
29 ; CHECK: %[[Ptr:.*]] = OpFunctionParameter %[[PtrChar]]
30 ; CHECK: %[[APlusOne:.*]] = OpIAdd %[[Int]] %[[A]] %[[Const1]]
31 ; CHECK: OpBranch %[[#]]
32 ; CHECK: [[#]] = OpLabel
33 ; CHECK: %[[PhiRes:.*]] = OpPhi %[[Int]] %[[Val:.*]] %[[#]] %[[APlusOne]] %[[#]]
34 ; CHECK: %[[IsOver:.*]] = OpIEqual %[[Bool]] %[[#]] %[[#]]
35 ; CHECK: OpBranchConditional %[[IsOver]] %[[#]] %[[#]]
36 ; CHECK: [[#]] = OpLabel
37 ; CHECK: OpStore %[[Ptr]] %[[Const42]] Aligned 1
38 ; CHECK: [[Val]] = OpIAdd %[[Int]] %[[PhiRes]] %[[Const1]]
39 ; CHECK: OpBranch %[[#]]
40 ; CHECK: [[#]] = OpLabel
41 ; OpReturnValue %[[PhiRes]]
42
43 ; NOLSR-DAG: %[[Int:.*]] = OpTypeInt 32 0
44 ; NOLSR-DAG: %[[Char:.*]] = OpTypeInt 8 0
45 ; NOLSR-DAG: %[[PtrChar:.*]] = OpTypePointer Generic %[[Char]]
46 ; NOLSR-DAG: %[[Bool:.*]] = OpTypeBool
47 ; NOLSR-DAG: %[[Struct:.*]] = OpTypeStruct %[[Int]] %[[Int]]
48 ; NOLSR-DAG: %[[Const1:.*]] = OpConstant %[[Int]] 1
49 ; NOLSR-DAG: %[[Const42:.*]] = OpConstant %[[Char]] 42
50 ; NOLSR-DAG: %[[Zero:.*]] = OpConstantNull %[[Int]]
51
52 ; NOLSR: OpFunction
53 ; NOLSR: %[[A:.*]] = OpFunctionParameter %[[Int]]
54 ; NOLSR: %[[Ptr:.*]] = OpFunctionParameter %[[PtrChar]]
55 ; NOLSR: %[[#]] = OpLabel
56 ; NOLSR: OpBranch %[[#]]
57 ; NOLSR: %[[#]] = OpLabel
58 ; NOLSR: %[[PhiRes:.*]] = OpPhi %[[Int]] %[[A]] %[[#]] %[[Val:.*]] %[[#]]
59 ; NOLSR: %[[AggRes:.*]] = OpIAddCarry %[[Struct]] %[[PhiRes]] %[[Const1]]
60 ; NOLSR: %[[Val]] = OpCompositeExtract %[[Int]] %[[AggRes]] 0
61 ; NOLSR: %[[Over:.*]] = OpCompositeExtract %[[Int]] %[[AggRes]] 1
62 ; NOLSR: %[[IsOver:.*]] = OpINotEqual %[[Bool:.*]] %[[Over]] %[[Zero]]
63 ; NOLSR: OpBranchConditional %[[IsOver]] %[[#]] %[[#]]
64 ; NOLSR: OpStore %[[Ptr]] %[[Const42]] Aligned 1
65 ; NOLSR: OpBranch %[[#]]
66 ; NOLSR: %[[#]] = OpLabel
67 ; NOLSR: OpReturnValue %[[Val]]
68 ; NOLSR: OpFunctionEnd
69
70 define spir_func i32 @foo(i32 %a, ptr addrspace(4) %p) {
71 entry:
72 br label %l1
73
74 body:
75 store i8 42, ptr addrspace(4) %p
76 br label %l1
77
78 l1:
79 %e = phi i32 [ %a, %entry ], [ %i, %body ]
80 %i = add nsw i32 %e, 1
81 %fl = icmp eq i32 %i, 0
82 br i1 %fl, label %exit, label %body
83
84 exit:
85 ret i32 %i
86 }