1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -instcombine -S < %s | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4"
5target triple = "x86_64-unknown-linux-gnu"
6
7define i8 addrspace(4)* @f_0() {
8; CHECK-LABEL: @f_0(
9; CHECK-NEXT:    ret i8 addrspace(4)* getelementptr (i8, i8 addrspace(4)* null, i64 50)
10;
11  %result = getelementptr i8, i8 addrspace(4)* null, i64 50
12  ret i8 addrspace(4)* %result
13}
14
15define i8 addrspace(3)* @f_1() {
16; inttoptr is fine here since addrspace(3) is integral.
17; CHECK-LABEL: @f_1(
18; CHECK-NEXT:    ret i8 addrspace(3)* inttoptr (i64 50 to i8 addrspace(3)*)
19;
20  %result = getelementptr i8, i8 addrspace(3)* null, i64 50
21  ret i8 addrspace(3)* %result
22}
23
24define void @f_2(i8 addrspace(4)** %ptr0, i8 addrspace(4)** %ptr1) {
25; It is not okay to convert the load/store pair to load and store
26; integers, since pointers in address space 4 are non-integral.
27; CHECK-LABEL: @f_2(
28; CHECK-NEXT:  entry:
29; CHECK-NEXT:    [[VAL:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)** [[PTR0:%.*]], align 8
30; CHECK-NEXT:    store i8 addrspace(4)* [[VAL]], i8 addrspace(4)** [[PTR1:%.*]], align 8
31; CHECK-NEXT:    ret void
32;
33entry:
34  %val = load i8 addrspace(4)*, i8 addrspace(4)** %ptr0
35  store i8 addrspace(4)* %val, i8 addrspace(4)** %ptr1
36  ret void
37}
38
39define void @f_3(i8 addrspace(3)** %ptr0, i8 addrspace(3)** %ptr1) {
40; It *is* okay to convert the load/store pair to load and store
41; integers, since pointers in address space 3 are integral.
42; CHECK-LABEL: @f_3(
43; CHECK-NEXT:  entry:
44; CHECK-NEXT:    [[TMP0:%.*]] = bitcast i8 addrspace(3)** [[PTR0:%.*]] to i64*
45; CHECK-NEXT:    [[VAL1:%.*]] = load i64, i64* [[TMP0]], align 8
46; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8 addrspace(3)** [[PTR1:%.*]] to i64*
47; CHECK-NEXT:    store i64 [[VAL1]], i64* [[TMP1]], align 8
48; CHECK-NEXT:    ret void
49;
50entry:
51  %val = load i8 addrspace(3)*, i8 addrspace(3)** %ptr0
52  store i8 addrspace(3)* %val, i8 addrspace(3)** %ptr1
53  ret void
54}
55
56define i64 @g(i8 addrspace(4)** %gp) {
57; CHECK-LABEL: @g(
58; CHECK-NEXT:    [[DOTPRE:%.*]] = load i8 addrspace(4)*, i8 addrspace(4)** [[GP:%.*]], align 8
59; CHECK-NEXT:    [[V74:%.*]] = call i8 addrspace(4)* @alloc()
60; CHECK-NEXT:    [[V77:%.*]] = getelementptr i8, i8 addrspace(4)* [[V74]], i64 -8
61; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8 addrspace(4)* [[V77]] to i8 addrspace(4)* addrspace(4)*
62; CHECK-NEXT:    [[TMP2:%.*]] = addrspacecast i8 addrspace(4)* addrspace(4)* [[TMP1]] to i8 addrspace(4)**
63; CHECK-NEXT:    store i8 addrspace(4)* [[DOTPRE]], i8 addrspace(4)** [[TMP2]], align 8
64; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i8 addrspace(4)* [[V77]] to i64 addrspace(4)*
65; CHECK-NEXT:    [[V80:%.*]] = addrspacecast i64 addrspace(4)* [[TMP3]] to i64*
66; CHECK-NEXT:    [[V81:%.*]] = load i64, i64* [[V80]], align 8
67; CHECK-NEXT:    ret i64 [[V81]]
68;
69  %.pre = load i8 addrspace(4)*, i8 addrspace(4)** %gp, align 8
70  %v74 = call i8 addrspace(4)* @alloc()
71  %v75 = addrspacecast i8 addrspace(4)* %v74 to i8*
72  %v76 = bitcast i8* %v75 to i8 addrspace(4)**
73  %v77 = getelementptr i8 addrspace(4)*, i8 addrspace(4)** %v76, i64 -1
74  store i8 addrspace(4)* %.pre, i8 addrspace(4)** %v77, align 8
75  %v80 = bitcast i8 addrspace(4)** %v77 to i64*
76  %v81 = load i64, i64* %v80, align 8
77  ret i64 %v81
78}
79
80define i64 @g2(i8* addrspace(4)* %gp) {
81; CHECK-LABEL: @g2(
82; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* addrspace(4)* [[GP:%.*]] to i64 addrspace(4)*
83; CHECK-NEXT:    [[DOTPRE1:%.*]] = load i64, i64 addrspace(4)* [[TMP1]], align 8
84; CHECK-NEXT:    [[V74:%.*]] = call i8 addrspace(4)* @alloc()
85; CHECK-NEXT:    [[V77:%.*]] = getelementptr i8, i8 addrspace(4)* [[V74]], i64 -8
86; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8 addrspace(4)* [[V77]] to i64 addrspace(4)*
87; CHECK-NEXT:    store i64 [[DOTPRE1]], i64 addrspace(4)* [[TMP2]], align 8
88; CHECK-NEXT:    ret i64 [[DOTPRE1]]
89;
90  %.pre = load i8*, i8* addrspace(4)* %gp, align 8
91  %v74 = call i8 addrspace(4)* @alloc()
92  %v76 = bitcast i8 addrspace(4)* %v74 to i8* addrspace(4)*
93  %v77 = getelementptr i8*, i8* addrspace(4)* %v76, i64 -1
94  store i8* %.pre, i8* addrspace(4)* %v77, align 8
95  %v80 = bitcast i8* addrspace(4)* %v77 to i64 addrspace(4)*
96  %v81 = load i64, i64 addrspace(4)* %v80, align 8
97  ret i64 %v81
98}
99
100declare i8 addrspace(4)* @alloc()
101
102define i64 @f_4(i8 addrspace(4)* %v0) {
103; CHECK-LABEL: @f_4(
104; CHECK-NEXT:    [[V6:%.*]] = call i64 bitcast (i64 (i64)* @f_5 to i64 (i8 addrspace(4)*)*)(i8 addrspace(4)* [[V0:%.*]])
105; CHECK-NEXT:    ret i64 [[V6]]
106;
107  %v5 = bitcast i64 (i64)* @f_5 to i64 (i8 addrspace(4)*)*
108  %v6 = call i64 %v5(i8 addrspace(4)* %v0)
109  ret i64 %v6
110}
111
112declare i64 @f_5(i64)
113