[llvm-branch-commits] LiveRangeShrink: Early exit when encountering a code motion barrier. (PR #136806)

Peter Collingbourne via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 23 16:08:02 PDT 2025


================
@@ -95,14 +95,24 @@ static MachineInstr *FindDominatedInstruction(MachineInstr &New,
   return Old;
 }
 
+static bool isCodeMotionBarrier(MachineInstr &MI) {
+  return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
+}
+
 /// Builds Instruction to its dominating order number map \p M by traversing
 /// from instruction \p Start.
 static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
                               InstOrderMap &M) {
   M.clear();
   unsigned i = 0;
-  for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
+  bool SawStore = false;
+  for (MachineInstr &I : make_range(Start, Start->getParent()->end())) {
+    if (I.mayStore())
+      SawStore = true;
+    if (!I.isSafeToMove(SawStore) && isCodeMotionBarrier(I))
----------------
pcc wrote:

Correct, updated this code to only call one.

While reading the code I observed that the code to update SawStore in this pass is redundant with what isSafeToMove is doing, so I removed it.

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


More information about the llvm-branch-commits mailing list