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

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 20 11:08:34 PST 2026


================
@@ -128,35 +146,98 @@ 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(RISCV::X0_Pair);
+    DestReg =
+        TRI->getMatchingSuperReg(FirstPair.Destination->getReg(),
+                                 RISCV::sub_gpr_even, &RISCV::GPRPairRegClass);
+
+    BuildMI(*I->getParent(), I, DL, TII->get(Opcode), DestReg)
+        .addReg(SrcReg1, getKillRegState(PairedSource.isKill() &&
+                                         FirstPair.Source->isKill()))
+        .addReg(SrcReg2, getKillRegState(PairedSource.isKill() &&
+                                         FirstPair.Source->isKill()));
+  } else
+    BuildMI(*I->getParent(), I, DL, TII->get(Opcode)).add(*Sreg1).add(*Sreg2);
----------------
lenary wrote:

If the `if` has `{}`, then the `else` should have them too.

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


More information about the llvm-commits mailing list