[llvm] [RISCV] Move performCombineVMergeAndVOps to RISCVVectorPeephole (PR #144076)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 13 09:24:18 PDT 2025


================
@@ -380,13 +381,23 @@ bool RISCVVectorPeephole::convertAllOnesVMergeToVMv(MachineInstr &MI) const {
   return true;
 }
 
-bool RISCVVectorPeephole::isKnownSameDefs(const MachineOperand &A,
-                                          const MachineOperand &B) const {
-  if (A.getReg().isPhysical() || B.getReg().isPhysical())
+bool RISCVVectorPeephole::isKnownSameDefs(Register A, Register B) const {
+  if (A.isPhysical() || B.isPhysical())
     return false;
 
-  return TRI->lookThruCopyLike(A.getReg(), MRI) ==
-         TRI->lookThruCopyLike(B.getReg(), MRI);
+  auto LookThruVirtRegCopies = [this](Register Reg) {
+    while (MachineInstr *Def = MRI->getUniqueVRegDef(Reg)) {
+      if (!Def->isFullCopy())
+        break;
+      Register Src = Def->getOperand(1).getReg();
+      if (!Src.isVirtual())
+        break;
+      Reg = Src;
+    }
+    return Reg;
+  };
+
+  return LookThruVirtRegCopies(A) == LookThruVirtRegCopies(B);
----------------
lukel97 wrote:

I forgot to mention, when plugging in isKnownSameDefs I noticed that lookThruCopyLike can actually return a physical register if it's the source of a copy chain, and we can't compare physical registers. So I've reworked it here to only look through virtual register COPYs.

Happy to split this off into a separate PR if preferred 

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


More information about the llvm-commits mailing list