This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] add NW flag for AddExpr (start + stride)
ClosedPublic

Authored by shchenz on Jul 17 2019, 6:39 AM.

Details

Summary
%i = phi i4 [ %start, %entry ], [ %i.next, %loop ]
%i.next = add nsw i4 %i, %stride

If we know that SCEV {(%start + %stride), +, %stride} poison value wil cause UB, it is safe to add SCEV::FlagNSW for it. And it should also be safe for (%start + %stride) to add SCEV::FlagNSW.

Diff Detail

Repository
rL LLVM

Event Timeline

shchenz created this revision.Jul 17 2019, 6:39 AM
reames accepted this revision.Jul 17 2019, 9:11 AM

LGTM, but please update your submit comment to emphasize that the only reason this is correct is that we've proven that the inc can't be poison without triggering UB in the original program. (i.e. it's not the fact the add is nsw which lets us do this, it's the fact that the add is nsw and can be proven to trigger UB if actually poison)

This revision is now accepted and ready to land.Jul 17 2019, 9:11 AM
shchenz edited the summary of this revision. (Show Details)Jul 18 2019, 2:07 AM
This revision was automatically updated to reflect the committed changes.