1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
declare ptr @getptr()
declare void @use(ptr)
define i1 @eq_base(ptr %x, i64 %y) {
; CHECK-LABEL: @eq_base(
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp eq ptr %g, %x
ret i1 %r
}
define i1 @ne_base_commute(i64 %y) {
; CHECK-LABEL: @ne_base_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[R:%.*]] = icmp ne i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp ne ptr %x, %g
ret i1 %r
}
define i1 @ne_base_inbounds(ptr %x, i64 %y) {
; CHECK-LABEL: @ne_base_inbounds(
; CHECK-NEXT: [[R:%.*]] = icmp ne i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp ne ptr %g, %x
ret i1 %r
}
define i1 @eq_base_inbounds_commute(i64 %y) {
; CHECK-LABEL: @eq_base_inbounds_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp eq ptr %x, %g
ret i1 %r
}
define i1 @slt_base(ptr %x, i64 %y) {
; CHECK-LABEL: @slt_base(
; CHECK-NEXT: [[G:%.*]] = getelementptr i8, ptr [[X:%.*]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp slt ptr [[G]], [[X]]
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp slt ptr %g, %x
ret i1 %r
}
define i1 @sgt_base_commute(i64 %y) {
; CHECK-LABEL: @sgt_base_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[G:%.*]] = getelementptr i8, ptr [[X]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp sgt ptr [[X]], [[G]]
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp sgt ptr %x, %g
ret i1 %r
}
define i1 @slt_base_inbounds(ptr %x, i64 %y) {
; CHECK-LABEL: @slt_base_inbounds(
; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[X:%.*]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp slt ptr [[G]], [[X]]
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp slt ptr %g, %x
ret i1 %r
}
define i1 @sgt_base_inbounds_commute(i64 %y) {
; CHECK-LABEL: @sgt_base_inbounds_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[X]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp sgt ptr [[X]], [[G]]
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp sgt ptr %x, %g
ret i1 %r
}
define i1 @ult_base(ptr %x, i64 %y) {
; CHECK-LABEL: @ult_base(
; CHECK-NEXT: [[G:%.*]] = getelementptr i8, ptr [[X:%.*]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp ult ptr [[G]], [[X]]
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp ult ptr %g, %x
ret i1 %r
}
define i1 @ugt_base_commute(i64 %y) {
; CHECK-LABEL: @ugt_base_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[G:%.*]] = getelementptr i8, ptr [[X]], i64 [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp ugt ptr [[X]], [[G]]
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr i8, ptr %x, i64 %y
%r = icmp ugt ptr %x, %g
ret i1 %r
}
define i1 @ult_base_inbounds(ptr %x, i64 %y) {
; CHECK-LABEL: @ult_base_inbounds(
; CHECK-NEXT: [[R:%.*]] = icmp slt i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp ult ptr %g, %x
ret i1 %r
}
define i1 @ugt_base_inbounds_commute(i64 %y) {
; CHECK-LABEL: @ugt_base_inbounds_commute(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[R:%.*]] = icmp slt i64 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr inbounds i8, ptr %x, i64 %y
%r = icmp ugt ptr %x, %g
ret i1 %r
}
define i1 @ne_base_inbounds_use(ptr %x, i64 %y) {
; CHECK-LABEL: @ne_base_inbounds_use(
; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[X:%.*]], i64 [[Y:%.*]]
; CHECK-NEXT: call void @use(ptr [[G]])
; CHECK-NEXT: [[R:%.*]] = icmp ne i64 [[Y]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%g = getelementptr inbounds i8, ptr %x, i64 %y
call void @use(ptr %g)
%r = icmp ne ptr %g, %x
ret i1 %r
}
define i1 @eq_base_inbounds_commute_use(i64 %y) {
; CHECK-LABEL: @eq_base_inbounds_commute_use(
; CHECK-NEXT: [[X:%.*]] = call ptr @getptr()
; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[X]], i64 [[Y:%.*]]
; CHECK-NEXT: call void @use(ptr [[G]])
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[Y]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%x = call ptr @getptr() ; thwart complexity-based canonicalization
%g = getelementptr inbounds i8, ptr %x, i64 %y
call void @use(ptr %g)
%r = icmp eq ptr %x, %g
ret i1 %r
}
define i1 @eq_bitcast_base(ptr %p, i64 %x) {
; CHECK-LABEL: @eq_bitcast_base(
; CHECK-NEXT: [[GEP_IDX_MASK:%.*]] = and i64 [[X:%.*]], 9223372036854775807
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[GEP_IDX_MASK]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%gep = getelementptr [2 x i8], ptr %p, i64 %x, i64 0
%r = icmp eq ptr %gep, %p
ret i1 %r
}
define i1 @eq_bitcast_base_inbounds(ptr %p, i64 %x) {
; CHECK-LABEL: @eq_bitcast_base_inbounds(
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%gep = getelementptr inbounds [2 x i8], ptr %p, i64 %x, i64 0
%r = icmp eq ptr %gep, %p
ret i1 %r
}
@X = global [1000 x i32] zeroinitializer
define i1 @PR8882(i64 %i) {
; CHECK-LABEL: @PR8882(
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 1000
; CHECK-NEXT: ret i1 [[CMP]]
;
%p1 = getelementptr inbounds i32, ptr @X, i64 %i
%cmp = icmp eq ptr %p1, getelementptr inbounds ([1000 x i32], ptr @X, i64 1, i64 0)
ret i1 %cmp
}
@X_as1 = addrspace(1) global [1000 x i32] zeroinitializer
define i1 @test24_as1(i64 %i) {
; CHECK-LABEL: @test24_as1(
; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[I:%.*]], 65535
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP1]], 1000
; CHECK-NEXT: ret i1 [[CMP]]
;
%p1 = getelementptr inbounds i32, ptr addrspace(1) @X_as1, i64 %i
%cmp = icmp eq ptr addrspace(1) %p1, getelementptr inbounds ([1000 x i32], ptr addrspace(1) @X_as1, i64 1, i64 0)
ret i1 %cmp
}
; PR16244
define i1 @test71(ptr %x) {
; CHECK-LABEL: @test71(
; CHECK-NEXT: ret i1 false
;
%a = getelementptr i8, ptr %x, i64 8
%b = getelementptr inbounds i8, ptr %x, i64 8
%c = icmp ugt ptr %a, %b
ret i1 %c
}
define i1 @test71_as1(ptr addrspace(1) %x) {
; CHECK-LABEL: @test71_as1(
; CHECK-NEXT: ret i1 false
;
%a = getelementptr i8, ptr addrspace(1) %x, i64 8
%b = getelementptr inbounds i8, ptr addrspace(1) %x, i64 8
%c = icmp ugt ptr addrspace(1) %a, %b
ret i1 %c
}
declare i32 @test58_d(i64)
define i1 @test59(ptr %foo) {
; CHECK-LABEL: @test59(
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[FOO:%.*]], i64 2
; CHECK-NEXT: [[USE:%.*]] = ptrtoint ptr [[GEP1]] to i64
; CHECK-NEXT: [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])
; CHECK-NEXT: ret i1 true
;
%gep1 = getelementptr inbounds i32, ptr %foo, i64 2
%gep2 = getelementptr inbounds i8, ptr %foo, i64 10
%cmp = icmp ult ptr %gep1, %gep2
%use = ptrtoint ptr %gep1 to i64
%call = call i32 @test58_d(i64 %use)
ret i1 %cmp
}
define i1 @test59_as1(ptr addrspace(1) %foo) {
; CHECK-LABEL: @test59_as1(
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr addrspace(1) [[FOO:%.*]], i16 2
; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr addrspace(1) [[GEP1]] to i16
; CHECK-NEXT: [[USE:%.*]] = zext i16 [[TMP1]] to i64
; CHECK-NEXT: [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])
; CHECK-NEXT: ret i1 true
;
%gep1 = getelementptr inbounds i32, ptr addrspace(1) %foo, i64 2
%gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i64 10
%cmp = icmp ult ptr addrspace(1) %gep1, %gep2
%use = ptrtoint ptr addrspace(1) %gep1 to i64
%call = call i32 @test58_d(i64 %use)
ret i1 %cmp
}
define i1 @test60(ptr %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test60(
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nsw i64 [[I:%.*]], 2
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[GEP1_IDX]], [[J:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr inbounds i32, ptr %foo, i64 %i
%gep2 = getelementptr inbounds i8, ptr %foo, i64 %j
%cmp = icmp ult ptr %gep1, %gep2
ret i1 %cmp
}
define i1 @test_gep_ult_no_inbounds(ptr %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test_gep_ult_no_inbounds(
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[FOO:%.*]], i64 [[I:%.*]]
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[FOO]], i64 [[J:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[GEP1]], [[GEP2]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr i32, ptr %foo, i64 %i
%gep2 = getelementptr i8, ptr %foo, i64 %j
%cmp = icmp ult ptr %gep1, %gep2
ret i1 %cmp
}
define i1 @test_gep_eq_no_inbounds(ptr %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test_gep_eq_no_inbounds(
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl i64 [[I:%.*]], 2
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[GEP1_IDX]], [[J:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr i32, ptr %foo, i64 %i
%gep2 = getelementptr i8, ptr %foo, i64 %j
%cmp = icmp eq ptr %gep1, %gep2
ret i1 %cmp
}
define i1 @test60_as1(ptr addrspace(1) %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test60_as1(
; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[I:%.*]] to i16
; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[J:%.*]] to i16
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nsw i16 [[TMP1]], 2
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP2]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr inbounds i32, ptr addrspace(1) %foo, i64 %i
%gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i64 %j
%cmp = icmp ult ptr addrspace(1) %gep1, %gep2
ret i1 %cmp
}
; Same as test60, but look through an addrspacecast instead of a
; bitcast. This uses the same sized addrspace.
define i1 @test60_addrspacecast(ptr %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test60_addrspacecast(
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nsw i64 [[I:%.*]], 2
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[GEP1_IDX]], [[J:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%bit = addrspacecast ptr %foo to ptr addrspace(3)
%gep1 = getelementptr inbounds i32, ptr addrspace(3) %bit, i64 %i
%gep2 = getelementptr inbounds i8, ptr %foo, i64 %j
%cast1 = addrspacecast ptr addrspace(3) %gep1 to ptr
%cmp = icmp ult ptr %cast1, %gep2
ret i1 %cmp
}
define i1 @test60_addrspacecast_smaller(ptr %foo, i16 %i, i64 %j) {
; CHECK-LABEL: @test60_addrspacecast_smaller(
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nsw i16 [[I:%.*]], 2
; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[J:%.*]] to i16
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP1]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%bit = addrspacecast ptr %foo to ptr addrspace(1)
%gep1 = getelementptr inbounds i32, ptr addrspace(1) %bit, i16 %i
%gep2 = getelementptr inbounds i8, ptr %foo, i64 %j
%cast1 = addrspacecast ptr addrspace(1) %gep1 to ptr
%cmp = icmp ult ptr %cast1, %gep2
ret i1 %cmp
}
define i1 @test60_addrspacecast_larger(ptr addrspace(1) %foo, i32 %i, i16 %j) {
; CHECK-LABEL: @test60_addrspacecast_larger(
; CHECK-NEXT: [[I_TR:%.*]] = trunc i32 [[I:%.*]] to i16
; CHECK-NEXT: [[TMP1:%.*]] = shl i16 [[I_TR]], 2
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[TMP1]], [[J:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%bit = addrspacecast ptr addrspace(1) %foo to ptr addrspace(2)
%gep1 = getelementptr inbounds i32, ptr addrspace(2) %bit, i32 %i
%gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i16 %j
%cast1 = addrspacecast ptr addrspace(2) %gep1 to ptr addrspace(1)
%cmp = icmp ult ptr addrspace(1) %cast1, %gep2
ret i1 %cmp
}
define i1 @test61(ptr %foo, i64 %i, i64 %j) {
; CHECK-LABEL: @test61(
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[FOO:%.*]], i64 [[I:%.*]]
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[FOO]], i64 [[J:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[GEP1]], [[GEP2]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr i32, ptr %foo, i64 %i
%gep2 = getelementptr i8, ptr %foo, i64 %j
%cmp = icmp ult ptr %gep1, %gep2
ret i1 %cmp
; Don't transform non-inbounds GEPs.
}
define i1 @test61_as1(ptr addrspace(1) %foo, i16 %i, i16 %j) {
; CHECK-LABEL: @test61_as1(
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr addrspace(1) [[FOO:%.*]], i16 [[I:%.*]]
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr addrspace(1) [[FOO]], i16 [[J:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr addrspace(1) [[GEP1]], [[GEP2]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%gep1 = getelementptr i32, ptr addrspace(1) %foo, i16 %i
%gep2 = getelementptr i8, ptr addrspace(1) %foo, i16 %j
%cmp = icmp ult ptr addrspace(1) %gep1, %gep2
ret i1 %cmp
; Don't transform non-inbounds GEPs.
}
|