[llvm] [RISCV] Run EarlyMachineLICM before VLOptimizer to hoist constant splats (PR #210028)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 05:18:51 PDT 2026


================
@@ -623,8 +623,10 @@ void RISCVPassConfig::addPreEmitPass2() {
 void RISCVPassConfig::addMachineSSAOptimization() {
   // It's beneficial to reduce the VL to enable more
   // Machine SSA optimizations.
-  if (TM->getOptLevel() != CodeGenOptLevel::None)
+  if (TM->getOptLevel() != CodeGenOptLevel::None) {
+    addPass(&EarlyMachineLICMID);
----------------
lukel97 wrote:

I measured a 0.2% geomean increase in the number of instructions on CTMark w/ `-march=rva23u64 -O3`. 

I also tried a third approach of just hoisting splats + any LIs that feed into them in RISCVVLOptimizer, but it doesn't catch all the cases that EarlyMachineLICM does. It also requires splitting critical edges whenever the loop has no preheader, which invalidates the CFG analyses, so it still incurs a compile time overhead.

On llvm-test-suite with the extra EarlyMachineLICM pass we go from 2,140 vector splat instructions hoisted to 9,327, which is a 4.4x increase. So I think the 0.2% increase in compile time is probably worth it.

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


More information about the llvm-commits mailing list