[llvm] [RISCV][TII] Add and use new hook to optimize/canonicalize instructions after MachineCopyPropagation (PR #137973)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 09:20:15 PDT 2025
================
@@ -3850,6 +3865,209 @@ MachineInstr *RISCVInstrInfo::commuteInstructionImpl(MachineInstr &MI,
return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2);
}
+bool RISCVInstrInfo::optimizeInstruction(MachineInstr &MI) const {
+ switch (MI.getOpcode()) {
+ default:
+ break;
+ case RISCV::OR:
+ case RISCV::XOR:
+ // Normalize:
+ // [x]or rd, zero, rs => [x]or rd, rs, zero
+ if (MI.getOperand(1).getReg() == RISCV::X0) {
+ MachineOperand MO1 = MI.getOperand(1);
----------------
topperc wrote:
I wonder if using `commuteInstruction` would be more obvious what the code is doing?
https://github.com/llvm/llvm-project/pull/137973
More information about the llvm-commits
mailing list