1
; RUN: opt -S -instsimplify < %s | FileCheck %s
3
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5
%struct.A = type { [7 x i8] }
7
define %struct.A* @test1(%struct.A* %b, %struct.A* %e) {
8
%e_ptr = ptrtoint %struct.A* %e to i64
9
%b_ptr = ptrtoint %struct.A* %b to i64
10
%sub = sub i64 %e_ptr, %b_ptr
11
%sdiv = sdiv exact i64 %sub, 7
12
%gep = getelementptr inbounds %struct.A, %struct.A* %b, i64 %sdiv
15
; CHECK-NEXT: ret %struct.A* %e
18
define i8* @test2(i8* %b, i8* %e) {
19
%e_ptr = ptrtoint i8* %e to i64
20
%b_ptr = ptrtoint i8* %b to i64
21
%sub = sub i64 %e_ptr, %b_ptr
22
%gep = getelementptr inbounds i8, i8* %b, i64 %sub
25
; CHECK-NEXT: ret i8* %e
28
define i64* @test3(i64* %b, i64* %e) {
29
%e_ptr = ptrtoint i64* %e to i64
30
%b_ptr = ptrtoint i64* %b to i64
31
%sub = sub i64 %e_ptr, %b_ptr
32
%ashr = ashr exact i64 %sub, 3
33
%gep = getelementptr inbounds i64, i64* %b, i64 %ashr
36
; CHECK-NEXT: ret i64* %e
39
define %struct.A* @test4(%struct.A* %b) {
40
%b_ptr = ptrtoint %struct.A* %b to i64
41
%sub = sub i64 0, %b_ptr
42
%sdiv = sdiv exact i64 %sub, 7
43
%gep = getelementptr inbounds %struct.A, %struct.A* %b, i64 %sdiv
46
; CHECK-NEXT: ret %struct.A* null
49
define i8* @test5(i8* %b) {
50
%b_ptr = ptrtoint i8* %b to i64
51
%sub = sub i64 0, %b_ptr
52
%gep = getelementptr inbounds i8, i8* %b, i64 %sub
55
; CHECK-NEXT: ret i8* null
58
define i64* @test6(i64* %b) {
59
%b_ptr = ptrtoint i64* %b to i64
60
%sub = sub i64 0, %b_ptr
61
%ashr = ashr exact i64 %sub, 3
62
%gep = getelementptr inbounds i64, i64* %b, i64 %ashr
65
; CHECK-NEXT: ret i64* null
68
define i8* @test7(i8* %b, i8** %e) {
69
%e_ptr = ptrtoint i8** %e to i64
70
%b_ptr = ptrtoint i8* %b to i64
71
%sub = sub i64 %e_ptr, %b_ptr
72
%gep = getelementptr inbounds i8, i8* %b, i64 %sub
75
; CHECK-NEXT: ptrtoint
76
; CHECK-NEXT: ptrtoint
78
; CHECK-NEXT: getelementptr