1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -newgvn < %s | FileCheck %s
4 define i32 addrspace(1)* @addrspacecast(i32* %ptr) {
5 ; CHECK-LABEL: @addrspacecast(
7 ; CHECK-NEXT: [[Z1:%.*]] = addrspacecast i32* [[PTR:%.*]] to i32 addrspace(1)*
8 ; CHECK-NEXT: br label [[BLOCK2:%.*]]
10 ; CHECK-NEXT: store i32 addrspace(1)* [[Z1]], i32 addrspace(1)** undef
11 ; CHECK-NEXT: ret i32 addrspace(1)* [[Z1]]
14 %z1 = addrspacecast i32* %ptr to i32 addrspace(1)*
18 %z2 = addrspacecast i32* %ptr to i32 addrspace(1)*
19 store i32 addrspace(1)* %z1, i32 addrspace(1)** undef
20 ret i32 addrspace(1)* %z2
23 ; Make sure casts with the same source value but different result
24 ; address spaces aren't incorrectly merged.
25 define i32 addrspace(1)* @addrspacecast_different_result_types(i32* %ptr) {
26 ; CHECK-LABEL: @addrspacecast_different_result_types(
28 ; CHECK-NEXT: [[Z1:%.*]] = addrspacecast i32* [[PTR:%.*]] to i32 addrspace(2)*
29 ; CHECK-NEXT: br label [[BLOCK2:%.*]]
31 ; CHECK-NEXT: [[Z2:%.*]] = addrspacecast i32* [[PTR]] to i32 addrspace(1)*
32 ; CHECK-NEXT: store i32 addrspace(2)* [[Z1]], i32 addrspace(2)** undef
33 ; CHECK-NEXT: ret i32 addrspace(1)* [[Z2]]
36 %z1 = addrspacecast i32* %ptr to i32 addrspace(2)*
40 %z2 = addrspacecast i32* %ptr to i32 addrspace(1)*
41 store i32 addrspace(2)* %z1, i32 addrspace(2)** undef
42 ret i32 addrspace(1)* %z2
45 define i32 addrspace(1)* @addrspacecast_simplify(i32 addrspace(1)* %ptr) {
46 ; CHECK-LABEL: @addrspacecast_simplify(
48 ; CHECK-NEXT: [[CAST0:%.*]] = addrspacecast i32 addrspace(1)* [[PTR:%.*]] to i32*
49 ; CHECK-NEXT: br label [[BLOCK2:%.*]]
51 ; CHECK-NEXT: store i32 addrspace(1)* [[PTR]], i32 addrspace(1)** undef
52 ; CHECK-NEXT: ret i32 addrspace(1)* [[PTR]]
55 %cast0 = addrspacecast i32 addrspace(1)* %ptr to i32*
56 %z1 = addrspacecast i32* %cast0 to i32 addrspace(1)*
60 %z2 = addrspacecast i32* %cast0 to i32 addrspace(1)*
61 store i32 addrspace(1)* %z1, i32 addrspace(1)** undef
62 ret i32 addrspace(1)* %z2
65 @h = common local_unnamed_addr global i32* null, align 4
67 define i32 addrspace(1)* @addrspacecast_constant() {
68 ; CHECK-LABEL: @addrspacecast_constant(
70 ; CHECK-NEXT: store i32* undef, i32** @h, align 4
71 ; CHECK-NEXT: br label [[BLOCK2:%.*]]
73 ; CHECK-NEXT: store i32 addrspace(1)* undef, i32 addrspace(1)** undef
74 ; CHECK-NEXT: ret i32 addrspace(1)* undef
77 store i32* undef, i32** @h, align 4
78 %ptr = load i32*, i32** @h, align 4
79 %z1 = addrspacecast i32* %ptr to i32 addrspace(1)*
83 %z2 = addrspacecast i32* %ptr to i32 addrspace(1)*
84 store i32 addrspace(1)* %z1, i32 addrspace(1)** undef
85 ret i32 addrspace(1)* %z2
88 define i32 addrspace(1)* @addrspacecast_leader(i32** %arg.ptr) {
89 ; CHECK-LABEL: @addrspacecast_leader(
91 ; CHECK-NEXT: [[LOAD0:%.*]] = load i32*, i32** [[ARG_PTR:%.*]]
92 ; CHECK-NEXT: [[Z1:%.*]] = addrspacecast i32* [[LOAD0]] to i32 addrspace(1)*
93 ; CHECK-NEXT: br label [[BLOCK2:%.*]]
95 ; CHECK-NEXT: store i32 addrspace(1)* [[Z1]], i32 addrspace(1)** undef
96 ; CHECK-NEXT: ret i32 addrspace(1)* [[Z1]]
99 %load0 = load i32*, i32** %arg.ptr
100 %z1 = addrspacecast i32* %load0 to i32 addrspace(1)*
104 %load1 = load i32*, i32** %arg.ptr
105 %z2 = addrspacecast i32* %load1 to i32 addrspace(1)*
106 store i32 addrspace(1)* %z1, i32 addrspace(1)** undef
107 ret i32 addrspace(1)* %z2