[PATCH] D148322: [SCEV] Infer NSW when subtracting expressions with the same signs
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 01:53:16 PDT 2023
mkazantsev added a comment.
I'd suspect that contextual analysis on SCEV creation might have negative CT impact.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7717
+
+ // Try to prove NSW based on operands signs. Subtracting non-negative
+ // values cannot overflow, as well as subtracting non-positives ones.
----------------
There is certain semblance b/w what you are doing and what `willNotOverflow` is doing. I also have an improvement for it that makes it support sub with context: D148618. I think it's a superset of (w/ this patch) of what you are trying to achieve.
Will calling this function w/ right context help here? If yes, you could do it for both `add` and `sub`.
I have a concern about using of context-aware checkers in SCEV creation. It might be OK since it is only done once, but I'm not sure what's the real impact on CT. Might be expensive, @nikic WDYT?
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7728
+ if (auto *AR = dyn_cast<SCEVAddRecExpr>(RHS))
+ L = AR->getLoop();
+ enum class SCEVExprSign { NonNegative, NonPositive, Unknown };
----------------
If both `LHS` and `RHS` have loops, you can use the one that is lower.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148322/new/
https://reviews.llvm.org/D148322
More information about the llvm-commits
mailing list