Skip to content

Commit facead6

Browse files
[AMDGPU] PromoteAlloca - bail always if load/store is volatile (#73228)
This change is addressing case where alloca size is the same as load/store size.
1 parent a05c23f commit facead6

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,12 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
681681
return RejectUser(Inst, "unsupported load/store as aggregate");
682682
assert(!AccessTy->isAggregateType() || AccessTy->isArrayTy());
683683

684+
// Check that this is a simple access of a vector element.
685+
bool IsSimple = isa<LoadInst>(Inst) ? cast<LoadInst>(Inst)->isSimple()
686+
: cast<StoreInst>(Inst)->isSimple();
687+
if (!IsSimple)
688+
return RejectUser(Inst, "not a simple load or store");
689+
684690
Ptr = Ptr->stripPointerCasts();
685691

686692
// Alloca already accessed as vector.
@@ -690,11 +696,6 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
690696
continue;
691697
}
692698

693-
// Check that this is a simple access of a vector element.
694-
bool IsSimple = isa<LoadInst>(Inst) ? cast<LoadInst>(Inst)->isSimple()
695-
: cast<StoreInst>(Inst)->isSimple();
696-
if (!IsSimple)
697-
return RejectUser(Inst, "not a simple load or store");
698699
if (!isSupportedAccessType(VectorTy, AccessTy, *DL))
699700
return RejectUser(Inst, "not a supported access type");
700701

llvm/test/CodeGen/AMDGPU/fix-frame-reg-in-custom-csr-spills.ll

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,37 @@ define void @test_stack_realign(<8 x i32> %val, i32 %idx) #0 {
1313
; GCN: ; %bb.0:
1414
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1515
; GCN-NEXT: s_mov_b32 s16, s33
16-
; GCN-NEXT: s_mov_b32 s33, s32
16+
; GCN-NEXT: s_add_i32 s33, s32, 0xfc0
17+
; GCN-NEXT: s_and_b32 s33, s33, 0xfffff000
1718
; GCN-NEXT: s_or_saveexec_b64 s[18:19], -1
18-
; GCN-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
19+
; GCN-NEXT: buffer_store_dword v42, off, s[0:3], s33 offset:96 ; 4-byte Folded Spill
1920
; GCN-NEXT: s_mov_b64 exec, s[18:19]
20-
; GCN-NEXT: s_addk_i32 s32, 0x400
21+
; GCN-NEXT: s_addk_i32 s32, 0x3000
2122
; GCN-NEXT: v_writelane_b32 v42, s16, 2
2223
; GCN-NEXT: s_getpc_b64 s[16:17]
2324
; GCN-NEXT: s_add_u32 s16, s16, extern_func@gotpcrel32@lo+4
2425
; GCN-NEXT: s_addc_u32 s17, s17, extern_func@gotpcrel32@hi+12
2526
; GCN-NEXT: s_load_dwordx2 s[16:17], s[16:17], 0x0
26-
; GCN-NEXT: v_writelane_b32 v42, s30, 0
27-
; GCN-NEXT: v_mov_b32_e32 v0, v8
2827
; GCN-NEXT: buffer_store_dword v40, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
2928
; GCN-NEXT: buffer_store_dword v41, off, s[0:3], s33 ; 4-byte Folded Spill
29+
; GCN-NEXT: v_writelane_b32 v42, s30, 0
30+
; GCN-NEXT: buffer_store_dword v7, off, s[0:3], s33 offset:92
31+
; GCN-NEXT: s_waitcnt vmcnt(0)
32+
; GCN-NEXT: buffer_store_dword v6, off, s[0:3], s33 offset:88
33+
; GCN-NEXT: s_waitcnt vmcnt(0)
34+
; GCN-NEXT: buffer_store_dword v5, off, s[0:3], s33 offset:84
35+
; GCN-NEXT: s_waitcnt vmcnt(0)
36+
; GCN-NEXT: buffer_store_dword v4, off, s[0:3], s33 offset:80
37+
; GCN-NEXT: s_waitcnt vmcnt(0)
38+
; GCN-NEXT: buffer_store_dword v3, off, s[0:3], s33 offset:76
39+
; GCN-NEXT: s_waitcnt vmcnt(0)
40+
; GCN-NEXT: buffer_store_dword v2, off, s[0:3], s33 offset:72
41+
; GCN-NEXT: s_waitcnt vmcnt(0)
42+
; GCN-NEXT: buffer_store_dword v1, off, s[0:3], s33 offset:68
43+
; GCN-NEXT: s_waitcnt vmcnt(0)
44+
; GCN-NEXT: buffer_store_dword v0, off, s[0:3], s33 offset:64
45+
; GCN-NEXT: s_waitcnt vmcnt(0)
46+
; GCN-NEXT: v_mov_b32_e32 v0, v8
3047
; GCN-NEXT: v_writelane_b32 v42, s31, 1
3148
; GCN-NEXT: ;;#ASMSTART
3249
; GCN-NEXT: ;;#ASMEND
@@ -40,9 +57,9 @@ define void @test_stack_realign(<8 x i32> %val, i32 %idx) #0 {
4057
; GCN-NEXT: v_readlane_b32 s30, v42, 0
4158
; GCN-NEXT: v_readlane_b32 s4, v42, 2
4259
; GCN-NEXT: s_or_saveexec_b64 s[6:7], -1
43-
; GCN-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
60+
; GCN-NEXT: buffer_load_dword v42, off, s[0:3], s33 offset:96 ; 4-byte Folded Reload
4461
; GCN-NEXT: s_mov_b64 exec, s[6:7]
45-
; GCN-NEXT: s_addk_i32 s32, 0xfc00
62+
; GCN-NEXT: s_addk_i32 s32, 0xd000
4663
; GCN-NEXT: s_mov_b32 s33, s4
4764
; GCN-NEXT: s_waitcnt vmcnt(0)
4865
; GCN-NEXT: s_setpc_b64 s[30:31]

llvm/test/CodeGen/AMDGPU/promote-alloca-volatile.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ entry:
2525
ret void
2626
}
2727

28+
; CHECK-LABEL: @volatile_store_vec(
29+
; CHECK: alloca [4 x i32]
30+
; CHECK: store volatile <4 x i32>
31+
define amdgpu_kernel void @volatile_store_vec(ptr addrspace(1) nocapture %out, ptr addrspace(1) nocapture %in) {
32+
entry:
33+
%stack = alloca [4 x i32], align 4, addrspace(5)
34+
%tmp = load <4 x i32>, ptr addrspace(1) %in, align 16
35+
store volatile <4 x i32> %tmp, ptr addrspace(5) %stack
36+
ret void
37+
}
38+
2839
; Has on OK non-volatile user but also a volatile user
2940
; CHECK-LABEL: @volatile_and_non_volatile_load(
3041
; CHECK: alloca double

0 commit comments

Comments
 (0)