[llvm] [RISCV] Enhance RISCVMoveMerger for GPRPair Moves on RV32 #180831 (PR #182416)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 17:59:06 PST 2026


================
@@ -128,35 +149,102 @@ RISCVMoveMerge::mergePairedInsns(MachineBasicBlock::iterator I,
   //
   //   mv a0, s2
   //   mv a1, s1    =>  cm.mva01s s2,s1
-  unsigned Opcode;
-  if (MoveFromSToA) {
-    // We are moving one of the copies earlier so its kill flag may become
-    // invalid. Clear the copied kill flag if there are any reads of the
-    // register between the new location and the old location.
+  unsigned Opcode = getMoveFromOpcode(*ST, MoveFromSToA);
+  // We are moving one of the copies earlier so its kill flag may become
+  // invalid. Clear the copied kill flag if there are any reads of the
+  // register between the new location and the old location.
+  if (MoveFromSToA || (!ST->hasStdExtZcmp() && !ST->hasVendorXqccmp()))
     for (auto It = std::next(I); It != Paired && PairedSource.isKill(); ++It)
       if (It->readsRegister(PairedSource.getReg(), TRI))
         PairedSource.setIsKill(false);
 
-    Opcode = getMoveFromSToAOpcode(*ST);
+  if (MoveFromSToA) {
     Sreg1 = FirstPair.Source;
     Sreg2 = &PairedSource;
     if (FirstPair.Destination->getReg() != RISCV::X10)
       std::swap(Sreg1, Sreg2);
   } else {
-    Opcode = getMoveFromAToSOpcode(*ST);
     Sreg1 = FirstPair.Destination;
     Sreg2 = PairedRegs.Destination;
     if (FirstPair.Source->getReg() != RISCV::X10)
       std::swap(Sreg1, Sreg2);
   }
 
-  BuildMI(*I->getParent(), I, DL, TII->get(Opcode)).add(*Sreg1).add(*Sreg2);
+  if (!ST->hasStdExtZcmp() && !ST->hasVendorXqccmp()) {
+    Register SrcReg1, SrcReg2, DestReg;
+
+    SrcReg1 =
+        TRI->getMatchingSuperReg(FirstPair.Source->getReg(),
+                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);
+    SrcReg2 =
+        ST->hasStdExtZdinx()
+            ? SrcReg1
+            : Register(TRI->getMatchingSuperReg(RISCV::X0, RISCV::sub_gpr_even,
+                                                &RISCV::GPRPairRegClass));
----------------
lenary wrote:

This can just be `Register(RISCV::X0_Pair)` iirc.

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


More information about the llvm-commits mailing list