1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 declare void @llvm.assume(i1) #1
9 define i1 @nonnull0_true(ptr %x) {
10 ; CHECK-LABEL: @nonnull0_true(
11 ; CHECK-NEXT: [[A:%.*]] = icmp ne ptr [[X:%.*]], null
12 ; CHECK-NEXT: call void @llvm.assume(i1 [[A]])
13 ; CHECK-NEXT: ret i1 true
15 %a = icmp ne ptr %x, null
16 call void @llvm.assume(i1 %a)
17 %q = icmp ne ptr %x, null
21 define i1 @nonnull1_true(ptr %x) {
22 ; CHECK-LABEL: @nonnull1_true(
23 ; CHECK-NEXT: [[INTPTR:%.*]] = ptrtoint ptr [[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
28 %intptr = ptrtoint ptr %x to i64
29 %a = icmp ne i64 %intptr, 0
30 call void @llvm.assume(i1 %a)
31 %q = icmp ne ptr %x, null
35 define 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
41 %a = icmp ugt i8 %x, %y
42 call void @llvm.assume(i1 %a)
46 define 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
52 %a = icmp ult i8 %y, %x
53 call void @llvm.assume(i1 %a)
58 define 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]]
63 %a = icmp uge i8 %x, 0
64 call void @llvm.assume(i1 %a)
68 define 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
74 %a = icmp uge i8 %x, 1
75 call void @llvm.assume(i1 %a)
80 define 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]]
87 %a = icmp sgt i8 %x, -1
88 call void @llvm.assume(i1 %a)
92 define 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
98 %a = icmp sgt i8 %x, 0
99 call void @llvm.assume(i1 %a)
100 %q = icmp ne i8 %x, 0
103 define 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
109 %a = icmp sgt i8 %x, 1
110 call void @llvm.assume(i1 %a)
111 %q = icmp ne i8 %x, 0
115 define 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]]
122 %a = icmp sge i8 %x, -1
123 call void @llvm.assume(i1 %a)
124 %q = icmp ne i8 %x, 0
127 define 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]]
134 %a = icmp sge i8 %x, 0
135 call void @llvm.assume(i1 %a)
136 %q = icmp ne i8 %x, 0
139 define 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
145 %a = icmp sge i8 %x, 1
146 call void @llvm.assume(i1 %a)
147 %q = icmp ne i8 %x, 0
151 define 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
157 %a = icmp slt i8 %x, 0
158 call void @llvm.assume(i1 %a)
159 %q = icmp ne i8 %x, 0
162 define 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]]
169 %a = icmp slt i8 %x, 1
170 call void @llvm.assume(i1 %a)
171 %q = icmp ne i8 %x, 0
174 define 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]]
181 %a = icmp slt i8 %x, 2
182 call void @llvm.assume(i1 %a)
183 %q = icmp ne i8 %x, 0
187 define 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
193 %a = icmp sle i8 %x, -1
194 call void @llvm.assume(i1 %a)
195 %q = icmp ne i8 %x, 0
198 define 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]]
205 %a = icmp sle i8 %x, 0
206 call void @llvm.assume(i1 %a)
207 %q = icmp ne i8 %x, 0
210 define 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]]
217 %a = icmp sle i8 %x, 1
218 call void @llvm.assume(i1 %a)
219 %q = icmp ne i8 %x, 0
222 define 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]]
229 %a = icmp sle i8 %x, 2
230 call void @llvm.assume(i1 %a)
231 %q = icmp ne i8 %x, 0