1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define i32 @xor_domcondition(i32 %x, i32 %y) {
5 ; CHECK-LABEL: @xor_domcondition(
7 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
8 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
10 ; CHECK-NEXT: br label [[COND_END]]
12 ; CHECK-NEXT: ret i32 0
15 %cmp = icmp eq i32 %x, %y
16 br i1 %cmp, label %cond.true, label %cond.end
23 %cond = phi i32 [ %xor, %cond.true ], [ 0, %entry ]
27 define i32 @sub_domcondition(i32 %x, i32 %y) {
28 ; CHECK-LABEL: @sub_domcondition(
30 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
31 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
33 ; CHECK-NEXT: br label [[COND_END]]
35 ; CHECK-NEXT: ret i32 0
38 %cmp = icmp eq i32 %x, %y
39 br i1 %cmp, label %cond.true, label %cond.end
46 %cond = phi i32 [ %sub, %cond.true ], [ 0, %entry ]
50 define i32 @udiv_domcondition(i32 %x, i32 %y) {
51 ; CHECK-LABEL: @udiv_domcondition(
53 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
54 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
56 ; CHECK-NEXT: br label [[COND_END]]
58 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ 1, [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
59 ; CHECK-NEXT: ret i32 [[COND]]
62 %cmp = icmp eq i32 %x, %y
63 br i1 %cmp, label %cond.true, label %cond.end
66 %udiv = udiv i32 %x, %y
70 %cond = phi i32 [ %udiv, %cond.true ], [ 0, %entry ]
74 define i32 @sdiv_domcondition(i32 %x, i32 %y) {
75 ; CHECK-LABEL: @sdiv_domcondition(
77 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
78 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
80 ; CHECK-NEXT: br label [[COND_END]]
82 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ 1, [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
83 ; CHECK-NEXT: ret i32 [[COND]]
86 %cmp = icmp eq i32 %x, %y
87 br i1 %cmp, label %cond.true, label %cond.end
90 %sdiv = sdiv i32 %x, %y
94 %cond = phi i32 [ %sdiv, %cond.true ], [ 0, %entry ]
98 define i32 @urem_domcondition(i32 %x, i32 %y) {
99 ; CHECK-LABEL: @urem_domcondition(
101 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
102 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
104 ; CHECK-NEXT: br label [[COND_END]]
106 ; CHECK-NEXT: ret i32 0
109 %cmp = icmp eq i32 %x, %y
110 br i1 %cmp, label %cond.true, label %cond.end
113 %urem = urem i32 %x, %y
117 %cond = phi i32 [ %urem, %cond.true ], [ 0, %entry ]
121 define i32 @srem_domcondition(i32 %x, i32 %y) {
122 ; CHECK-LABEL: @srem_domcondition(
124 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
125 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
127 ; CHECK-NEXT: br label [[COND_END]]
129 ; CHECK-NEXT: ret i32 0
132 %cmp = icmp eq i32 %x, %y
133 br i1 %cmp, label %cond.true, label %cond.end
136 %srem = srem i32 %x, %y
140 %cond = phi i32 [ %srem, %cond.true ], [ 0, %entry ]
144 ; TODO: %and can be one of %x, %y
145 define i32 @and_domcondition(i32 %x, i32 %y) {
146 ; CHECK-LABEL: @and_domcondition(
148 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
149 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
151 ; CHECK-NEXT: br label [[COND_END]]
153 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[Y]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
154 ; CHECK-NEXT: ret i32 [[COND]]
157 %cmp = icmp eq i32 %x, %y
158 br i1 %cmp, label %cond.true, label %cond.end
161 %and = and i32 %x, %y
165 %cond = phi i32 [ %and, %cond.true ], [ 0, %entry ]
169 ; TODO: %or can be one of %x, %y
170 define i32 @or_domcondition(i32 %x, i32 %y) {
171 ; CHECK-LABEL: @or_domcondition(
173 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
174 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
176 ; CHECK-NEXT: br label [[COND_END]]
178 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[Y]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
179 ; CHECK-NEXT: ret i32 [[COND]]
182 %cmp = icmp eq i32 %x, %y
183 br i1 %cmp, label %cond.true, label %cond.end
190 %cond = phi i32 [ %or, %cond.true ], [ 0, %entry ]
194 ; negative test, dominate condtion is not eq
195 define i32 @xor_domcondition_negative(i32 %x, i32 %y) {
196 ; CHECK-LABEL: @xor_domcondition_negative(
198 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
199 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
201 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
202 ; CHECK-NEXT: br label [[COND_END]]
204 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[XOR]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
205 ; CHECK-NEXT: ret i32 [[COND]]
208 %cmp = icmp uge i32 %x, %y
209 br i1 %cmp, label %cond.true, label %cond.end
212 %xor = xor i32 %x, %y
216 %cond = phi i32 [ %xor, %cond.true ], [ 0, %entry ]
220 define i32 @xor_simplify_by_dci(i32 %x, i32 %y, i1 %c) {
221 ; CHECK-LABEL: @xor_simplify_by_dci(
223 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
224 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
226 ; CHECK-NEXT: br i1 [[C:%.*]], label [[XORBB:%.*]], label [[COND_END]]
228 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
229 ; CHECK-NEXT: br label [[COND_END]]
231 ; CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[XOR]], [[XORBB]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[COND_TRUE]] ]
232 ; CHECK-NEXT: ret i32 [[COND]]
235 %cmp = icmp eq i32 %x, %y
236 br i1 %cmp, label %cond.true, label %cond.end
239 br i1 %c, label %xorbb, label %cond.end
242 %xor = xor i32 %x, %y
246 %cond = phi i32 [ %xor, %xorbb ], [ 0, %entry ], [0, %cond.true]
250 define void @icmp_simplify_by_dci(i32 %a, i32 %b, i1 %x) {
251 ; CHECK-LABEL: @icmp_simplify_by_dci(
252 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
253 ; CHECK-NEXT: br i1 [[CMP1]], label [[END:%.*]], label [[TAKEN:%.*]]
255 ; CHECK-NEXT: br i1 [[X:%.*]], label [[SELBB:%.*]], label [[END]]
257 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[A]], [[B]]
258 ; CHECK-NEXT: [[C:%.*]] = select i1 [[CMP2]], i32 20, i32 0
259 ; CHECK-NEXT: call void @foo(i32 [[C]])
260 ; CHECK-NEXT: br label [[END]]
262 ; CHECK-NEXT: ret void
264 %cmp1 = icmp eq i32 %a, %b
265 br i1 %cmp1, label %end, label %taken
268 br i1 %x, label %selbb, label %end
271 %cmp2 = icmp ne i32 %a, %b
272 %c = select i1 %cmp2, i32 20, i32 0
273 call void @foo(i32 %c)
280 declare void @foo(i32)