1 ; RUN: opt -passes=constraint-elimination -constraint-elimination-dump-reproducers -pass-remarks=constraint-elimination %s 2>&1 | FileCheck %s
3 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 declare void @llvm.assume(i1)
9 define i1 @test_no_known_facts(ptr %dst) {
10 ; CHECK: remark: <unknown>:0:0: module; ModuleID = 'test_no_known_facts'
11 ; CHECK-LABEL: define i1 @"{{.+}}test_no_known_factsrepro"(ptr %dst)
13 ; CHECK-NEXT: %dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
14 ; CHECK-NEXT: %upper = getelementptr inbounds ptr, ptr %dst, i64 2
15 ; CHECK-NEXT: %c = icmp ult ptr %dst.0, %upper
16 ; CHECK-NEXT: ret i1 %c
20 %dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
21 %upper = getelementptr inbounds ptr, ptr %dst, i64 2
22 %c = icmp ult ptr %dst.0, %upper
26 define void @test_one_known_fact_true_branch(i8 %start, i8 %high) {
27 ; CHECK: remark: <unknown>:0:0: module; ModuleID = 'test_one_known_fact_true_branch'
29 ; CHECK-LABEL: define i1 @"{{.*}}test_one_known_fact_true_branchrepro"(i8 %high, i8 %start) {
31 ; CHECK-NEXT: %add.ptr.i = add nuw i8 %start, 3
32 ; CHECK-NEXT: %0 = icmp ult i8 %add.ptr.i, %high
33 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
34 ; CHECK-NEXT: %t.0 = icmp ult i8 %start, %high
35 ; CHECK-NEXT: ret i1 %t.0
39 %add.ptr.i = add nuw i8 %start, 3
40 %c.1 = icmp ult i8 %add.ptr.i, %high
41 br i1 %c.1, label %if.then, label %if.end
44 %t.0 = icmp ult i8 %start, %high
45 call void @use(i1 %t.0)
52 define void @test_one_known_fact_false_branch(i8 %start, i8 %high) {
53 ; CHECK: remark: <unknown>:0:0: module; ModuleID = 'test_one_known_fact_false_branch'
55 ; CHECK-LABEL:define i1 @"{{.*}}test_one_known_fact_false_branchrepro"(i8 %high, i8 %start) {
57 ; CHECK-NEXT: %add.ptr.i = add nuw i8 %start, 3
58 ; CHECK-NEXT: %0 = icmp ult i8 %add.ptr.i, %high
59 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
60 ; CHECK-NEXT: %t.0 = icmp ult i8 %start, %high
61 ; CHECK-NEXT: ret i1 %t.0
65 %add.ptr.i = add nuw i8 %start, 3
66 %c.1 = icmp uge i8 %add.ptr.i, %high
67 br i1 %c.1, label %if.then, label %if.end
73 %t.0 = icmp ult i8 %start, %high
74 call void @use(i1 %t.0)
78 define void @test_multiple_known_facts_branches_1(i8 %a, i8 %b) {
79 ; CHECK: remark: <unknown>:0:0: module; ModuleID = 'test_multiple_known_facts_branches_1'
81 ; CHECK-LABEL: define i1 @"{{.*}}test_multiple_known_facts_branches_1repro"(i8 %a, i8 %b) {
83 ; CHECK-NEXT: %0 = icmp ugt i8 %a, 10
84 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
85 ; CHECK-NEXT: %1 = icmp ugt i8 %b, 10
86 ; CHECK-NEXT: call void @llvm.assume(i1 %1)
87 ; CHECK-NEXT: %add = add nuw i8 %a, %b
88 ; CHECK-NEXT: %t.0 = icmp ugt i8 %add, 20
89 ; CHECK-NEXT: ret i1 %t.0
93 %c.1 = icmp ugt i8 %a, 10
94 br i1 %c.1, label %then.1, label %else.1
97 %c.2 = icmp ugt i8 %b, 10
98 br i1 %c.2, label %then.2, label %else.1
101 %add = add nuw i8 %a, %b
102 %t.0 = icmp ugt i8 %add, 20
103 call void @use(i1 %t.0)
110 define void @test_multiple_known_facts_branches_2(i8 %a, i8 %b) {
111 ; CHECK: remark: <unknown>:0:0: module; ModuleID = 'test_multiple_known_facts_branches_2'
113 ; CHECK-LABEL: define i1 @"{{.*}}test_multiple_known_facts_branches_2repro"(i8 %a, i8 %b) {
115 ; CHECK-NEXT: %0 = icmp ugt i8 %a, 10
116 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
117 ; CHECK-NEXT: %1 = icmp ugt i8 %b, 10
118 ; CHECK-NEXT: call void @llvm.assume(i1 %1)
119 ; CHECK-NEXT: %add = add nuw i8 %a, %b
120 ; CHECK-NEXT: %t.0 = icmp ugt i8 %add, 20
121 ; CHECK-NEXT: ret i1 %t.0
125 %c.1 = icmp ugt i8 %a, 10
126 br i1 %c.1, label %then.1, label %exit
129 %c.2 = icmp ule i8 %b, 10
130 br i1 %c.2, label %exit, label %else.2
133 %add = add nuw i8 %a, %b
134 %t.0 = icmp ugt i8 %add, 20
135 call void @use(i1 %t.0)
142 define void @test_assumes(i8 %a, i8 %b) {
143 ; CHECK-LABEL: define i1 @"{{.*}}test_assumesrepro.2"(i8 %a, i8 %b) {
145 ; CHECK-NEXT: %0 = icmp ugt i8 %a, 10
146 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
147 ; CHECK-NEXT: %1 = icmp ugt i8 %b, 10
148 ; CHECK-NEXT: call void @llvm.assume(i1 %1)
149 ; CHECK-NEXT: %add = add nuw i8 %a, %b
150 ; CHECK-NEXT: %t.0 = icmp ult i8 %add, 20
151 ; CHECK-NEXT: ret i1 %t.0
155 %c.1 = icmp ugt i8 %a, 10
156 call void @llvm.assume(i1 %c.1)
157 %c.2 = icmp ugt i8 %b, 10
158 call void @llvm.assume(i1 %c.2)
159 %add = add nuw i8 %a, %b
160 %t.0 = icmp ult i8 %add, 20
161 call void @use(i1 %t.0)
165 declare void @noundef(ptr noundef)
167 ; Currently this fails decomposition. No reproducer should be generated.
168 define i1 @test_inbounds_precondition(ptr %src, i32 %n, i32 %idx) {
169 ; CHECK-NOT: test_inbounds_precondition
171 %upper = getelementptr inbounds i32, ptr %src, i64 5
172 %src.idx.4 = getelementptr i32, ptr %src, i64 4
173 %cmp.upper.4 = icmp ule ptr %src.idx.4, %upper
174 br i1 %cmp.upper.4, label %then, label %else
183 define i32 @test_branch(i32 %a) {
184 ; CHECK-LABEL: define i1 @"{{.+}}test_branchrepro"(i32 %a) {
186 ; CHECK-NEXT: %0 = icmp ult i32 %a, 4
187 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
188 ; CHECK-NEXT: %c.2 = icmp ugt i32 0, 0
189 ; CHECK-NEXT: ret i1 %c.2
193 %c.1 = icmp ult i32 %a, 4
194 br i1 %c.1, label %then, label %exit
197 %c.2 = icmp ugt i32 0, 0
198 call void @use(i1 %c.2)
205 define i32 @test_invoke(i32 %a) personality ptr null {
206 ; CHECK-LABEL: define i1 @"{{.+}}test_invokerepro"(i32 %l, i32 %a) {
208 ; CHECK-NEXT: %0 = icmp slt i32 %a, %l
209 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
210 ; CHECK-NEXT: %c.2 = icmp eq i32 0, 0
211 ; CHECK-NEXT: ret i1 %c.2
215 %call = invoke ptr null(i64 0)
216 to label %cont unwind label %lpad
219 %l = load i32, ptr %call, align 4
220 %c.1 = icmp slt i32 %a, %l
221 br i1 %c.1, label %then, label %exit
224 %lp = landingpad { ptr, i32 }
230 %c.2 = icmp eq i32 0, 0
231 call void @use(i1 %c.2)
238 define <2 x i1> @vector_cmp(<2 x ptr> %vec) {
239 ; CHECK-LABEL: define <2 x i1> @"{{.+}}vector_cmprepro"(<2 x ptr> %vec) {
241 ; CHECK-NEXT: %gep.1 = getelementptr inbounds i32, <2 x ptr> %vec, i64 1
242 ; CHECK-NEXT: %t.1 = icmp ult <2 x ptr> %vec, %gep.1
243 ; CHECK-NEXT: ret <2 x i1> %t.1
246 %gep.1 = getelementptr inbounds i32, <2 x ptr> %vec, i64 1
247 %t.1 = icmp ult <2 x ptr> %vec, %gep.1
251 define i1 @shared_operand() {
252 ; CHECK-LABEL: define i1 @"{{.+}}shared_operandrepro"() {
254 ; CHECK-NEXT: %sub = sub i8 0, 0
255 ; CHECK-NEXT: %sub.2 = sub nuw i8 %sub, 0
256 ; CHECK-NEXT: %c.5 = icmp ult i8 %sub.2, %sub
257 ; CHECK-NEXT: ret i1 %c.5
262 %sub.2 = sub nuw i8 %sub, 0
263 %c.5 = icmp ult i8 %sub.2, %sub
267 @glob = external global i32
269 define i1 @load_global() {
270 ; CHECK-LABEL: define i1 @"{{.*}}load_globalrepro"(i32 %l) {
272 ; CHECK-NEXT: %c = icmp ugt i32 %l, %l
273 ; CHECK-NEXT: ret i1 %c
277 %l = load i32, ptr @glob, align 8
278 %c = icmp ugt i32 %l, %l
282 define i1 @test_ptr_null_constant(ptr %a) {
283 ; CHECK-LABEL: define i1 @"{{.+}}test_ptr_null_constantrepro"(ptr %a) {
285 ; CHECK-NEXT: %0 = icmp eq ptr %a, null
286 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
287 ; CHECK-NEXT: %c.2 = icmp eq ptr %a, null
288 ; CHECK-NEXT: ret i1 %c.2
292 %c.1 = icmp eq ptr %a, null
293 br i1 %c.1, label %then, label %else
296 %c.2 = icmp eq ptr %a, null
303 define i1 @test_both_signed_and_unsigned_conds_needed_in_reproducer(ptr %src, ptr %lower, ptr %upper, i16 %N) {
304 ; CHECK-LABEL: define i1 @"{{.+}}test_both_signed_and_unsigned_conds_needed_in_reproducerrepro"(i16 %N, ptr %src) {
306 ; CHECK-NEXT: %0 = icmp sge i16 %N, 0
307 ; CHECK-NEXT: call void @llvm.assume(i1 %0)
308 ; CHECK-NEXT: %src.end = getelementptr inbounds i8, ptr %src, i16 %N
309 ; CHECK-NEXT: %cmp.src.start = icmp ule ptr %src, %src.end
310 ; CHECK-NEXT: ret i1 %cmp.src.start
314 %N.pos = icmp sge i16 %N, 0
315 br i1 %N.pos, label %then, label %else
318 %src.end = getelementptr inbounds i8, ptr %src, i16 %N
319 %cmp.src.start = icmp ule ptr %src, %src.end
320 ret i1 %cmp.src.start