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

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 16 14:44:42 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;
----------------
mshockwave wrote:

could we use `std::distance` here?

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


More information about the llvm-commits mailing list