1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -S -passes=infer-address-spaces --verify-each %s | FileCheck %s
4 ; Inst can use a value multiple time. When we're inserting an addrspacecast to flat,
5 ; it's important all the identical uses use an indentical replacement, especially
8 define amdgpu_kernel void @test_phi() {
9 ; CHECK-LABEL: @test_phi(
11 ; CHECK-NEXT: [[LOADED_PTR:%.*]] = load ptr, ptr addrspace(4) null, align 8
12 ; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast ptr [[LOADED_PTR]] to ptr addrspace(1)
13 ; CHECK-NEXT: br label [[BB0:%.*]]
15 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr addrspace(1) [[TMP0]], i64 3
16 ; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr addrspace(1) [[GEP]] to ptr
17 ; CHECK-NEXT: switch i32 0, label [[END:%.*]] [
18 ; CHECK-NEXT: i32 1, label [[END]]
19 ; CHECK-NEXT: i32 4, label [[END]]
20 ; CHECK-NEXT: i32 5, label [[BB1:%.*]]
23 ; CHECK-NEXT: [[TMP2:%.*]] = load double, ptr addrspace(1) [[GEP]], align 16
24 ; CHECK-NEXT: br label [[END]]
26 ; CHECK-NEXT: [[RETVAL_SROA_0_0_I569_PH:%.*]] = phi ptr [ null, [[BB1]] ], [ [[TMP1]], [[BB0]] ], [ [[TMP1]], [[BB0]] ], [ [[TMP1]], [[BB0]] ]
27 ; CHECK-NEXT: ret void
30 %loaded.ptr = load ptr, ptr addrspace(4) null, align 8
34 %gep = getelementptr i64, ptr %loaded.ptr, i64 3
35 switch i32 0, label %end [
42 %0 = load double, ptr %gep, align 16
46 %retval.sroa.0.0.i569.ph = phi ptr [ null, %bb1 ], [ %gep, %bb0 ], [ %gep, %bb0 ], [ %gep, %bb0 ]
50 declare void @uses_ptrs(ptr, ptr, ptr)
52 ; We shouldn't treat PHIs differently, even other users should have the same treatment.
53 ; All occurences of %gep are replaced with an identical value.
54 define amdgpu_kernel void @test_other() {
55 ; CHECK-LABEL: @test_other(
57 ; CHECK-NEXT: [[LOADED_PTR:%.*]] = load ptr, ptr addrspace(4) null, align 8
58 ; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast ptr [[LOADED_PTR]] to ptr addrspace(1)
59 ; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr addrspace(1) [[TMP0]] to ptr
60 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[TMP1]], i64 3
61 ; CHECK-NEXT: call void @uses_ptrs(ptr [[GEP]], ptr [[GEP]], ptr [[GEP]])
62 ; CHECK-NEXT: ret void
65 %loaded.ptr = load ptr, ptr addrspace(4) null, align 8
66 %gep = getelementptr i64, ptr %loaded.ptr, i64 3
67 call void @uses_ptrs(ptr %gep, ptr %gep, ptr %gep)