[llvm] [RISCV] Ensure false dominates in vmerge peephole (PR #181664)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 16 21:59:18 PST 2026


================
@@ -558,20 +559,34 @@ static bool isSafeToMove(const MachineInstr &From, const MachineInstr &To) {
   return From.isSafeToMove(SawStore);
 }
 
+/// Given \p A and \p B are in the same block, returns the instruction that
+/// comes first.
+static MachineBasicBlock::iterator first(MachineBasicBlock::iterator A,
+                                         MachineBasicBlock::iterator B) {
+  assert(A->getParent() == B->getParent());
+  MachineBasicBlock::iterator I = A->getParent()->begin();
+  for (; &*I != A && &*I != B; ++I)
+    ;
+  return I;
----------------
lukel97 wrote:

I had the same thought too but I think if B isn't reachable from A, i.e. B is before A, then std::distance is undefined since MachineBasicBlock::iterators aren't random access

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


More information about the llvm-commits mailing list