1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instsimplify < %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 %struct.A = type { [7 x i8] }
8 define %struct.A* @test1(%struct.A* %b, %struct.A* %e) {
10 ; CHECK-NEXT: ret %struct.A* [[E:%.*]]
12 %e_ptr = ptrtoint %struct.A* %e to i64
13 %b_ptr = ptrtoint %struct.A* %b to i64
14 %sub = sub i64 %e_ptr, %b_ptr
15 %sdiv = sdiv exact i64 %sub, 7
16 %gep = getelementptr inbounds %struct.A, %struct.A* %b, i64 %sdiv
20 define i8* @test2(i8* %b, i8* %e) {
21 ; CHECK-LABEL: @test2(
22 ; CHECK-NEXT: ret i8* [[E:%.*]]
24 %e_ptr = ptrtoint i8* %e to i64
25 %b_ptr = ptrtoint i8* %b to i64
26 %sub = sub i64 %e_ptr, %b_ptr
27 %gep = getelementptr inbounds i8, i8* %b, i64 %sub
31 define i64* @test3(i64* %b, i64* %e) {
32 ; CHECK-LABEL: @test3(
33 ; CHECK-NEXT: ret i64* [[E:%.*]]
35 %e_ptr = ptrtoint i64* %e to i64
36 %b_ptr = ptrtoint i64* %b to i64
37 %sub = sub i64 %e_ptr, %b_ptr
38 %ashr = ashr exact i64 %sub, 3
39 %gep = getelementptr inbounds i64, i64* %b, i64 %ashr
43 define %struct.A* @test4(%struct.A* %b) {
44 ; CHECK-LABEL: @test4(
45 ; CHECK-NEXT: ret %struct.A* null
47 %b_ptr = ptrtoint %struct.A* %b to i64
48 %sub = sub i64 0, %b_ptr
49 %sdiv = sdiv exact i64 %sub, 7
50 %gep = getelementptr inbounds %struct.A, %struct.A* %b, i64 %sdiv
54 define i8* @test5(i8* %b) {
55 ; CHECK-LABEL: @test5(
56 ; CHECK-NEXT: ret i8* null
58 %b_ptr = ptrtoint i8* %b to i64
59 %sub = sub i64 0, %b_ptr
60 %gep = getelementptr inbounds i8, i8* %b, i64 %sub
64 define i64* @test6(i64* %b) {
65 ; CHECK-LABEL: @test6(
66 ; CHECK-NEXT: ret i64* null
68 %b_ptr = ptrtoint i64* %b to i64
69 %sub = sub i64 0, %b_ptr
70 %ashr = ashr exact i64 %sub, 3
71 %gep = getelementptr inbounds i64, i64* %b, i64 %ashr
75 define i8* @test7(i8* %b, i8** %e) {
76 ; CHECK-LABEL: @test7(
77 ; CHECK-NEXT: [[E_PTR:%.*]] = ptrtoint i8** [[E:%.*]] to i64
78 ; CHECK-NEXT: [[B_PTR:%.*]] = ptrtoint i8* [[B:%.*]] to i64
79 ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[E_PTR]], [[B_PTR]]
80 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[B]], i64 [[SUB]]
81 ; CHECK-NEXT: ret i8* [[GEP]]
83 %e_ptr = ptrtoint i8** %e to i64
84 %b_ptr = ptrtoint i8* %b to i64
85 %sub = sub i64 %e_ptr, %b_ptr
86 %gep = getelementptr inbounds i8, i8* %b, i64 %sub
90 define <8 x i64*> @undef_vec1() {
91 ; CHECK-LABEL: @undef_vec1(
92 ; CHECK-NEXT: ret <8 x i64*> undef
94 %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef
98 define <8 x i64*> @undef_vec2() {
99 ; CHECK-LABEL: @undef_vec2(
100 ; CHECK-NEXT: ret <8 x i64*> undef
102 %el = getelementptr i64, <8 x i64*> undef, <8 x i64> undef