Skip to content

Commit 6914c06

Browse files
authored
[WaveTransform] Fine-tune shouldCoalesce target hook (#705)
With upstream PR 168988 the AMDGPU-specific implementation of shouldCoalesce has been removed and the default implementation is now used during register coalescing. In the wave-transform pipeline, the coalescer is invoked twice. First invocation is immediately after the two-address instruction pass and the next one after the wave-transform pass. This ensure that the scalar registers and the WWM values are not coalesced before the wave transform. It gives us an upper hand as the wave-transform pass may insert additional SGPR copies which can then be optimized by the second coalescer invocation. To achieve this a register class based filtering mechanism is already available in the feature branch. However, at this stage, the WWM virtual registers are not introduced before SGPR spill lowering, so the filtering for them can be safely removed. We should reinstate this check when WWM values are introduced earlier in the pipeline.
1 parent 91f1bb6 commit 6914c06

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,26 +3968,14 @@ bool SIRegisterInfo::shouldCoalesce(MachineInstr *MI,
39683968
unsigned DstSubReg,
39693969
const TargetRegisterClass *NewRC,
39703970
LiveIntervals &LIS) const {
3971-
auto MFI = MI->getMF()->getInfo<SIMachineFunctionInfo>();
3972-
if (!MFI->isWaveCFG()) {
3973-
// Do not coalesce any SGPR copy before WaveTransform.
3974-
// Note that we also need a separate pass to deal with phi-node for
3975-
// vector-i1 values stored in SGPRs.
3976-
if (isSGPRClass(SrcRC) || isSGPRClass(DstRC) || isSGPRClass(NewRC))
3977-
return false;
3978-
// Check all register operands of the CopyMI. If any vgpr is marked
3979-
// with WWM flag, we do not want to coalesce them before WaveTransform.
3980-
// This assumes that we have set the WWM flag properly before coalescer.
3981-
const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
3982-
for (auto opnd : MI->operands()) {
3983-
if (!opnd.isReg())
3984-
continue;
3985-
auto Reg = opnd.getReg();
3986-
const TargetRegisterClass *RC = MRI.getRegClass(Reg);
3987-
if (isVectorSuperClass(RC) &&
3988-
MFI->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG))
3989-
return false;
3990-
}
3971+
const SIMachineFunctionInfo *MFI =
3972+
MI->getMF()->getInfo<SIMachineFunctionInfo>();
3973+
// Do not coalesce any SGPR copy before WaveTransform.
3974+
// Note that we also need a separate pass to deal with phi-node for
3975+
// vector-i1 values stored in SGPRs.
3976+
if (!MFI->isWaveCFG() &&
3977+
(isSGPRClass(SrcRC) || isSGPRClass(DstRC) || isSGPRClass(NewRC))) {
3978+
return false;
39913979
}
39923980

39933981
return TargetRegisterInfo::shouldCoalesce(MI, SrcRC, SubReg, DstRC, DstSubReg,

0 commit comments

Comments
 (0)