1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -instsimplify < %s | FileCheck %s 3 4target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 5 6%struct.A = type { [7 x i8] } 7 8define %struct.A* @test1(%struct.A* %b, %struct.A* %e) { 9; CHECK-LABEL: @test1( 10; CHECK-NEXT: ret %struct.A* [[E:%.*]] 11; 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 17 ret %struct.A* %gep 18} 19 20define i8* @test2(i8* %b, i8* %e) { 21; CHECK-LABEL: @test2( 22; CHECK-NEXT: ret i8* [[E:%.*]] 23; 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 28 ret i8* %gep 29} 30 31define i64* @test3(i64* %b, i64* %e) { 32; CHECK-LABEL: @test3( 33; CHECK-NEXT: ret i64* [[E:%.*]] 34; 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 40 ret i64* %gep 41} 42 43define %struct.A* @test4(%struct.A* %b) { 44; CHECK-LABEL: @test4( 45; CHECK-NEXT: ret %struct.A* null 46; 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 51 ret %struct.A* %gep 52} 53 54define i8* @test5(i8* %b) { 55; CHECK-LABEL: @test5( 56; CHECK-NEXT: ret i8* null 57; 58 %b_ptr = ptrtoint i8* %b to i64 59 %sub = sub i64 0, %b_ptr 60 %gep = getelementptr inbounds i8, i8* %b, i64 %sub 61 ret i8* %gep 62} 63 64define i64* @test6(i64* %b) { 65; CHECK-LABEL: @test6( 66; CHECK-NEXT: ret i64* null 67; 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 72 ret i64* %gep 73} 74 75define 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]] 82; 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 87 ret i8* %gep 88} 89 90define <8 x i64*> @undef_vec1() { 91; CHECK-LABEL: @undef_vec1( 92; CHECK-NEXT: ret <8 x i64*> undef 93; 94 %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef 95 ret <8 x i64*> %el 96} 97 98define <8 x i64*> @undef_vec2() { 99; CHECK-LABEL: @undef_vec2( 100; CHECK-NEXT: ret <8 x i64*> undef 101; 102 %el = getelementptr i64, <8 x i64*> undef, <8 x i64> undef 103 ret <8 x i64*> %el 104} 105 106