Skip to content

[AMDGPU] SIWholeQuadMode: avoid execz effects in exact regions #101157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,8 +1364,26 @@ void SIWholeQuadMode::processBlock(MachineBasicBlock &MBB, bool IsEntry) {
llvm_unreachable("Unknown state");
break;
}
char StartState = State & StateStrict ? NonStrictState : State;
bool WQMToExact =
StartState == StateWQM && (Needs & StateExact) && !(Needs & StateWQM);
bool ExactToWQM = StartState == StateExact && (Needs & StateWQM) &&
!(Needs & StateExact);
bool PreferLast = Needs == StateWQM;
// Exact regions in divergent control flow may run at EXEC=0, so try to
// exclude instructions with unexpected effects from them.
// FIXME: ideally we would branch over these when EXEC=0,
// but this requires updating implicit values, live intervals and CFG.
if ((WQMToExact && (OutNeeds & StateWQM)) || ExactToWQM) {
for (MachineBasicBlock::iterator I = First; I != II; ++I) {
if (TII->hasUnwantedEffectsWhenEXECEmpty(*I)) {
PreferLast = WQMToExact;
break;
}
}
}
MachineBasicBlock::iterator Before =
prepareInsertion(MBB, First, II, Needs == StateWQM, SaveSCC);
prepareInsertion(MBB, First, II, PreferLast, SaveSCC);

if (State & StateStrict) {
assert(State == StateStrictWWM || State == StateStrictWQM);
Expand All @@ -1385,18 +1403,16 @@ void SIWholeQuadMode::processBlock(MachineBasicBlock &MBB, bool IsEntry) {

toStrictMode(MBB, Before, SavedNonStrictReg, Needs);
State = Needs;

} else {
if (State == StateWQM && (Needs & StateExact) && !(Needs & StateWQM)) {
if (WQMToExact) {
if (!WQMFromExec && (OutNeeds & StateWQM)) {
assert(!SavedWQMReg);
SavedWQMReg = MRI->createVirtualRegister(BoolRC);
}

toExact(MBB, Before, SavedWQMReg);
State = StateExact;
} else if (State == StateExact && (Needs & StateWQM) &&
!(Needs & StateExact)) {
} else if (ExactToWQM) {
assert(WQMFromExec == (SavedWQMReg == 0));

toWQM(MBB, Before, SavedWQMReg);
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/CodeGen/AMDGPU/wqm.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3551,13 +3551,13 @@ define amdgpu_ps float @short_exact_regions(<8 x i32> inreg %rsrc, <4 x i32> inr
; GFX9-W64-NEXT: s_and_saveexec_b64 s[14:15], vcc
; GFX9-W64-NEXT: s_cbranch_execz .LBB59_2
; GFX9-W64-NEXT: ; %bb.1: ; %if
; GFX9-W64-NEXT: s_and_saveexec_b64 s[16:17], s[12:13]
; GFX9-W64-NEXT: global_load_dword v0, v[1:2], off
; GFX9-W64-NEXT: s_waitcnt vmcnt(0)
; GFX9-W64-NEXT: v_readfirstlane_b32 s18, v0
; GFX9-W64-NEXT: s_buffer_load_dword s18, s[8:11], s18 offset:0x0
; GFX9-W64-NEXT: v_readfirstlane_b32 s16, v0
; GFX9-W64-NEXT: s_buffer_load_dword s16, s[8:11], s16 offset:0x0
; GFX9-W64-NEXT: s_waitcnt lgkmcnt(0)
; GFX9-W64-NEXT: v_mov_b32_e32 v0, s18
; GFX9-W64-NEXT: v_mov_b32_e32 v0, s16
; GFX9-W64-NEXT: s_and_saveexec_b64 s[16:17], s[12:13]
; GFX9-W64-NEXT: buffer_store_dwordx4 v[3:6], v0, s[0:3], 0 idxen
; GFX9-W64-NEXT: s_mov_b64 exec, s[16:17]
; GFX9-W64-NEXT: .LBB59_2: ; %endif
Expand All @@ -3581,13 +3581,13 @@ define amdgpu_ps float @short_exact_regions(<8 x i32> inreg %rsrc, <4 x i32> inr
; GFX10-W32-NEXT: v_cmpx_gt_u32_e32 16, v0
; GFX10-W32-NEXT: s_cbranch_execz .LBB59_2
; GFX10-W32-NEXT: ; %bb.1: ; %if
; GFX10-W32-NEXT: s_and_saveexec_b32 s14, s12
; GFX10-W32-NEXT: global_load_dword v0, v[1:2], off
; GFX10-W32-NEXT: s_waitcnt vmcnt(0)
; GFX10-W32-NEXT: v_readfirstlane_b32 s15, v0
; GFX10-W32-NEXT: s_buffer_load_dword s15, s[8:11], s15 offset:0x0
; GFX10-W32-NEXT: v_readfirstlane_b32 s14, v0
; GFX10-W32-NEXT: s_buffer_load_dword s14, s[8:11], s14 offset:0x0
; GFX10-W32-NEXT: s_waitcnt lgkmcnt(0)
; GFX10-W32-NEXT: v_mov_b32_e32 v0, s15
; GFX10-W32-NEXT: v_mov_b32_e32 v0, s14
; GFX10-W32-NEXT: s_and_saveexec_b32 s14, s12
; GFX10-W32-NEXT: buffer_store_dwordx4 v[3:6], v0, s[0:3], 0 idxen
; GFX10-W32-NEXT: s_mov_b32 exec_lo, s14
; GFX10-W32-NEXT: .LBB59_2: ; %endif
Expand Down
Loading