This is an archive of the discontinued LLVM Phabricator instance.

Fix PR22179
ClosedPublic

Authored by sanjoy on Jan 9 2015, 6:38 PM.

Details

Summary

We were incorrectly inferring nsw for certain SCEVs. We can be more aggressive here (see Richard Smith's comment on http://llvm.org/bugs/show_bug.cgi?id=22179) but this change just focuses on correctness.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 17968.Jan 9 2015, 6:38 PM
sanjoy retitled this revision from to Fix PR22179.
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: atrick, majnemer, rsmith, hfinkel.
sanjoy added a subscriber: Unknown Object (MLST).
majnemer added inline comments.Jan 10 2015, 1:33 AM
lib/Analysis/ScalarEvolution.cpp
1748–1749 ↗(On Diff #17968)

The extra parens don't really add to readability here and the expression is formatted a little funny, consider using clang-format here.

1757–1758 ↗(On Diff #17968)

Why isn't this just equivalent to if (SignOrUnsignWrap == SCEV::FlagNSW) ?

sanjoy updated this revision to Diff 17976.Jan 10 2015, 12:47 PM

Address David's review. Functionally this exactly the same as the previous patch.

majnemer accepted this revision.Jan 10 2015, 2:42 PM
majnemer edited edge metadata.

LGTM with nits.

lib/Analysis/ScalarEvolution.cpp
1758 ↗(On Diff #17976)

std::bind1st and std::mem_fun are deprecated in C++11, we should probably avoid new references to them.

How about:

auto IsKnownNonNegative =
    std::bind(std::mem_fn(&ScalarEvolution::isKnownNonNegative), SE));
1761 ↗(On Diff #17976)

This looks way nicer :)

This revision is now accepted and ready to land.Jan 10 2015, 2:42 PM
This revision was automatically updated to reflect the committed changes.
sanjoy added inline comments.Jan 10 2015, 3:44 PM
lib/Analysis/ScalarEvolution.cpp
1758 ↗(On Diff #17976)

Done.

1761 ↗(On Diff #17976)

I changed this to if (SignOrUnsignWrap == SCEV::FlagNSW && std::all_of(Ops.begin(), Ops.end(), IsKnownNonNegative)) before checking in -- that reduces one level of nesting.