[flang-commits] [flang] [flang] Added LoopInvariantCodeMotion pass for [HL]FIR. (PR #173438)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Dec 30 10:06:01 PST 2025


================
@@ -206,6 +206,10 @@ void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
   pm.addPass(fir::createSimplifyRegionLite());
   pm.addPass(mlir::createCSEPass());
 
+  // Run LICM after CSE, which may reduce the number of operations to hoist.
+  if (pc.OptLevel.isOptimizingForSpeed())
+    pm.addPass(fir::createLoopInvariantCodeMotion());
----------------
vzakhari wrote:

I still need to measure performance, but my expectation is that this patch won't change anything.  You have a good point about the compilation time, and I will measure it.

There is one example related to private copies of descriptors in OpenACC, which LICM can help to address (though, I guess this is not the only way to solve it). In general, I would like to be able to optimize code at MLIR level, which otherwise would require more detailed alias-info representation in LLVM IR. In addition, such early MLIR optimizations may help with enabling more MLIR optimizations (like the ones related to Affine transformations).

I agree with you that it is probably too early to enable this by default, and I will move it under an option.

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


More information about the flang-commits mailing list