This patch generalizes MatchBinaryAddToConst to support matching
(A + C1), (A + C2), instead of just matching (A + C1), A.
The existing cases can be handled by treating non-add expressions A as
A + 0.
Paths
| Differential D104634
[SCEV] Generalize MatchBinaryAddToConst to support non-add expressions. ClosedPublic Authored by fhahn on Jun 21 2021, 4:04 AM.
Details Summary This patch generalizes MatchBinaryAddToConst to support matching The existing cases can be handled by treating non-add expressions A as
Diff Detail
Event TimelineComment Actions I think this is wrong.
This revision now requires changes to proceed.Jun 21 2021, 6:01 AM
Comment Actions Ok, thanks for clarification. With this clarification looks fine. Please give me some time to run it through my fuzz corps. Comment Actions For an optional follow up change, I believe we can avoid checking the wrap flags for one operand, if C1 and C2 share the same sign. Consider: If X + C2 does not signed wrap, and C1 s<= C2, then X+C1 also can not wrap if both are positive. As a result, we don't need to check for the wrap flag on LHS as we've proven it. The negative case is the inverse. The mixed sign case does require both checks as the two could overflow off different ends of the range. (Actually, can they? Is there any single value of X which you can add a value to and both wrap above and wrap below? Might be worth further thought.) It's also worth noting that we can *disprove* cases here as well. Consider: This would require a change to the API (probably returning an optional bool), but might be interesting to short circuit later checks. Again, follow up change (if interested). This revision is now accepted and ready to land.Jun 21 2021, 8:33 PM Comment Actions
Thanks, I'll try to look into this as a follow-up.
Thanks for the testing ahead of landing! I'll wait a day or so with landing, in case one of my earlier patches surfaces any issues. Closed by commit rG121ecb05e734: [SCEV] Generalize MatchBinaryAddToConst to support non-add expressions. (authored by fhahn). · Explain WhyJun 24 2021, 4:16 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 353331 llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Transforms/SLPVectorizer/AArch64/memory-runtime-checks.ll
llvm/test/Transforms/SLPVectorizer/X86/memory-runtime-checks.ll
|
Is lack of nsw in (X + C2) intentional? If yes, the counter-example to this is
(X + C1)<nsw> = SINT_MIN + 1 <= (X - 1) = SINT_MAX, but obviously C1 > C2.