Page MenuHomePhabricator

[SCEV] Fix buggy behavior in getAddExpr with truncs

Authored by mkazantsev on Jul 18 2018, 3:53 AM.



SCEV tries to constant-fold arguments of trunc operands in SCEVAddExpr, and when it does
that, it passes wrong flags into the recursion. It is only valid to pass flags that are proved for
narrow type into a computation in wider type if we can prove that trunc instruction doesn't
actually change the value. If it did lose some meaningful bits, we may end up proving wrong
no-wrap flags for sum of arguments of trunc.

In the provided test we end up with nuw where it shouldn't be because of this bug.

The solution is to conservatively pass SCEV::FlagAnyWrap which is always a valid thing to do.

Diff Detail


Event Timeline

mkazantsev created this revision.Jul 18 2018, 3:53 AM
jlebar removed a reviewer: jlebar.Jul 18 2018, 8:04 AM
jlebar added a subscriber: jlebar.
sanjoy accepted this revision.Jul 18 2018, 9:35 AM


This revision is now accepted and ready to land.Jul 18 2018, 9:35 AM
This revision was automatically updated to reflect the committed changes.