[llvm] [RISCV] Use C.ADD when OR is not compressible due to register restriction (PR #156044)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 07:44:04 PDT 2025


================
@@ -1178,7 +1178,21 @@ bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
   if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
     return false;
 
-  OutMI.setOpcode(MI->getOpcode());
+  unsigned Opcode = MI->getOpcode();
+  // If we have a disjoint OR which isn't compressible as an c.or, we can
+  // convert it to a c.add which doesn't have the gprc register restriction.
+  if (STI->hasStdExtZca() && Opcode == RISCV::OR &&
----------------
preames wrote:

> I'm not super happy with the choice to do this here, honestly. This is mostly a rote function, and I don't think users would expect changes to happen in it.

Understood, happy to rework if we see a better option.  


> Given you're not changing register allocation
Hold on.  Not changing register allocation *for now*.  I'm expecting to return to the register allocation in an upcoming patch; I was just staging work to make the diff more understandable.  Does this change your take at all?


>     * A CompressPat, with `isCompressOnly=true`. I realise we might not be able to control the priority of the two patterns, but I think right now the system uses file order?
Craig addressed this idea.

>     * RISCVMakeCompressible - where we're sort-of expecting optimisations like this.
This only performs size optimizations, and the while this change does improve size, it's not gated on any of the Os/Oz flags.  


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


More information about the llvm-commits mailing list