This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Infer NSW when subtracting expressions with the same signs
Needs ReviewPublic

Authored by dmakogon on Apr 14 2023, 3:32 AM.

Details

Summary

When creating a SCEV for X - Y infer NSW for the resulting expression if X and Y are either both non-positive or non-negative.
In these cases there can be no signed overflow.

Diff Detail

Event Timeline

dmakogon created this revision.Apr 14 2023, 3:32 AM
dmakogon requested review of this revision.Apr 14 2023, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 3:32 AM

I'd suspect that contextual analysis on SCEV creation might have negative CT impact.

llvm/lib/Analysis/ScalarEvolution.cpp
7717

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?

7728

If both LHS and RHS have loops, you can use the one that is lower.