[llvm] AMDGPU: VALU data fast-forwarding needs no s_delay (PR #205481)
Reem Elkhouly via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 18:56:32 PDT 2026
================
@@ -392,19 +552,42 @@ class AMDGPUInsertDelayAlu {
State = DelayState();
} else if (Type != OTHER) {
DelayInfo Delay;
+ Register VccReg = AMDGPU::LaneMaskConstants::get(*ST).VccReg;
+ Register ExecReg = AMDGPU::LaneMaskConstants::get(*ST).ExecReg;
+
// C-reuse: back-to-back WMMAs into the same C register forward the
// accumulator in place, so the tied srcC read has no dependency. WMMA
// implies GFX11+, so no explicit subtarget check is needed.
bool IsWMMACReuse =
PrevWMMAVDst.isValid() && (SII->isWMMA(MI) || SII->isSWMMAC(MI));
- // TODO: Scan implicit uses too?
- for (const auto &Op : MI.explicit_uses()) {
+
+ for (const auto &Op : MI.all_uses()) {
if (Op.isReg()) {
// One of the operands of the writelane is also the output operand.
// This creates the insertion of redundant delays. Hence, we have to
// ignore this operand.
if (MI.getOpcode() == AMDGPU::V_WRITELANE_B32 && Op.isTied())
continue;
+
+ Register Reg = Op.getReg();
+ unsigned OperandNo = MI.getOperandNo(&Op);
+ // Skip operands that are not part of the instruction definition
+ if (OperandNo >= MI.getDesc().getNumOperands() &&
+ !MI.getDesc().hasImplicitUseOfPhysReg(
+ Reg == VccReg ? AMDGPU::VCC : Reg))
----------------
amd-relkhoul wrote:
This is the wave32 case where the special handling is required:
```
$vgpr0, $vcc_lo = V_ADD_CO_U32_e64 $vgpr0, $vgpr1, 0, implicit $exec
$vgpr2 = V_DIV_FMAS_F32_e64 0, $vgpr2, 0, $vgpr3, 0, $vgpr4, 0, 0, implicit $mode, implicit $vcc, implicit $exec
```
A delay is required before `v_div_fmas_f32_e64` because it implicitly uses `$vcc` which slips the `Reg == VccReg` check.
I need to mirror that in the `all_defs` side loop (from review point 1) as well to cover the following case:
```
$vgpr0 = V_ADD_CO_U32_e32 $vgpr1, $vgpr2, implicit-def $vcc, implicit $exec
$vgpr5 = V_DIV_FMAS_F32_e64 0, $vgpr6, 0, $vgpr3, 0, $vgpr4, 0, 0, implicit $mode, implicit $vcc, implicit $exec
```
where `$vcc` is implicitly defined and used.
https://github.com/llvm/llvm-project/pull/205481
More information about the llvm-commits
mailing list