This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine][KnownBits] Use KnownBits better to detect nsw adds
ClosedPublic

Authored by yabash on Apr 30 2017, 10:07 AM.

Details

Summary

Change checkRippleForAdd from a heuristic to a full check -
if it is provable that the add does not overflow return true, otherwise false.

Diff Detail

Repository
rL LLVM

Event Timeline

yabash created this revision.Apr 30 2017, 10:07 AM
craig.topper added inline comments.Apr 30 2017, 8:53 PM
lib/Transforms/InstCombine/InstCombineAddSub.cpp
866 ↗(On Diff #97237)

Space between 'if' and 'parenthese'

871 ↗(On Diff #97237)

Wrap both MaxLHS and MaxRHS in std::move so we can reuse one of their allocations to hold the addition result when dealing with larger than 64-bit numbers.

880 ↗(On Diff #97237)

Space between 'if' and 'parenthese'

885 ↗(On Diff #97237)

Wrap both MinLHS and MinRHS in std::move so we can reuse one of their allocations to hold the addition result when dealing with larger than 64-bit numbers.

craig.topper added inline comments.Apr 30 2017, 8:56 PM
lib/Transforms/InstCombine/InstCombineAddSub.cpp
853 ↗(On Diff #97237)

The these parameter names are swapped relative to the caller. Prefer LHS followed by RHS.

866 ↗(On Diff #97237)

Also do LHS check first then RHS. Basically as much as possible do everything for LHS before RHS.

871 ↗(On Diff #97237)

Or better yet, maybe just use MaxLHS += MaxRHS.

yabash updated this revision to Diff 97265.May 1 2017, 12:35 AM

Thanks for the comments, fixed.

I opted for std::move and not += because both don't allocate,
and std::move looks more readable (dedicated name 'Result').
Let me know what you think.

yabash marked 6 inline comments as done.May 1 2017, 12:36 AM
This revision is now accepted and ready to land.May 2 2017, 8:19 AM

Thanks!
Can you help with committing?

This revision was automatically updated to reflect the committed changes.