1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 declare void @llvm.assume(i1)
6 define i1 @test(i8 %x, i8 %y) {
8 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: [[CMP_0:%.*]] = icmp uge i8 [[ADD]], 10
10 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP_0]])
11 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[X]] to i16
12 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i16 [[EXT]], 1
13 ; CHECK-NEXT: [[RES:%.*]] = xor i1 true, [[C_1]]
14 ; CHECK-NEXT: ret i1 [[RES]]
16 %add = add nuw nsw i8 %x, %y
17 %cmp.0 = icmp uge i8 %add, 10
18 tail call void @llvm.assume(i1 %cmp.0)
19 %ext = zext i8 %x to i16
20 %t.1 = icmp uge i16 %ext, 0
21 %c.1 = icmp uge i16 %ext, 1
22 %res = xor i1 %t.1, %c.1
26 define i1 @test2(i8 %x, i8 %y) {
27 ; CHECK-LABEL: @test2(
28 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[X:%.*]], [[Y:%.*]]
29 ; CHECK-NEXT: [[CMP_0:%.*]] = icmp uge i8 [[ADD]], 0
30 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP_0]])
31 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[X]] to i16
32 ; CHECK-NEXT: [[ADD_1:%.*]] = add nuw nsw i16 [[EXT]], 1
33 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i16 [[ADD_1]], 2
34 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_1]]
35 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], false
36 ; CHECK-NEXT: [[C_2:%.*]] = icmp sge i16 [[ADD_1]], 1
37 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[C_2]]
38 ; CHECK-NEXT: ret i1 [[RES_3]]
40 %add = add nuw nsw i8 %x, %y
41 %cmp.0 = icmp uge i8 %add, 0
42 tail call void @llvm.assume(i1 %cmp.0)
43 %ext = zext i8 %x to i16
44 %add.1 = add nuw nsw i16 %ext, 1
45 %t.1 = icmp uge i16 %add.1, 1
46 %c.1 = icmp uge i16 %add.1, 2
47 %f.1 = icmp ult i16 %add.1, 1
48 %res.1 = xor i1 %t.1, %c.1
49 %res.2 = xor i1 %res.1, %f.1
50 %c.2 = icmp sge i16 %add.1, 1
51 %res.3 = xor i1 %res.2, %c.2
55 define i1 @gep_zext_idx(ptr %p, i8 %cnt, i8 %off) {
56 ; CHECK-LABEL: @gep_zext_idx(
58 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[CNT:%.*]], [[OFF:%.*]]
59 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[ADD]], 10
60 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP]])
61 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[CNT]] to i16
62 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i16 [[EXT]]
63 ; CHECK-NEXT: [[GEP_11:%.*]] = getelementptr inbounds i32, ptr [[P]], i16 11
64 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt ptr [[ADD_PTR]], [[GEP_11]]
65 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, false
66 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_1]]
67 ; CHECK-NEXT: ret i1 [[RES_2]]
70 %add = add nuw nsw i8 %cnt, %off
71 %cmp = icmp ugt i8 %add, 10
72 tail call void @llvm.assume(i1 %cmp)
73 %ext = zext i8 %cnt to i16
74 %add.ptr = getelementptr inbounds i32, ptr %p, i16 %ext
75 %t.1 = icmp uge ptr %add.ptr, %p
76 %f.1 = icmp ult ptr %add.ptr, %p
77 %gep.11 = getelementptr inbounds i32, ptr %p, i16 11
78 %c.1 = icmp ugt ptr %add.ptr, %gep.11
79 %res.1 = xor i1 %t.1, %f.1
80 %res.2 = xor i1 %res.1, %c.1
84 define i1 @gep_zext_idx_adds(ptr %p, i8 %cnt, i8 %off) {
85 ; CHECK-LABEL: @gep_zext_idx_adds(
87 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[CNT:%.*]], [[OFF:%.*]]
88 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[ADD]], 10
89 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP]])
90 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[CNT]] to i16
91 ; CHECK-NEXT: [[EXT_1:%.*]] = add nuw nsw i16 [[EXT]], 1
92 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i16 [[EXT_1]]
93 ; CHECK-NEXT: [[GEP_11:%.*]] = getelementptr inbounds i32, ptr [[P]], i16 11
94 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge ptr [[ADD_PTR]], [[GEP_11]]
95 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, false
96 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_1]]
97 ; CHECK-NEXT: ret i1 [[RES_2]]
100 %add = add nuw nsw i8 %cnt, %off
101 %cmp = icmp uge i8 %add, 10
102 tail call void @llvm.assume(i1 %cmp)
103 %ext = zext i8 %cnt to i16
104 %ext.1 = add nuw nsw i16 %ext, 1
105 %add.ptr = getelementptr inbounds i32, ptr %p, i16 %ext.1
106 %t.1 = icmp uge ptr %add.ptr, %p
107 %f.1 = icmp ult ptr %add.ptr, %p
108 %gep.11 = getelementptr inbounds i32, ptr %p, i16 11
109 %c.1 = icmp uge ptr %add.ptr, %gep.11
110 %res.1 = xor i1 %t.1, %f.1
111 %res.2 = xor i1 %res.1, %c.1