[llvm] [RISCV][TII] Add and use new hook to optimize/canonicalize instructions after MachineCopyPropagation (PR #137973)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 15:14:00 PDT 2025


================
@@ -510,6 +510,16 @@ class TargetInstrInfo : public MCInstrInfo {
     return false;
   }
 
+  /// If possible, converts the instruction to a more 'optimized'/canonical
+  /// form. Returns true if the instruction was modified.
+  ///
+  /// This function is only called after register allocation. The MI will be
+  /// modified in place. This is called by passes such as
+  /// MachineCopyPropagation, where their mutation of the MI operands may
+  /// expose opportunities to convert the instruction to a simpler form (e.g.
+  /// a load of 0).
+  virtual bool optimizeInstruction(MachineInstr &MI) const { return false; }
----------------
preames wrote:

@asb Can you say a bit about why this needs to be in MCP?  As opposed to just after MCP?  Does doing this in the process of copy propagation expose additional copies?  (Not implausible, but do you actually see this?)

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


More information about the llvm-commits mailing list