1 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
3 ; Test that pure addrspacecast instructions not directly connected to
4 ; a memory operation are inferred.
6 ; CHECK-LABEL: @addrspacecast_gep_addrspacecast(
7 ; CHECK: %gep0 = getelementptr i32, ptr addrspace(3) %ptr, i64 9
8 ; CHECK-NEXT: store i32 8, ptr addrspace(3) %gep0, align 8
10 define void @addrspacecast_gep_addrspacecast(ptr addrspace(3) %ptr) {
11 %asc0 = addrspacecast ptr addrspace(3) %ptr to ptr
12 %gep0 = getelementptr i32, ptr %asc0, i64 9
13 %asc1 = addrspacecast ptr %gep0 to ptr addrspace(3)
14 store i32 8, ptr addrspace(3) %asc1, align 8
18 ; CHECK-LABEL: @addrspacecast_different_pointee_type(
19 ; CHECK: [[GEP:%.*]] = getelementptr i32, ptr addrspace(3) %ptr, i64 9
20 ; CHECK-NEXT: store i8 8, ptr addrspace(3) [[GEP]], align 8
21 ; CHECK-NEXT: ret void
22 define void @addrspacecast_different_pointee_type(ptr addrspace(3) %ptr) {
23 %asc0 = addrspacecast ptr addrspace(3) %ptr to ptr
24 %gep0 = getelementptr i32, ptr %asc0, i64 9
25 %asc1 = addrspacecast ptr %gep0 to ptr addrspace(3)
26 store i8 8, ptr addrspace(3) %asc1, align 8
30 ; CHECK-LABEL: @addrspacecast_to_memory(
31 ; CHECK: %gep0 = getelementptr i32, ptr addrspace(3) %ptr, i64 9
32 ; CHECK-NEXT: store volatile ptr addrspace(3) %gep0, ptr addrspace(1) undef
33 ; CHECK-NEXT: ret void
34 define void @addrspacecast_to_memory(ptr addrspace(3) %ptr) {
35 %asc0 = addrspacecast ptr addrspace(3) %ptr to ptr
36 %gep0 = getelementptr i32, ptr %asc0, i64 9
37 %asc1 = addrspacecast ptr %gep0 to ptr addrspace(3)
38 store volatile ptr addrspace(3) %asc1, ptr addrspace(1) undef
42 ; CHECK-LABEL: @multiuse_addrspacecast_gep_addrspacecast(
43 ; CHECK: %asc0 = addrspacecast ptr addrspace(3) %ptr to ptr
44 ; CHECK-NEXT: store volatile ptr %asc0, ptr addrspace(1) undef
45 ; CHECK-NEXT: %gep0 = getelementptr i32, ptr addrspace(3) %ptr, i64 9
46 ; CHECK-NEXT: store i32 8, ptr addrspace(3) %gep0, align 8
47 ; CHECK-NEXT: ret void
48 define void @multiuse_addrspacecast_gep_addrspacecast(ptr addrspace(3) %ptr) {
49 %asc0 = addrspacecast ptr addrspace(3) %ptr to ptr
50 store volatile ptr %asc0, ptr addrspace(1) undef
51 %gep0 = getelementptr i32, ptr %asc0, i64 9
52 %asc1 = addrspacecast ptr %gep0 to ptr addrspace(3)
53 store i32 8, ptr addrspace(3) %asc1, align 8