1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7declare void @llvm.assume(i1) #1
8
9define i1 @nonnull0_true(i8* %x) {
10; CHECK-LABEL: @nonnull0_true(
11; CHECK-NEXT:    [[A:%.*]] = icmp ne i8* [[X:%.*]], null
12; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
13; CHECK-NEXT:    ret i1 true
14;
15  %a = icmp ne i8* %x, null
16  call void @llvm.assume(i1 %a)
17  %q = icmp ne i8* %x, null
18  ret i1 %q
19}
20
21define i1 @nonnull1_true(i8* %x) {
22; CHECK-LABEL: @nonnull1_true(
23; CHECK-NEXT:    [[INTPTR:%.*]] = ptrtoint i8* [[X:%.*]] to i64
24; CHECK-NEXT:    [[A:%.*]] = icmp ne i64 [[INTPTR]], 0
25; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
26; CHECK-NEXT:    ret i1 true
27;
28  %intptr = ptrtoint i8* %x to i64
29  %a = icmp ne i64 %intptr, 0
30  call void @llvm.assume(i1 %a)
31  %q = icmp ne i8* %x, null
32  ret i1 %q
33}
34
35define i1 @nonnull2_true(i8 %x, i8 %y) {
36; CHECK-LABEL: @nonnull2_true(
37; CHECK-NEXT:    [[A:%.*]] = icmp ugt i8 [[X:%.*]], [[Y:%.*]]
38; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
39; CHECK-NEXT:    ret i1 true
40;
41  %a = icmp ugt i8 %x, %y
42  call void @llvm.assume(i1 %a)
43  %q = icmp ne i8 %x, 0
44  ret i1 %q
45}
46define i1 @nonnull2_true_swapped(i8 %x, i8 %y) {
47; CHECK-LABEL: @nonnull2_true_swapped(
48; CHECK-NEXT:    [[A:%.*]] = icmp ult i8 [[Y:%.*]], [[X:%.*]]
49; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
50; CHECK-NEXT:    ret i1 true
51;
52  %a = icmp ult i8 %y, %x
53  call void @llvm.assume(i1 %a)
54  %q = icmp ne i8 %x, 0
55  ret i1 %q
56}
57
58define i1 @nonnull3_unknown(i8 %x) {
59; CHECK-LABEL: @nonnull3_unknown(
60; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X:%.*]], 0
61; CHECK-NEXT:    ret i1 [[Q]]
62;
63  %a = icmp uge i8 %x, 0
64  call void @llvm.assume(i1 %a)
65  %q = icmp ne i8 %x, 0
66  ret i1 %q
67}
68define i1 @nonnull4_true(i8 %x) {
69; CHECK-LABEL: @nonnull4_true(
70; CHECK-NEXT:    [[A:%.*]] = icmp uge i8 [[X:%.*]], 1
71; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
72; CHECK-NEXT:    ret i1 true
73;
74  %a = icmp uge i8 %x, 1
75  call void @llvm.assume(i1 %a)
76  %q = icmp ne i8 %x, 0
77  ret i1 %q
78}
79
80define i1 @nonnull5_unknown(i8 %x) {
81; CHECK-LABEL: @nonnull5_unknown(
82; CHECK-NEXT:    [[A:%.*]] = icmp sgt i8 [[X:%.*]], -1
83; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
84; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
85; CHECK-NEXT:    ret i1 [[Q]]
86;
87  %a = icmp sgt i8 %x, -1
88  call void @llvm.assume(i1 %a)
89  %q = icmp ne i8 %x, 0
90  ret i1 %q
91}
92define i1 @nonnull6_true(i8 %x) {
93; CHECK-LABEL: @nonnull6_true(
94; CHECK-NEXT:    [[A:%.*]] = icmp sgt i8 [[X:%.*]], 0
95; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
96; CHECK-NEXT:    ret i1 true
97;
98  %a = icmp sgt i8 %x, 0
99  call void @llvm.assume(i1 %a)
100  %q = icmp ne i8 %x, 0
101  ret i1 %q
102}
103define i1 @nonnull7_true(i8 %x) {
104; CHECK-LABEL: @nonnull7_true(
105; CHECK-NEXT:    [[A:%.*]] = icmp sgt i8 [[X:%.*]], 1
106; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
107; CHECK-NEXT:    ret i1 true
108;
109  %a = icmp sgt i8 %x, 1
110  call void @llvm.assume(i1 %a)
111  %q = icmp ne i8 %x, 0
112  ret i1 %q
113}
114
115define i1 @nonnull8_unknown(i8 %x) {
116; CHECK-LABEL: @nonnull8_unknown(
117; CHECK-NEXT:    [[A:%.*]] = icmp sge i8 [[X:%.*]], -1
118; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
119; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
120; CHECK-NEXT:    ret i1 [[Q]]
121;
122  %a = icmp sge i8 %x, -1
123  call void @llvm.assume(i1 %a)
124  %q = icmp ne i8 %x, 0
125  ret i1 %q
126}
127define i1 @nonnull9_unknown(i8 %x) {
128; CHECK-LABEL: @nonnull9_unknown(
129; CHECK-NEXT:    [[A:%.*]] = icmp sge i8 [[X:%.*]], 0
130; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
131; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
132; CHECK-NEXT:    ret i1 [[Q]]
133;
134  %a = icmp sge i8 %x, 0
135  call void @llvm.assume(i1 %a)
136  %q = icmp ne i8 %x, 0
137  ret i1 %q
138}
139define i1 @nonnull10_true(i8 %x) {
140; CHECK-LABEL: @nonnull10_true(
141; CHECK-NEXT:    [[A:%.*]] = icmp sge i8 [[X:%.*]], 1
142; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
143; CHECK-NEXT:    ret i1 true
144;
145  %a = icmp sge i8 %x, 1
146  call void @llvm.assume(i1 %a)
147  %q = icmp ne i8 %x, 0
148  ret i1 %q
149}
150
151define i1 @nonnull11_true(i8 %x) {
152; CHECK-LABEL: @nonnull11_true(
153; CHECK-NEXT:    [[A:%.*]] = icmp slt i8 [[X:%.*]], 0
154; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
155; CHECK-NEXT:    ret i1 true
156;
157  %a = icmp slt i8 %x, 0
158  call void @llvm.assume(i1 %a)
159  %q = icmp ne i8 %x, 0
160  ret i1 %q
161}
162define i1 @nonnull12_unknown(i8 %x) {
163; CHECK-LABEL: @nonnull12_unknown(
164; CHECK-NEXT:    [[A:%.*]] = icmp slt i8 [[X:%.*]], 1
165; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
166; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
167; CHECK-NEXT:    ret i1 [[Q]]
168;
169  %a = icmp slt i8 %x, 1
170  call void @llvm.assume(i1 %a)
171  %q = icmp ne i8 %x, 0
172  ret i1 %q
173}
174define i1 @nonnull13_unknown(i8 %x) {
175; CHECK-LABEL: @nonnull13_unknown(
176; CHECK-NEXT:    [[A:%.*]] = icmp slt i8 [[X:%.*]], 2
177; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
178; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
179; CHECK-NEXT:    ret i1 [[Q]]
180;
181  %a = icmp slt i8 %x, 2
182  call void @llvm.assume(i1 %a)
183  %q = icmp ne i8 %x, 0
184  ret i1 %q
185}
186
187define i1 @nonnull14_true(i8 %x) {
188; CHECK-LABEL: @nonnull14_true(
189; CHECK-NEXT:    [[A:%.*]] = icmp sle i8 [[X:%.*]], -1
190; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
191; CHECK-NEXT:    ret i1 true
192;
193  %a = icmp sle i8 %x, -1
194  call void @llvm.assume(i1 %a)
195  %q = icmp ne i8 %x, 0
196  ret i1 %q
197}
198define i1 @nonnull15_unknown(i8 %x) {
199; CHECK-LABEL: @nonnull15_unknown(
200; CHECK-NEXT:    [[A:%.*]] = icmp sle i8 [[X:%.*]], 0
201; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
202; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
203; CHECK-NEXT:    ret i1 [[Q]]
204;
205  %a = icmp sle i8 %x, 0
206  call void @llvm.assume(i1 %a)
207  %q = icmp ne i8 %x, 0
208  ret i1 %q
209}
210define i1 @nonnull16_unknown(i8 %x) {
211; CHECK-LABEL: @nonnull16_unknown(
212; CHECK-NEXT:    [[A:%.*]] = icmp sle i8 [[X:%.*]], 1
213; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
214; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
215; CHECK-NEXT:    ret i1 [[Q]]
216;
217  %a = icmp sle i8 %x, 1
218  call void @llvm.assume(i1 %a)
219  %q = icmp ne i8 %x, 0
220  ret i1 %q
221}
222define i1 @nonnull17_unknown(i8 %x) {
223; CHECK-LABEL: @nonnull17_unknown(
224; CHECK-NEXT:    [[A:%.*]] = icmp sle i8 [[X:%.*]], 2
225; CHECK-NEXT:    call void @llvm.assume(i1 [[A]])
226; CHECK-NEXT:    [[Q:%.*]] = icmp ne i8 [[X]], 0
227; CHECK-NEXT:    ret i1 [[Q]]
228;
229  %a = icmp sle i8 %x, 2
230  call void @llvm.assume(i1 %a)
231  %q = icmp ne i8 %x, 0
232  ret i1 %q
233}
234