[llvm] [AMDGPU] Add commute for some VOP3 inst (PR #121326)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 05:36:06 PST 2025


================
@@ -2762,6 +2762,54 @@ static MachineInstr *swapInlineConstOperands(MachineInstr &MI,
   return &MI;
 }
 
+bool SIInstrInfo::isLegalToSwap(const MachineInstr &MI, 
+                                unsigned OpIdx0, const MachineOperand *MO0,
+                                unsigned OpIdx1, const MachineOperand *MO1) const {
+  const MCInstrDesc &InstDesc = MI.getDesc();
+  const MCOperandInfo &OpInfo0 = InstDesc.operands()[OpIdx0];
+  const MCOperandInfo &OpInfo1 = InstDesc.operands()[OpIdx1];
+  const TargetRegisterClass *DefinedRC1 =
+      OpInfo1.RegClass != -1 ? RI.getRegClass(OpInfo1.RegClass) : nullptr;
+  const TargetRegisterClass *DefinedRC0 =
+      OpInfo1.RegClass != -1 ? RI.getRegClass(OpInfo0.RegClass) : nullptr;
+  
+  unsigned Opc = MI.getOpcode();
+  int Src0Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0);
+  if (Src0Idx == -1) {
+    // VOPD V_DUAL_* instructions use different operand names.
+    Src0Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0X);
+  }
+
+  // Swap doesn't breach constantbus or literal limits
----------------
arsenm wrote:

```suggestion
  // Swap doesn't breach constant bus or literal limits
```

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


More information about the llvm-commits mailing list