[llvm] [AMDGPU] Adding multiple use analysis to SIPeepholeSDWA (PR #94800)

Brian Favela via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 13:56:24 PDT 2024


================
@@ -327,7 +336,37 @@ uint64_t SDWASrcOperand::getSrcMods(const SIInstrInfo *TII,
   return Mods;
 }
 
-MachineInstr *SDWASrcOperand::potentialToConvert(const SIInstrInfo *TII) {
+MachineInstr *SDWASrcOperand::potentialToConvert(const SIInstrInfo *TII,
+                                                 const GCNSubtarget &ST,
+                                                 SDWAOperandsMap *PotentialMatches) {
+  // If PotentialMatches is not null, then fill out the map for all uses,
+  // if all can be converted
+  if (PotentialMatches != nullptr) {
+    MachineOperand *Reg = getReplacedOperand();
+    if (!Reg->isReg() || !Reg->isDef()) {
+      return nullptr;
+    }
+
+    for (MachineOperand &UseMO : getMRI()->use_nodbg_operands(Reg->getReg())) {
+      // If there exist use of subreg of Reg then return nullptr
+      if (!isSameReg(UseMO, *Reg))
+        return nullptr;
+
+      // Check that all instructions the use Reg can be converted
+      if (!isConvertibleToSDWA(*(UseMO.getParent()), ST, TII)) {
+        return nullptr;
+      }
+    }
+    // Now that it's guaranteed all uses are legal, iterate over the uses again
+    // to add them for later conversion.
+    for (MachineOperand &UseMO : getMRI()->use_nodbg_operands(Reg->getReg())) {
----------------
bfavela wrote:

The "convertToSDWA" iterates on every operand that can be converted. If you have multiple uses in an instruction that are the same operand, it won't catch them. I added a test for this as well.

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


More information about the llvm-commits mailing list