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.
Differential D104634
[SCEV] Generalize MatchBinaryAddToConst to support non-add expressions. fhahn on Jun 21 2021, 4:04 AM. Authored by
Details 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.
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). 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. |
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.