This is an archive of the discontinued LLVM Phabricator instance.

Bugfix: SCEV incorrectly marks certain add recurrences as nsw
ClosedPublic

Authored by sanjoy on Feb 8 2015, 7:27 PM.

Details

Summary

When creating a scev for sext({X,+,Y}), scev checks if the expression
is equivalent to {sext X,+,zext Y}. If it can prove that, it also
tags the original {X,+,Y} as <nsw>, which is not correct AFAICT.

In the test case I run -scalar-evolution twice because the bug
manifests only once SCEV has run through and seen the sext
expressions (and then does a in-place mutation on {X,+,Y}).

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 19565.Feb 8 2015, 7:27 PM
sanjoy retitled this revision from to Bugfix: SCEV incorrectly marks certain add recurrences as nsw.
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: atrick, hfinkel, majnemer, nlewycky.
sanjoy added a subscriber: Unknown Object (MLST).
atrick accepted this revision.Feb 8 2015, 11:02 PM
atrick edited edge metadata.

Great catch and test case!

It's not clear to me why the isKnownNonZero check is necessary. Otherwise LGTM.

This revision is now accepted and ready to land.Feb 8 2015, 11:02 PM

Great catch and test case!

It's not clear to me why the isKnownNonZero check is necessary. Otherwise LGTM.

I thought if X is 0 in {S,+,X} then it would "wrap" on every iteration. But ScalarEvolution.h says no-wrap means abs(step) * max-iteration(loop) <= unsigned-max(bitwidth). So this means we cannot assume that a <nw> add-rec will never reach its starting value, right (since step = 0 satisfies the inequality)?

In practice it seems the two places that actually do something with <nw> work only with a constant non-zero step size, so it is probably okay to remove the check. But I think the comments in the header file should be changed to state that <nw> means that step is either 0 or abs(step) * max-iteration(loop) <= unsigned-max(bitwidth).

This revision was automatically updated to reflect the committed changes.