1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S -verify | FileCheck %s
4 define i1 @ule_null_constexpr(i8* %x) {
5 ; CHECK-LABEL: @ule_null_constexpr(
6 ; CHECK-NEXT: ret i1 true
8 %cmp = icmp ule i8 (...)* null, bitcast (i1 (i8*)* @ule_null_constexpr to i8 (...)*)
12 define i1 @ugt_null_constexpr(i8* %x) {
13 ; CHECK-LABEL: @ugt_null_constexpr(
14 ; CHECK-NEXT: ret i1 false
16 %cmp = icmp ugt i8 (...)* null, bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*)
20 define i1 @uge_constexpr_null(i8* %x) {
21 ; CHECK-LABEL: @uge_constexpr_null(
22 ; CHECK-NEXT: ret i1 true
24 %cmp = icmp uge i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
28 define i1 @ult_constexpr_null(i8* %x) {
29 ; CHECK-LABEL: @ult_constexpr_null(
30 ; CHECK-NEXT: ret i1 false
32 %cmp = icmp ult i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
36 ; Negative test - we don't know if the constexpr is null.
38 define i1 @ule_constexpr_null(i8* %x) {
39 ; CHECK-LABEL: @ule_constexpr_null(
40 ; CHECK-NEXT: ret i1 false
42 %cmp = icmp ule i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
46 ; Negative test - we don't know if the constexpr is *signed* less-than null.
48 define i1 @slt_constexpr_null(i8* %x) {
49 ; CHECK-LABEL: @slt_constexpr_null(
50 ; CHECK-NEXT: ret i1 icmp slt (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null)
52 %cmp = icmp slt i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
56 ; Negative test - we don't try to evaluate this comparison of constant expressions.
58 define i1 @ult_constexpr_constexpr_one(i8* %x) {
59 ; CHECK-LABEL: @ult_constexpr_constexpr_one(
60 ; CHECK-NEXT: ret i1 icmp ult (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* inttoptr (i32 1 to i8 (...)*))
62 %cmp = icmp ult i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), inttoptr (i32 1 to i8 (...)*)
66 @g = global [2 x i32] [i32 1, i32 2]
69 define i1 @global_ne_null() {
70 ; CHECK-LABEL: @global_ne_null(
71 ; CHECK-NEXT: ret i1 true
73 %cmp = icmp ne [2 x i32]* @g, null
77 define i1 @global_ugt_null() {
78 ; CHECK-LABEL: @global_ugt_null(
79 ; CHECK-NEXT: ret i1 true
81 %cmp = icmp ugt [2 x i32]* @g, null
85 define i1 @global_sgt_null() {
86 ; CHECK-LABEL: @global_sgt_null(
87 ; CHECK-NEXT: ret i1 icmp sgt ([2 x i32]* @g, [2 x i32]* null)
89 %cmp = icmp sgt [2 x i32]* @g, null
93 define i1 @global_gep_ne_null() {
94 ; CHECK-LABEL: @global_gep_ne_null(
95 ; CHECK-NEXT: ret i1 true
97 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
98 %cmp = icmp ne [2 x i32]* %gep, null
102 define i1 @global_gep_ugt_null() {
103 ; CHECK-LABEL: @global_gep_ugt_null(
104 ; CHECK-NEXT: ret i1 true
106 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
107 %cmp = icmp ugt [2 x i32]* %gep, null
111 define i1 @global_gep_sgt_null() {
112 ; CHECK-LABEL: @global_gep_sgt_null(
113 ; CHECK-NEXT: ret i1 icmp sgt ([2 x i32]* getelementptr inbounds ([2 x i32], [2 x i32]* @g, i64 1), [2 x i32]* null)
115 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
116 %cmp = icmp sgt [2 x i32]* %gep, null
120 define i1 @null_gep_ne_null() {
121 ; CHECK-LABEL: @null_gep_ne_null(
122 ; CHECK-NEXT: ret i1 true
124 %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
125 %cmp = icmp ne i8* %gep, null
129 define i1 @null_gep_ugt_null() {
130 ; CHECK-LABEL: @null_gep_ugt_null(
131 ; CHECK-NEXT: ret i1 true
133 %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
134 %cmp = icmp ugt i8* %gep, null
138 define i1 @null_gep_sgt_null() {
139 ; CHECK-LABEL: @null_gep_sgt_null(
140 ; CHECK-NEXT: ret i1 icmp sgt (i8* getelementptr (i8, i8* null, i64 ptrtoint (i32* @g2 to i64)), i8* null)
142 %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
143 %cmp = icmp sgt i8* %gep, null
147 define i1 @null_gep_ne_global() {
148 ; CHECK-LABEL: @null_gep_ne_global(
149 ; CHECK-NEXT: ret i1 true
151 %gep = getelementptr [2 x i32], [2 x i32]* null, i64 ptrtoint (i32* @g2 to i64)
152 %cmp = icmp ne [2 x i32]* %gep, @g
156 define i1 @null_gep_ult_global() {
157 ; CHECK-LABEL: @null_gep_ult_global(
158 ; CHECK-NEXT: ret i1 true
160 %gep = getelementptr [2 x i32], [2 x i32]* null, i64 ptrtoint (i32* @g2 to i64)
161 %cmp = icmp ult [2 x i32]* %gep, @g
165 define i1 @null_gep_slt_global() {
166 ; CHECK-LABEL: @null_gep_slt_global(
167 ; CHECK-NEXT: ret i1 icmp slt ([2 x i32]* getelementptr ([2 x i32], [2 x i32]* null, i64 ptrtoint (i32* @g2 to i64)), [2 x i32]* @g)
169 %gep = getelementptr [2 x i32], [2 x i32]* null, i64 ptrtoint (i32* @g2 to i64)
170 %cmp = icmp slt [2 x i32]* %gep, @g
174 define i1 @global_gep_ne_global() {
175 ; CHECK-LABEL: @global_gep_ne_global(
176 ; CHECK-NEXT: ret i1 true
178 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
179 %cmp = icmp ne [2 x i32]* %gep, @g
183 define i1 @global_gep_ugt_global() {
184 ; CHECK-LABEL: @global_gep_ugt_global(
185 ; CHECK-NEXT: ret i1 true
187 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
188 %cmp = icmp ugt [2 x i32]* %gep, @g
192 define i1 @global_gep_sgt_global() {
193 ; CHECK-LABEL: @global_gep_sgt_global(
194 ; CHECK-NEXT: ret i1 icmp sgt ([2 x i32]* getelementptr inbounds ([2 x i32], [2 x i32]* @g, i64 1), [2 x i32]* @g)
196 %gep = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 1
197 %cmp = icmp sgt [2 x i32]* %gep, @g
201 define i1 @global_gep_ugt_global_neg_offset() {
202 ; CHECK-LABEL: @global_gep_ugt_global_neg_offset(
203 ; CHECK-NEXT: ret i1 true
205 %gep = getelementptr [2 x i32], [2 x i32]* @g, i64 -1
206 %cmp = icmp ugt [2 x i32]* %gep, @g
210 define i1 @global_gep_sgt_global_neg_offset() {
211 ; CHECK-LABEL: @global_gep_sgt_global_neg_offset(
212 ; CHECK-NEXT: ret i1 icmp sgt ([2 x i32]* getelementptr ([2 x i32], [2 x i32]* @g, i64 -1), [2 x i32]* @g)
214 %gep = getelementptr [2 x i32], [2 x i32]* @g, i64 -1
215 %cmp = icmp sgt [2 x i32]* %gep, @g