[llvm] [SCEV] Rewrite more SCEVAddExpr when applying guards. (PR #159942)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 9 05:35:26 PDT 2025
https://github.com/fhahn commented:
> Can you please add some more detail on why this specific pattern is relevant? Based on tests it clearly is, I'm just not super clear on why.
The general case where this can help is if we have a guard for an SCEVAddExpr (e.g x - y > 0). Previously we would only re-write the operands of SCEVAddExprs, and would not apply the guard info.
The logic with `(Const + 1 + A) -> ((Const + 1 + A) - 1)` is needed to avoid regressions when comparing expressions with guards applied (like BTC/exit count expressions or the value at the last iteration vs value at 2n-to-last iteration). With the current changes, we may apply info to only one of the those expressions, which can lead to pessimizations. One example is if we have (n - 2 != n - 1) and we have {n - 1: umin(1, n-1)}, then we would only rewrite (n -1) -> umin(1, n-1) and fail to simplify the compare to true.
https://github.com/llvm/llvm-project/pull/159942
More information about the llvm-commits
mailing list