1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2 ; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
4 define internal i32 @f1(i32 %x) {
5 ; CHECK-LABEL: define {{[^@]+}}@f1
6 ; CHECK-SAME: (i32 range(i32 0, 2) [[X:%.*]]) {
7 ; CHECK-NEXT: ret i32 poison
9 %cmp = icmp sgt i32 %x, 300
10 %res = select i1 %cmp, i32 1, i32 2
14 ; %res is a constant range [0, 2) from a PHI node.
15 define i32 @caller1(i1 %cmp) {
16 ; CHECK-LABEL: define {{[^@]+}}@caller1
17 ; CHECK-SAME: (i1 [[CMP:%.*]]) {
19 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_TRUE:%.*]], label [[END:%.*]]
21 ; CHECK-NEXT: br label [[END]]
23 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]
24 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f1(i32 [[RES]])
25 ; CHECK-NEXT: ret i32 2
30 br i1 %cmp, label %if.true, label %end
36 %res = phi i32 [ 0, %entry], [ 1, %if.true ]
37 %call1 = tail call i32 @f1(i32 %res)
41 define internal i32 @f2(i32 %x, i32 %y, i32 %z, i1 %cmp.1, i1 %cmp.2) {
42 ; CHECK-LABEL: define {{[^@]+}}@f2
43 ; CHECK-SAME: (i32 range(i32 0, 2) [[X:%.*]], i32 range(i32 -10, 2) [[Y:%.*]], i32 range(i32 1, 11) [[Z:%.*]], i1 [[CMP_1:%.*]], i1 [[CMP_2:%.*]]) {
45 ; CHECK-NEXT: br i1 [[CMP_1]], label [[IF_TRUE_1:%.*]], label [[END:%.*]]
47 ; CHECK-NEXT: br i1 [[CMP_2]], label [[IF_TRUE_2:%.*]], label [[END]]
49 ; CHECK-NEXT: br label [[END]]
51 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[X]], [[ENTRY:%.*]] ], [ [[Y]], [[IF_TRUE_1]] ], [ [[Z]], [[IF_TRUE_2]] ]
52 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[P]], 5
53 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[P]], 0
54 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i32 [[P]], 0
55 ; CHECK-NEXT: [[V_1:%.*]] = select i1 [[C_1]], i32 10, i32 100
56 ; CHECK-NEXT: [[V_2:%.*]] = select i1 [[C_2]], i32 20, i32 200
57 ; CHECK-NEXT: [[V_3:%.*]] = select i1 [[C_3]], i32 30, i32 300
58 ; CHECK-NEXT: [[R_1:%.*]] = add nuw nsw i32 [[V_1]], [[V_2]]
59 ; CHECK-NEXT: [[R_2:%.*]] = add nuw nsw i32 [[R_1]], [[V_3]]
60 ; CHECK-NEXT: [[R_3:%.*]] = add nuw nsw i32 [[R_2]], 400
61 ; CHECK-NEXT: [[R_4:%.*]] = add nuw nsw i32 [[R_3]], 50
62 ; CHECK-NEXT: [[R_5:%.*]] = add nuw nsw i32 [[R_4]], 60
63 ; CHECK-NEXT: [[R_6:%.*]] = add nuw nsw i32 [[R_4]], 700
64 ; CHECK-NEXT: ret i32 [[R_6]]
70 br i1 %cmp.1, label %if.true.1, label %end
73 br i1 %cmp.2, label %if.true.2, label %end
79 %p = phi i32 [ %x, %entry ], [ %y, %if.true.1 ], [ %z, %if.true.2 ]
80 %c.1 = icmp sgt i32 %p, 5
81 %c.2 = icmp eq i32 %p, 0
82 %c.3 = icmp slt i32 %p, 0
83 %c.4 = icmp sgt i32 %p, 10
84 %c.5 = icmp sle i32 %p, 10
85 %c.6 = icmp sgt i32 %p, -11
86 %c.7 = icmp slt i32 %p, -11
87 %v.1 = select i1 %c.1, i32 10, i32 100
88 %v.2 = select i1 %c.2, i32 20, i32 200
89 %v.3 = select i1 %c.3, i32 30, i32 300
90 %v.4 = select i1 %c.4, i32 40, i32 400
91 %v.5 = select i1 %c.5, i32 50, i32 500
92 %v.6 = select i1 %c.6, i32 60, i32 600
93 %v.7 = select i1 %c.7, i32 70, i32 700
94 %r.1 = add i32 %v.1, %v.2
95 %r.2 = add i32 %r.1, %v.3
96 %r.3 = add i32 %r.2, %v.4
97 %r.4 = add i32 %r.3, %v.5
98 %r.5 = add i32 %r.4, %v.6
99 %r.6 = add i32 %r.4, %v.7
103 define i32 @caller2(i1 %cmp.1, i1 %cmp.2) {
104 ; CHECK-LABEL: define {{[^@]+}}@caller2
105 ; CHECK-SAME: (i1 [[CMP_1:%.*]], i1 [[CMP_2:%.*]]) {
107 ; CHECK-NEXT: br i1 [[CMP_1]], label [[IF_TRUE:%.*]], label [[END:%.*]]
109 ; CHECK-NEXT: br label [[END]]
111 ; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]
112 ; CHECK-NEXT: [[P2:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ -10, [[IF_TRUE]] ]
113 ; CHECK-NEXT: [[P3:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 10, [[IF_TRUE]] ]
114 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f2(i32 [[P1]], i32 [[P2]], i32 [[P3]], i1 [[CMP_1]], i1 [[CMP_2]])
115 ; CHECK-NEXT: ret i32 [[CALL1]]
121 br i1 %cmp.1, label %if.true, label %end
127 %p1 = phi i32 [ 0, %entry], [ 1, %if.true ]
128 %p2 = phi i32 [ 1, %entry], [ -10, %if.true ]
129 %p3 = phi i32 [ 1, %entry], [ 10, %if.true ]
130 %call1 = tail call i32 @f2(i32 %p1, i32 %p2, i32 %p3, i1 %cmp.1, i1 %cmp.2)
134 define internal i32 @f3(i32 %x, i32 %y, i1 %cmp.1) {
135 ; CHECK-LABEL: define {{[^@]+}}@f3
136 ; CHECK-SAME: (i32 range(i32 0, 6) [[X:%.*]], i32 [[Y:%.*]], i1 [[CMP_1:%.*]]) {
138 ; CHECK-NEXT: br i1 [[CMP_1]], label [[IF_TRUE_1:%.*]], label [[END:%.*]]
140 ; CHECK-NEXT: br label [[END]]
142 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[X]], [[ENTRY:%.*]] ], [ [[Y]], [[IF_TRUE_1]] ]
143 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[P]], 5
144 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i32 [[P]], 0
145 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i32 [[P]], 0
146 ; CHECK-NEXT: [[C_4:%.*]] = icmp sgt i32 [[P]], 10
147 ; CHECK-NEXT: [[C_5:%.*]] = icmp sle i32 [[P]], 10
148 ; CHECK-NEXT: [[C_6:%.*]] = icmp sgt i32 [[P]], -11
149 ; CHECK-NEXT: [[C_7:%.*]] = icmp slt i32 [[P]], -11
150 ; CHECK-NEXT: [[V_1:%.*]] = select i1 [[C_1]], i32 10, i32 100
151 ; CHECK-NEXT: [[V_2:%.*]] = select i1 [[C_2]], i32 20, i32 200
152 ; CHECK-NEXT: [[V_3:%.*]] = select i1 [[C_3]], i32 30, i32 300
153 ; CHECK-NEXT: [[V_4:%.*]] = select i1 [[C_4]], i32 40, i32 400
154 ; CHECK-NEXT: [[V_5:%.*]] = select i1 [[C_5]], i32 50, i32 500
155 ; CHECK-NEXT: [[V_6:%.*]] = select i1 [[C_6]], i32 60, i32 600
156 ; CHECK-NEXT: [[V_7:%.*]] = select i1 [[C_7]], i32 70, i32 700
157 ; CHECK-NEXT: [[R_1:%.*]] = add nuw nsw i32 [[V_1]], [[V_2]]
158 ; CHECK-NEXT: [[R_2:%.*]] = add nuw nsw i32 [[R_1]], [[V_3]]
159 ; CHECK-NEXT: [[R_3:%.*]] = add nuw nsw i32 [[R_2]], [[V_4]]
160 ; CHECK-NEXT: [[R_4:%.*]] = add nuw nsw i32 [[R_3]], [[V_5]]
161 ; CHECK-NEXT: [[R_5:%.*]] = add nuw nsw i32 [[R_4]], [[V_6]]
162 ; CHECK-NEXT: [[R_6:%.*]] = add nuw nsw i32 [[R_4]], [[V_7]]
163 ; CHECK-NEXT: ret i32 [[R_6]]
168 br i1 %cmp.1, label %if.true.1, label %end
174 %p = phi i32 [ %x, %entry ], [ %y, %if.true.1 ]
175 %c.1 = icmp sgt i32 %p, 5
176 %c.2 = icmp eq i32 %p, 0
177 %c.3 = icmp slt i32 %p, 0
178 %c.4 = icmp sgt i32 %p, 10
179 %c.5 = icmp sle i32 %p, 10
180 %c.6 = icmp sgt i32 %p, -11
181 %c.7 = icmp slt i32 %p, -11
182 %v.1 = select i1 %c.1, i32 10, i32 100
183 %v.2 = select i1 %c.2, i32 20, i32 200
184 %v.3 = select i1 %c.3, i32 30, i32 300
185 %v.4 = select i1 %c.4, i32 40, i32 400
186 %v.5 = select i1 %c.5, i32 50, i32 500
187 %v.6 = select i1 %c.6, i32 60, i32 600
188 %v.7 = select i1 %c.7, i32 70, i32 700
189 %r.1 = add i32 %v.1, %v.2
190 %r.2 = add i32 %r.1, %v.3
191 %r.3 = add i32 %r.2, %v.4
192 %r.4 = add i32 %r.3, %v.5
193 %r.5 = add i32 %r.4, %v.6
194 %r.6 = add i32 %r.4, %v.7
198 define i32 @caller3(i32 %y, i1 %cmp.1) {
199 ; CHECK-LABEL: define {{[^@]+}}@caller3
200 ; CHECK-SAME: (i32 [[Y:%.*]], i1 [[CMP_1:%.*]]) {
202 ; CHECK-NEXT: br i1 [[CMP_1]], label [[IF_TRUE:%.*]], label [[END:%.*]]
204 ; CHECK-NEXT: br label [[END]]
206 ; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 5, [[IF_TRUE]] ]
207 ; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[P1]], i32 [[Y]], i1 [[CMP_1]])
208 ; CHECK-NEXT: ret i32 [[CALL1]]
213 br i1 %cmp.1, label %if.true, label %end
219 %p1 = phi i32 [ 0, %entry], [ 5, %if.true ]
220 %call1 = tail call i32 @f3(i32 %p1, i32 %y, i1 %cmp.1)