[llvm] [LICM] Do not reassociate constant offset GEP (PR #151492)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 09:57:41 PDT 2025


================
@@ -2517,6 +2517,12 @@ static bool hoistGEP(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
   if (!L.isLoopInvariant(SrcPtr) || !all_of(GEP->indices(), LoopInvariant))
     return false;
 
+  // Do not try to hoist a constant GEP out of the loop via reassociation.
+  // Constant GEPs can often be folded into addressing modes, and reassociating
+  // them may inhibit CSE of a common base.
+  if (GEP->hasAllConstantIndices())
----------------
dtcxzyw wrote:

Can we move the check to the front? `isLoopInvariant` and `contains` are a bit more expensive.

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


More information about the llvm-commits mailing list