1 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces -o - %s | FileCheck %s
4 ; CHECK: addrspacecast ptr {{%.*}} to ptr addrspace(3)
5 ; CHECK: getelementptr inbounds float, ptr addrspace(3)
6 ; CHECK: load float, ptr addrspace(3)
7 define float @f0(ptr %p) {
9 %0 = call i1 @llvm.amdgcn.is.shared(ptr %p)
10 tail call void @llvm.assume(i1 %0)
11 %1 = tail call i32 @llvm.amdgcn.workitem.id.x()
12 %idxprom = zext i32 %1 to i64
13 %arrayidx = getelementptr inbounds float, ptr %p, i64 %idxprom
14 %2 = load float, ptr %arrayidx, align 4
19 ; CHECK: addrspacecast ptr {{%.*}} to ptr addrspace(5)
20 ; CHECK: getelementptr inbounds float, ptr addrspace(5)
21 ; CHECK: load float, ptr addrspace(5)
22 define float @f1(ptr %p) {
24 %0 = call i1 @llvm.amdgcn.is.private(ptr %p)
25 tail call void @llvm.assume(i1 %0)
26 %1 = tail call i32 @llvm.amdgcn.workitem.id.x()
27 %idxprom = zext i32 %1 to i64
28 %arrayidx = getelementptr inbounds float, ptr %p, i64 %idxprom
29 %2 = load float, ptr %arrayidx, align 4
34 ; CHECK: addrspacecast ptr {{%.*}} to ptr addrspace(1)
35 ; CHECK: getelementptr inbounds float, ptr addrspace(1)
36 ; CHECK: load float, ptr addrspace(1)
37 define float @f2(ptr %p) {
39 %0 = call i1 @llvm.amdgcn.is.private(ptr %p)
41 %2 = call i1 @llvm.amdgcn.is.shared(ptr %p)
44 tail call void @llvm.assume(i1 %4)
45 %5 = tail call i32 @llvm.amdgcn.workitem.id.x()
46 %idxprom = zext i32 %5 to i64
47 %arrayidx = getelementptr inbounds float, ptr %p, i64 %idxprom
48 %6 = load float, ptr %arrayidx, align 4
54 ; CHECK: addrspacecast ptr {{%.*}} to ptr addrspace(3)
55 ; CHECK: getelementptr inbounds float, ptr addrspace(3)
56 ; CHECK: load float, ptr addrspace(3)
58 ; CHECK: getelementptr inbounds float, ptr
59 ; CHECK: load float, ptr
60 define float @g0(i32 %c, ptr %p) {
62 %tobool.not = icmp eq i32 %c, 0
63 br i1 %tobool.not, label %if.end, label %if.then
66 %0 = call i1 @llvm.amdgcn.is.shared(ptr %p)
67 tail call void @llvm.assume(i1 %0)
68 %1 = tail call i32 @llvm.amdgcn.workitem.id.x()
69 %idxprom = zext i32 %1 to i64
70 %arrayidx = getelementptr inbounds float, ptr %p, i64 %idxprom
71 %2 = load float, ptr %arrayidx, align 4
72 %add = fadd float %2, 0.
76 %s = phi float [ %add, %if.then ], [ 0., %entry ]
77 %3 = tail call i32 @llvm.amdgcn.workitem.id.y()
78 %idxprom2 = zext i32 %3 to i64
79 %arrayidx2 = getelementptr inbounds float, ptr %p, i64 %idxprom2
80 %4 = load float, ptr %arrayidx2, align 4
81 %add2 = fadd float %s, %4
85 declare void @llvm.assume(i1)
86 declare i1 @llvm.amdgcn.is.shared(ptr nocapture)
87 declare i1 @llvm.amdgcn.is.private(ptr nocapture)
88 declare i32 @llvm.amdgcn.workitem.id.x()
89 declare i32 @llvm.amdgcn.workitem.id.y()