This is an archive of the discontinued LLVM Phabricator instance.

Make ScalarEvolution less aggressive with respect to no-wrap flags.
ClosedPublic

Authored by sanjoy on Jan 21 2015, 12:25 AM.

Details

Summary

ScalarEvolution currently lowers a subtraction recurrence to an add recurrence with the same no-wrap flags as the subtraction. This is incorrect because sub nsw X, Y is not the same as add nsw X, -Y and sub nuw X, Y is not the same as add nuw X, -Y. This patch fixes the issue, and adds a test case demonstrating the bug.

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 18485.Jan 21 2015, 12:25 AM
sanjoy retitled this revision from to Make ScalarEvolution less aggressive with respect to no-wrap flags..
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: atrick, majnemer.
sanjoy added a subscriber: Unknown Object (MLST).
majnemer accepted this revision.Jan 21 2015, 1:41 AM
majnemer edited edge metadata.

LGTM

lib/Analysis/ScalarEvolution.cpp
3149–3160

Flags doesn't seem very useful now, perhaps it should be removed?

This revision is now accepted and ready to land.Jan 21 2015, 1:41 AM
atrick accepted this revision.Jan 21 2015, 9:00 AM
atrick edited edge metadata.

LGTM with one suggestion for comment.
Thanks for the test cases.

lib/Analysis/ScalarEvolution.cpp
3464–3469

Add a short comment that subtract does not preserve nsw/nuw Flags.

Replies inline.

lib/Analysis/ScalarEvolution.cpp
3149–3160

Yup, I'll do that in a follow-up refactoring change.

3464–3469

Will do.

This revision was automatically updated to reflect the committed changes.