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