[llvm] [AMDGPU] Correctly insert s_nops for implicit read of SDWA (PR #100276)
Jeffrey Byrnes via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 2 08:34:57 PDT 2024
================
@@ -875,13 +875,34 @@ GCNHazardRecognizer::checkVALUHazardsHelper(const MachineOperand &Def,
return DataIdx >= 0 &&
TRI->regsOverlap(MI.getOperand(DataIdx).getReg(), Reg);
};
+
int WaitStatesNeededForDef =
VALUWaitStates - getWaitStatesSince(IsHazardFn, VALUWaitStates);
WaitStatesNeeded = std::max(WaitStatesNeeded, WaitStatesNeededForDef);
return WaitStatesNeeded;
}
+static const MachineOperand *
+getDstSelForwardingOperand(const MachineInstr &MI, const GCNSubtarget &ST) {
+ if (!SIInstrInfo::isVALU(MI))
+ return nullptr;
+
+ const SIInstrInfo *TII = ST.getInstrInfo();
+ if (SIInstrInfo::isSDWA(MI)) {
+ if (auto *DstSel = TII->getNamedOperand(MI, AMDGPU::OpName::dst_sel))
+ if (DstSel->getImm() == AMDGPU::SDWA::DWORD)
+ return nullptr;
+ } else {
+ if (!AMDGPU::hasNamedOperand(MI.getOpcode(), AMDGPU::OpName::op_sel) ||
+ !(TII->getNamedOperand(MI, AMDGPU::OpName::src0_modifiers)->getImm() &
+ SISrcMods::DST_OP_SEL))
+ return nullptr;
+ }
----------------
jrbyrnes wrote:
Yes, `V_ADD_U16` doesn't preserve dest in VOP2, but can in VOP3. I thought the problem was limited to VOP3 due to op_sel
Thanks for pointing out that list..
I took another look at the ISA, and you're right.. there are VOP2 which also have dest preserve semantics -- e.g. V_MAC_F16
So I guess we should safely s_nop any VALU WAW, and "optimize" once we can trust zeroesHigh16BitsOfDest
https://github.com/llvm/llvm-project/pull/100276
More information about the llvm-commits
mailing list