This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Preserve NSW for AddRec multiplied by -1 if it cannot be signed minimum
ClosedPublic

Authored by dmakogon on Apr 12 2023, 2:12 AM.

Details

Summary

This preserves NSW flag for AddRecs multiplied by -1 if we can prove via constant ranges that the AddRec cannot be signed minimum.
An explanation: Let M be signed minimum. If AddRec's range contains M, then M * (-1) will stay M and (M + 1) * (-1) will be signed maximum, so we get a signed overflow.
In all other cases if an AddRec didn't signed overflow, then AddRec * (-1) wouldn't too.

Diff Detail

Event Timeline

dmakogon created this revision.Apr 12 2023, 2:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 2:12 AM
dmakogon requested review of this revision.Apr 12 2023, 2:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 2:12 AM
mkazantsev accepted this revision.Apr 12 2023, 2:20 AM

LG, please hold this for couple of days in case if someone has objections.

This revision is now accepted and ready to land.Apr 12 2023, 2:20 AM
nikic added a comment.EditedApr 12 2023, 2:47 AM

Can you please rebase this to current main? It doesn't apply cleanly.

llvm/lib/Analysis/ScalarEvolution.cpp
3203

No need to check this if there's no nsw flag in the first place?

dmakogon updated this revision to Diff 512759.Apr 12 2023, 3:58 AM

Can you please rebase this to current main? It doesn't apply cleanly.

Should apply now, forgot to push a test fixup patch before this one.

dmakogon updated this revision to Diff 512763.Apr 12 2023, 4:04 AM

Check AddRec range only if if already has nsw

dmakogon marked an inline comment as done.Apr 12 2023, 4:05 AM