[PATCH] D94389: [InlineSpiller]Re-tie operands if folding failed

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 20:43:51 PST 2021


skatkov updated this revision to Diff 315987.
skatkov retitled this revision from "[InlineSpiller] Add an assert for untied registers" to "[InlineSpiller]Re-tie operands if folding failed".
skatkov edited the summary of this revision.
skatkov added a comment.

Ok, I modified the patch to re-tie operands in case of folding failure.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94389/new/

https://reviews.llvm.org/D94389

Files:
  llvm/lib/CodeGen/InlineSpiller.cpp


Index: llvm/lib/CodeGen/InlineSpiller.cpp
===================================================================
--- llvm/lib/CodeGen/InlineSpiller.cpp
+++ llvm/lib/CodeGen/InlineSpiller.cpp
@@ -838,16 +838,13 @@
       continue;
     }
 
-    if (UntieRegs && MO.isTied())
-      MI->untieRegOperand(Idx);
-
     if (!SpillSubRegs && MO.getSubReg())
       return false;
     // We cannot fold a load instruction into a def.
     if (LoadMI && MO.isDef())
       return false;
     // Tied use operands should not be passed to foldMemoryOperand.
-    if (!MI->isRegTiedToDefOperand(Idx))
+    if (UntieRegs || !MI->isRegTiedToDefOperand(Idx))
       FoldOps.push_back(Idx);
   }
 
@@ -858,11 +855,31 @@
 
   MachineInstrSpan MIS(MI, MI->getParent());
 
+  SmallVector<std::pair<unsigned, unsigned> > TiedOps;
+  if (UntieRegs)
+    for (unsigned Idx : FoldOps) {
+      MachineOperand &MO = MI->getOperand(Idx);
+      if (!MO.isTied())
+        continue;
+      unsigned Tied = MI->findTiedOperandIdx(Idx);
+      if (MO.isUse())
+        TiedOps.emplace_back(Tied, Idx);
+      else {
+        assert(MO.isDef() && "Tied to not use and def?");
+        TiedOps.emplace_back(Idx, Tied);
+      }
+      MI->untieRegOperand(Idx);
+    }
+
   MachineInstr *FoldMI =
       LoadMI ? TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
              : TII.foldMemoryOperand(*MI, FoldOps, StackSlot, &LIS, &VRM);
-  if (!FoldMI)
+  if (!FoldMI) {
+    // Re-tie operands.
+    for (auto Tied : TiedOps)
+      MI->tieOperands(Tied.first, Tied.second);
     return false;
+  }
 
   // Remove LIS for any dead defs in the original MI not in FoldMI.
   for (MIBundleOperands MO(*MI); MO.isValid(); ++MO) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94389.315987.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210112/7250aa67/attachment.bin>


More information about the llvm-commits mailing list