[PATCH] D94389: [InlineSpiller] Add an assert for untied registers

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 00:44:37 PST 2021


skatkov created this revision.
skatkov added reviewers: dantrushin, reames.
Herald added subscribers: hiraditya, qcolombet.
skatkov requested review of this revision.
Herald added a project: LLVM.

InlineSpiller::foldMemoryOperand unties registers before an attempt to fold and
does not restore tied-ness in case of failure.

The patch adds an assert to ensure that if we tied registers is broken fold happens.


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
@@ -818,6 +818,11 @@
   // foldMemoryOperand and signal foldPatchpoint that it is allowed to
   // fold them.
   bool UntieRegs = MI->getOpcode() == TargetOpcode::STATEPOINT;
+  bool UntieRegsHappened = false;
+  auto UntieRegsCheck = [UntieRegsHappened]() {
+    assert(!UntieRegsHappened && "Untie Regs broken");
+    return false;
+  };
 
   // Spill subregs if the target allows it.
   // We always want to spill subregs for stackmap/patchpoint pseudos.
@@ -838,14 +843,16 @@
       continue;
     }
 
-    if (UntieRegs && MO.isTied())
+    if (UntieRegs && MO.isTied()) {
+      UntieRegsHappened = true;
       MI->untieRegOperand(Idx);
+    }
 
     if (!SpillSubRegs && MO.getSubReg())
-      return false;
+      return UntieRegsCheck();
     // We cannot fold a load instruction into a def.
     if (LoadMI && MO.isDef())
-      return false;
+      return UntieRegsCheck();
     // Tied use operands should not be passed to foldMemoryOperand.
     if (!MI->isRegTiedToDefOperand(Idx))
       FoldOps.push_back(Idx);
@@ -854,7 +861,7 @@
   // If we only have implicit uses, we won't be able to fold that.
   // Moreover, TargetInstrInfo::foldMemoryOperand will assert if we try!
   if (FoldOps.empty())
-    return false;
+    return UntieRegsCheck();
 
   MachineInstrSpan MIS(MI, MI->getParent());
 
@@ -862,7 +869,7 @@
       LoadMI ? TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
              : TII.foldMemoryOperand(*MI, FoldOps, StackSlot, &LIS, &VRM);
   if (!FoldMI)
-    return false;
+    return UntieRegsCheck();
 
   // 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.315716.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210111/b512fce3/attachment.bin>


More information about the llvm-commits mailing list