1 ; RUN: opt -instcombine -S < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4"
4 target triple = "x86_64-unknown-linux-gnu"
6 define i8 addrspace(4)* @f_0() {
8 ; CHECK: ret i8 addrspace(4)* getelementptr (i8, i8 addrspace(4)* null, i64 50)
9 %result = getelementptr i8, i8 addrspace(4)* null, i64 50
10 ret i8 addrspace(4)* %result
13 define i8 addrspace(3)* @f_1() {
14 ; inttoptr is fine here since addrspace(3) is integral.
17 ; CHECK: ret i8 addrspace(3)* inttoptr (i64 50 to i8 addrspace(3)*)
18 %result = getelementptr i8, i8 addrspace(3)* null, i64 50
19 ret i8 addrspace(3)* %result
22 define void @f_2(i8 addrspace(4)** %ptr0, i8 addrspace(4)** %ptr1) {
23 ; It is not okay to convert the load/store pair to load and store
24 ; integers, since pointers in address space 4 are non-integral.
28 ; CHECK: %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0, align 8
29 ; CHECK: store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1, align 8
31 ; CHECK-NOT: store i64
32 %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0
33 store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1
37 define void @f_3(i8 addrspace(3)** %ptr0, i8 addrspace(3)** %ptr1) {
38 ; It *is* okay to convert the load/store pair to load and store
39 ; integers, since pointers in address space 3 are integral.
45 %val = load i8 addrspace(3)*, i8 addrspace(3)** %ptr0
46 store i8 addrspace(3)* %val, i8 addrspace(3)** %ptr1
50 define i64 @g(i8 addrspace(4)** %gp) {
53 %.pre = load i8 addrspace(4)*, i8 addrspace(4)** %gp, align 8
54 %v74 = call i8 addrspace(4)* @alloc()
55 %v75 = addrspacecast i8 addrspace(4)* %v74 to i8*
56 %v76 = bitcast i8* %v75 to i8 addrspace(4)**
57 %v77 = getelementptr i8 addrspace(4)*, i8 addrspace(4)** %v76, i64 -1
59 store i8 addrspace(4)* %.pre, i8 addrspace(4)** %v77, align 8
60 %v80 = bitcast i8 addrspace(4)** %v77 to i64*
63 %v81 = load i64, i64* %v80, align 8
67 define i64 @g2(i8* addrspace(4)* %gp) {
70 %.pre = load i8*, i8* addrspace(4)* %gp, align 8
71 %v74 = call i8 addrspace(4)* @alloc()
72 %v76 = bitcast i8 addrspace(4)* %v74 to i8* addrspace(4)*
73 %v77 = getelementptr i8*, i8* addrspace(4)* %v76, i64 -1
75 store i8* %.pre, i8* addrspace(4)* %v77, align 8
76 %v80 = bitcast i8* addrspace(4)* %v77 to i64 addrspace(4)*
78 %v81 = load i64, i64 addrspace(4)* %v80, align 8
82 declare i8 addrspace(4)* @alloc()
84 define i64 @f_4(i8 addrspace(4)* %v0) {
87 %v5 = bitcast i64 (i64)* @f_5 to i64 (i8 addrspace(4)*)*
88 %v6 = call i64 %v5(i8 addrspace(4)* %v0)