[llvm] [BasicAA] Extend two-variable MinAbsVarIndex heuristic to different scales (PR #218639)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 08:05:12 PDT 2026


================
@@ -2018,14 +2036,48 @@ std::optional<APInt> BasicAAResult::computeMinAbsVarOffset(
     // inequality of values across loop iterations.
     const VariableGEPIndex &Var0 = VarIndices[0];
     const VariableGEPIndex &Var1 = VarIndices[1];
-    if (Var0.hasNegatedScaleOf(Var1) && Var0.Val.TruncBits == 0 &&
-        Var0.Val.hasSameCastsAs(Var1.Val) && !AAQI.MayBeCrossIteration &&
-        MultiplyByScaleNoWrap(Var0) && MultiplyByScaleNoWrap(Var1) &&
+    bool Preconditions =
+        Var0.Val.TruncBits == 0 && Var0.Val.hasSameCastsAs(Var1.Val) &&
+        !AAQI.MayBeCrossIteration && MultiplyByScaleNoWrap(Var0) &&
+        MultiplyByScaleNoWrap(Var1);
+    if (Var0.hasNegatedScaleOf(Var1) && Preconditions &&
----------------
nikic wrote:

I think we probably want to return early if hasNegatedScaleOf() and the remaining conditions don't match. In that case folding through to the new logic is not going to be useful and will only waste compile-time, right?

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


More information about the llvm-commits mailing list