[llvm] AMDGPU: Minor SDWA pass cleanups (PR #166629)

Frederik Harwath via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 6 01:56:48 PST 2025


================
@@ -1334,20 +1334,21 @@ void SIPeepholeSDWA::legalizeScalarOperands(MachineInstr &MI,
   const MCInstrDesc &Desc = TII->get(MI.getOpcode());
   unsigned ConstantBusCount = 0;
   for (MachineOperand &Op : MI.explicit_uses()) {
-    if (!Op.isImm() && !(Op.isReg() && !TRI->isVGPR(*MRI, Op.getReg())))
-      continue;
-
-    unsigned I = Op.getOperandNo();
+    if (Op.isReg()) {
+      if (TRI->isVGPR(*MRI, Op.getReg()))
+        continue;
 
-    int16_t RegClass = TII->getOpRegClassID(Desc.operands()[I]);
-    if (RegClass == -1 || !TRI->isVSSuperClass(TRI->getRegClass(RegClass)))
+      if (ST.hasSDWAScalar() && ConstantBusCount == 0) {
+        ++ConstantBusCount;
----------------
frederik-h wrote:

The (preexisting) `ConstantBusCount` variable name and use is a bit odd since the variable's value is always 0 or 1.
Perhaps you want to change it along those lines while you are at it:
``` 
  bool ConstantBusAvailable = ST.hasSDWAScalar();
  for (MachineOperand &Op : MI.explicit_uses()) {
    if (Op.isReg()) {
      if (TRI->isVGPR(*MRI, Op.getReg()))
        continue;

      if (ConstantBusAvailable) {
        ConstantBusAvailable = false;
        continue;
      }
```

We are also missing a test that checks that the constant bus is not used more than once, i.e. the `ConstantBusAvailable = false` assignment can be removed without causing any test failures.

https://github.com/llvm/llvm-project/pull/166629


More information about the llvm-commits mailing list