1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 define i1 @test_second_or_condition_implied_by_first(i8 %x) {
5 ; CHECK-LABEL: @test_second_or_condition_implied_by_first(
7 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
8 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
9 ; CHECK-NEXT: [[OR:%.*]] = or i1 true, [[T_1]]
10 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
12 ; CHECK-NEXT: ret i1 false
14 ; CHECK-NEXT: ret i1 true
17 %c.1 = icmp ule i8 %x, 10
18 %t.1 = icmp ugt i8 %x, 5
19 %or = or i1 %c.1, %t.1
20 br i1 %or, label %then, label %else
29 define i1 @test_first_or_condition_implied_by_second_ops(i8 %x) {
30 ; CHECK-LABEL: @test_first_or_condition_implied_by_second_ops(
32 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
33 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
34 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[T_1]], true
35 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
37 ; CHECK-NEXT: ret i1 false
39 ; CHECK-NEXT: ret i1 true
42 %c.1 = icmp ule i8 %x, 10
43 %t.1 = icmp ugt i8 %x, 5
44 %or = or i1 %t.1, %c.1
45 br i1 %or, label %then, label %else
54 define i1 @test_second_or_condition_implied_by_first_select_form(i8 %x) {
55 ; CHECK-LABEL: @test_second_or_condition_implied_by_first_select_form(
57 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
58 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
59 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[C_1]], i1 false, i1 [[T_1]]
60 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
62 ; CHECK-NEXT: ret i1 false
64 ; CHECK-NEXT: ret i1 true
67 %c.1 = icmp ule i8 %x, 10
68 %t.1 = icmp ugt i8 %x, 5
69 %or = select i1 %c.1, i1 false, i1 %t.1
70 br i1 %or, label %then, label %else
79 define i1 @test_first_or_condition_implied_by_second_select_form(i8 %x) {
80 ; CHECK-LABEL: @test_first_or_condition_implied_by_second_select_form(
82 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
83 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
84 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[T_1]], i1 false, i1 [[C_1]]
85 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
87 ; CHECK-NEXT: ret i1 false
89 ; CHECK-NEXT: ret i1 true
92 %c.1 = icmp ule i8 %x, 10
93 %t.1 = icmp ugt i8 %x, 5
94 %or = select i1 %t.1, i1 false, i1 %c.1
95 br i1 %or, label %then, label %else
104 define i1 @test_same_cond_for_or(i8 %x) {
105 ; CHECK-LABEL: @test_same_cond_for_or(
107 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
108 ; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[C_1]]
109 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
111 ; CHECK-NEXT: ret i1 false
113 ; CHECK-NEXT: ret i1 true
116 %c.1 = icmp ugt i8 %x, 10
117 %or = or i1 %c.1, %c.1
118 br i1 %or, label %then, label %else
127 define i1 @test_same_cond_for_or_select_form(i8 %x) {
128 ; CHECK-LABEL: @test_same_cond_for_or_select_form(
130 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
131 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[C_1]], i1 false, i1 [[C_1]]
132 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
134 ; CHECK-NEXT: ret i1 false
136 ; CHECK-NEXT: ret i1 true
139 %c.1 = icmp ugt i8 %x, 10
140 %or = select i1 %c.1, i1 false, i1 %c.1
141 br i1 %or, label %then, label %else
150 define i1 @test_second_or_condition_not_implied_by_first(i8 %x) {
151 ; CHECK-LABEL: @test_second_or_condition_not_implied_by_first(
153 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
154 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i8 [[X]], 5
155 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[C_2]], false
156 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
158 ; CHECK-NEXT: ret i1 false
160 ; CHECK-NEXT: ret i1 true
163 %c.1 = icmp ugt i8 %x, 10
164 %c.2 = icmp ugt i8 %x, 5
165 %or = or i1 %c.2, %c.1
166 br i1 %or, label %then, label %else
175 define i1 @test_remove_variables(i1 %c, ptr %A, i64 %B, ptr %C) {
176 ; CHECK-LABEL: @test_remove_variables(
178 ; CHECK-NEXT: br i1 [[C:%.*]], label [[THEN_1:%.*]], label [[EXIT:%.*]]
180 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[C:%.*]], align 8
181 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[TMP0]], [[A:%.*]]
182 ; CHECK-NEXT: br i1 [[C_1]], label [[THEN_2:%.*]], label [[ELSE_2:%.*]]
184 ; CHECK-NEXT: [[C_3:%.*]] = icmp sgt i64 [[B:%.*]], 0
185 ; CHECK-NEXT: [[OR:%.*]] = or i1 true, [[C_3]]
186 ; CHECK-NEXT: ret i1 [[OR]]
188 ; CHECK-NEXT: ret i1 false
190 ; CHECK-NEXT: ret i1 true
193 br i1 %c, label %then.1, label %exit
196 %0 = load ptr, ptr %C, align 8
197 %c.1 = icmp ult ptr %0, %A
198 br i1 %c.1, label %then.2, label %else.2
201 %c.2 = icmp ne ptr %A, null
202 %c.3 = icmp sgt i64 %B, 0
203 %or = or i1 %c.2, %c.3
210 %t = icmp eq ptr null, null
214 define i1 @test_or_op_0_simplified(i32 %v) {
215 ; CHECK-LABEL: @test_or_op_0_simplified(
217 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[V:%.*]], 0
218 ; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[C_1]]
219 ; CHECK-NEXT: ret i1 [[OR]]
222 %c.1 = icmp sgt i32 %v, 0
223 %t.1 = icmp sgt i32 0, 0
224 %or = or i1 %t.1, %c.1
228 define i1 @test_or_op_1_simplified(i32 %v) {
229 ; CHECK-LABEL: @test_or_op_1_simplified(
231 ; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i32 [[V:%.*]], 0
232 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[C_1]], false
233 ; CHECK-NEXT: ret i1 [[OR]]
236 %c.1 = icmp sgt i32 %v, 0
237 %t.1 = icmp sgt i32 0, 0
238 %or = or i1 %c.1, %t.1
242 define i1 @test_or_used_in_false_branch(i8 %x) {
243 ; CHECK-LABEL: @test_or_used_in_false_branch(
245 ; CHECK-NEXT: [[C_1:%.*]] = icmp ule i8 [[X:%.*]], 10
246 ; CHECK-NEXT: [[T_1:%.*]] = icmp ule i8 [[X]], 5
247 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[C_1]], false
248 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
250 ; CHECK-NEXT: ret i1 [[T_1]]
252 ; CHECK-NEXT: ret i1 false
256 %c.1 = icmp ule i8 %x, 10
257 %t.1 = icmp ule i8 %x, 5
258 %or = or i1 %c.1, %t.1
259 br i1 %or, label %then, label %else
268 define i1 @test_or_used_in_false_branch2(i8 %x) {
269 ; CHECK-LABEL: @test_or_used_in_false_branch2(
271 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i8 [[X:%.*]], 10
272 ; CHECK-NEXT: [[T_1:%.*]] = icmp ugt i8 [[X]], 5
273 ; CHECK-NEXT: [[OR:%.*]] = or i1 false, [[T_1]]
274 ; CHECK-NEXT: br i1 [[OR]], label [[THEN:%.*]], label [[ELSE:%.*]]
276 ; CHECK-NEXT: ret i1 [[T_1]]
278 ; CHECK-NEXT: ret i1 false
282 %c.1 = icmp ugt i8 %x, 10
283 %t.1 = icmp ugt i8 %x, 5
284 %or = or i1 %c.1, %t.1
285 br i1 %or, label %then, label %else
294 define i1 @select_or_set_operand(ptr noundef %a, ptr noundef %b) {
295 ; CHECK-LABEL: @select_or_set_operand(
297 ; CHECK-NEXT: [[CMP_EQ:%.*]] = icmp eq ptr [[A:%.*]], [[B:%.*]]
298 ; CHECK-NEXT: [[INCDEC_PTR12_I:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 1
299 ; CHECK-NEXT: [[CMP_EQ_1:%.*]] = icmp eq ptr [[INCDEC_PTR12_I]], [[B]]
300 ; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP_EQ]], i1 true, i1 [[CMP_EQ_1]]
301 ; CHECK-NEXT: ret i1 [[OR]]
304 %cmp.eq = icmp eq ptr %a, %b
305 %incdec.ptr12.i = getelementptr inbounds i32, ptr %a, i64 1
306 %cmp.eq.1 = icmp eq ptr %incdec.ptr12.i, %b
307 %or = select i1 %cmp.eq, i1 true, i1 %cmp.eq.1