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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 07:02:39 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 had the same thought but haven't taken any measurements yet, I will try and get some.

I tried the other approach of changing RISCVVLOptimizer to not reduce the VL on instructions that are loop invariant, but it results in a lot of regressions where we hoist and then fail to coalesce vsetvlis, e.g:

```diff
 ; CHECK-LABEL: vector_init_vsetvli_fv:
 ; CHECK:       # %bb.0: # %entry
 ; CHECK-NEXT:    li a2, 0
-; CHECK-NEXT:    vsetivli a3, 4, e64, m1, ta, ma
+; CHECK-NEXT:    vsetvli a3, zero, e64, m1, ta, ma
 ; CHECK-NEXT:    vmv.v.i v8, 0
+; CHECK-NEXT:    vsetivli a3, 4, e64, m1, ta, ma
 ; CHECK-NEXT:    slli a4, a3, 3
```


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


More information about the llvm-commits mailing list