1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify,verify -S | FileCheck %s
4 define i1 @ule_null_constexpr(ptr %x) {
5 ; CHECK-LABEL: @ule_null_constexpr(
6 ; CHECK-NEXT: ret i1 true
8 %cmp = icmp ule ptr null, @ule_null_constexpr
12 define i1 @ugt_null_constexpr(ptr %x) {
13 ; CHECK-LABEL: @ugt_null_constexpr(
14 ; CHECK-NEXT: ret i1 false
16 %cmp = icmp ugt ptr null, @ugt_null_constexpr
20 define i1 @uge_constexpr_null(ptr %x) {
21 ; CHECK-LABEL: @uge_constexpr_null(
22 ; CHECK-NEXT: ret i1 true
24 %cmp = icmp uge ptr @ugt_null_constexpr, null
28 define i1 @ult_constexpr_null(ptr %x) {
29 ; CHECK-LABEL: @ult_constexpr_null(
30 ; CHECK-NEXT: ret i1 false
32 %cmp = icmp ult ptr @ugt_null_constexpr, null
36 ; Negative test - we don't know if the constexpr is null.
38 define i1 @ule_constexpr_null(ptr %x) {
39 ; CHECK-LABEL: @ule_constexpr_null(
40 ; CHECK-NEXT: ret i1 false
42 %cmp = icmp ule ptr @ugt_null_constexpr, null
46 ; Negative test - we don't know if the constexpr is *signed* less-than null.
48 define i1 @slt_constexpr_null(ptr %x) {
49 ; CHECK-LABEL: @slt_constexpr_null(
50 ; CHECK-NEXT: ret i1 icmp slt (ptr @ugt_null_constexpr, ptr null)
52 %cmp = icmp slt ptr @ugt_null_constexpr, null
56 ; Negative test - we don't try to evaluate this comparison of constant expressions.
58 define i1 @ult_constexpr_constexpr_one(ptr %x) {
59 ; CHECK-LABEL: @ult_constexpr_constexpr_one(
60 ; CHECK-NEXT: ret i1 icmp ugt (ptr inttoptr (i32 1 to ptr), ptr @ugt_null_constexpr)
62 %cmp = icmp ult ptr @ugt_null_constexpr, inttoptr (i32 1 to ptr)
66 @g = global [2 x i32] [i32 1, i32 2]
68 @g2_weak = extern_weak global i32
71 define i1 @global_ne_null() {
72 ; CHECK-LABEL: @global_ne_null(
73 ; CHECK-NEXT: ret i1 true
75 %cmp = icmp ne ptr @g, null
79 define i1 @global_ugt_null() {
80 ; CHECK-LABEL: @global_ugt_null(
81 ; CHECK-NEXT: ret i1 true
83 %cmp = icmp ugt ptr @g, null
87 define i1 @global_sgt_null() {
88 ; CHECK-LABEL: @global_sgt_null(
89 ; CHECK-NEXT: ret i1 icmp sgt (ptr @g, ptr null)
91 %cmp = icmp sgt ptr @g, null
95 ; Should not fold to true, as the gep computes a null value.
96 define i1 @global_out_of_bounds_gep_ne_null() {
97 ; CHECK-LABEL: @global_out_of_bounds_gep_ne_null(
98 ; CHECK-NEXT: ret i1 icmp ne (ptr getelementptr (i8, ptr @g3, i64 sub (i64 0, i64 ptrtoint (ptr @g3 to i64))), ptr null)
100 %cmp = icmp ne ptr getelementptr (i8, ptr @g3, i64 sub (i64 0, i64 ptrtoint (ptr @g3 to i64))), null
104 define i1 @global_inbounds_gep_ne_null() {
105 ; CHECK-LABEL: @global_inbounds_gep_ne_null(
106 ; CHECK-NEXT: ret i1 true
108 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
109 %cmp = icmp ne ptr %gep, null
113 define i1 @global_gep_ugt_null() {
114 ; CHECK-LABEL: @global_gep_ugt_null(
115 ; CHECK-NEXT: ret i1 true
117 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
118 %cmp = icmp ugt ptr %gep, null
122 define i1 @global_gep_sgt_null() {
123 ; CHECK-LABEL: @global_gep_sgt_null(
124 ; CHECK-NEXT: ret i1 icmp sgt (ptr getelementptr inbounds ([2 x i32], ptr @g, i64 1), ptr null)
126 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
127 %cmp = icmp sgt ptr %gep, null
131 ; @g2_weak may be null, in which case this is a zero-index GEP and the pointers
133 define i1 @null_gep_ne_null() {
134 ; CHECK-LABEL: @null_gep_ne_null(
135 ; CHECK-NEXT: ret i1 icmp ne (ptr getelementptr (i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)), ptr null)
137 %gep = getelementptr i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)
138 %cmp = icmp ne ptr %gep, null
142 define i1 @null_gep_ugt_null() {
143 ; CHECK-LABEL: @null_gep_ugt_null(
144 ; CHECK-NEXT: ret i1 icmp ugt (ptr getelementptr (i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)), ptr null)
146 %gep = getelementptr i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)
147 %cmp = icmp ugt ptr %gep, null
151 define i1 @null_gep_sgt_null() {
152 ; CHECK-LABEL: @null_gep_sgt_null(
153 ; CHECK-NEXT: ret i1 icmp sgt (ptr getelementptr (i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)), ptr null)
155 %gep = getelementptr i8, ptr null, i64 ptrtoint (ptr @g2_weak to i64)
156 %cmp = icmp sgt ptr %gep, null
160 define i1 @null_gep_ne_null_constant_int() {
161 ; CHECK-LABEL: @null_gep_ne_null_constant_int(
162 ; CHECK-NEXT: ret i1 true
164 %gep = getelementptr i8, ptr null, i64 1
165 %cmp = icmp ne ptr %gep, null
169 define i1 @null_gep_ugt_null_constant_int() {
170 ; CHECK-LABEL: @null_gep_ugt_null_constant_int(
171 ; CHECK-NEXT: ret i1 true
173 %gep = getelementptr i8, ptr null, i64 1
174 %cmp = icmp ugt ptr %gep, null
178 define i1 @null_gep_ne_global() {
179 ; CHECK-LABEL: @null_gep_ne_global(
180 ; CHECK-NEXT: ret i1 icmp ne (ptr getelementptr (i8, ptr null, i64 ptrtoint (ptr @g3 to i64)), ptr @g3)
182 %gep = getelementptr i8, ptr null, i64 ptrtoint (ptr @g3 to i64)
183 %cmp = icmp ne ptr %gep, @g3
187 define i1 @null_gep_ult_global() {
188 ; CHECK-LABEL: @null_gep_ult_global(
189 ; CHECK-NEXT: ret i1 icmp ult (ptr getelementptr (i8, ptr null, i64 ptrtoint (ptr @g3 to i64)), ptr @g3)
191 %gep = getelementptr i8, ptr null, i64 ptrtoint (ptr @g3 to i64)
192 %cmp = icmp ult ptr %gep, @g3
196 define i1 @null_gep_slt_global() {
197 ; CHECK-LABEL: @null_gep_slt_global(
198 ; CHECK-NEXT: ret i1 icmp slt (ptr getelementptr ([2 x i32], ptr null, i64 ptrtoint (ptr @g2 to i64)), ptr @g)
200 %gep = getelementptr [2 x i32], ptr null, i64 ptrtoint (ptr @g2 to i64)
201 %cmp = icmp slt ptr %gep, @g
205 define i1 @global_gep_ne_global() {
206 ; CHECK-LABEL: @global_gep_ne_global(
207 ; CHECK-NEXT: ret i1 true
209 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
210 %cmp = icmp ne ptr %gep, @g
214 define i1 @global_gep_ugt_global() {
215 ; CHECK-LABEL: @global_gep_ugt_global(
216 ; CHECK-NEXT: ret i1 true
218 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
219 %cmp = icmp ugt ptr %gep, @g
223 define i1 @global_gep_sgt_global() {
224 ; CHECK-LABEL: @global_gep_sgt_global(
225 ; CHECK-NEXT: ret i1 icmp sgt (ptr getelementptr inbounds ([2 x i32], ptr @g, i64 1), ptr @g)
227 %gep = getelementptr inbounds [2 x i32], ptr @g, i64 1
228 %cmp = icmp sgt ptr %gep, @g
232 ; This should not fold to true, as the offset is negative.
233 define i1 @global_gep_ugt_global_neg_offset() {
234 ; CHECK-LABEL: @global_gep_ugt_global_neg_offset(
235 ; CHECK-NEXT: ret i1 icmp ugt (ptr getelementptr ([2 x i32], ptr @g, i64 -1), ptr @g)
237 %gep = getelementptr [2 x i32], ptr @g, i64 -1
238 %cmp = icmp ugt ptr %gep, @g
242 define i1 @global_gep_sgt_global_neg_offset() {
243 ; CHECK-LABEL: @global_gep_sgt_global_neg_offset(
244 ; CHECK-NEXT: ret i1 icmp sgt (ptr getelementptr ([2 x i32], ptr @g, i64 -1), ptr @g)
246 %gep = getelementptr [2 x i32], ptr @g, i64 -1
247 %cmp = icmp sgt ptr %gep, @g
251 define i1 @global_gep_ugt_global_gep() {
252 ; CHECK-LABEL: @global_gep_ugt_global_gep(
253 ; CHECK-NEXT: ret i1 true
255 %gep2 = getelementptr inbounds [2 x i32], ptr @g, i64 0, i64 1
256 %cmp = icmp ugt ptr %gep2, @g
260 ; Should not fold due to signed comparison.
261 define i1 @global_gep_sgt_global_gep() {
262 ; CHECK-LABEL: @global_gep_sgt_global_gep(
263 ; CHECK-NEXT: ret i1 icmp sgt (ptr getelementptr inbounds ([2 x i32], ptr @g, i64 0, i64 1), ptr @g)
265 %gep2 = getelementptr inbounds [2 x i32], ptr @g, i64 0, i64 1
266 %cmp = icmp sgt ptr %gep2, @g
270 define i1 @global_gep_ugt_global_gep_complex() {
271 ; CHECK-LABEL: @global_gep_ugt_global_gep_complex(
272 ; CHECK-NEXT: ret i1 true
274 %gep3 = getelementptr inbounds i8, ptr @g, i64 2
275 %cmp = icmp ugt ptr %gep3, @g
281 define i1 @global_no_cfi() {
282 ; CHECK-LABEL: @global_no_cfi(
283 ; CHECK-NEXT: ret i1 icmp eq (ptr @func, ptr no_cfi @func)
285 %cmp = icmp eq ptr @func, no_cfi @func
289 define i1 @blockaddr_no_cfi() {
290 ; CHECK-LABEL: @blockaddr_no_cfi(
291 ; CHECK-NEXT: br label [[BB:%.*]]
293 ; CHECK-NEXT: ret i1 icmp eq (ptr blockaddress(@blockaddr_no_cfi, [[BB]]), ptr no_cfi @func)
298 %cmp = icmp eq ptr blockaddress(@blockaddr_no_cfi, %bb), no_cfi @func