This is an archive of the discontinued LLVM Phabricator instance.

Add handling for range metadata in ValueTracking isKnownNonZero
ClosedPublic

Authored by reames on Oct 23 2014, 4:15 PM.

Details

Summary

Teach isKnownNonZero to look at range metadata

If we load from a location with range metadata, we can use information about the ranges of the loaded value for optimization purposes. This helps to remove redundant checks and canonicalize checks for other optimization passes.

Currently, these tests are against InstCombine. In theory, all of these should be InstSimplify since we're not inserting any new instructions. Moving the code may follow in a separate change.

Diff Detail

Event Timeline

reames updated this revision to Diff 15359.Oct 23 2014, 4:15 PM
reames retitled this revision from to Add handling for range metadata in ValueTracking isKnownNonZero.
reames updated this object.
reames edited the test plan for this revision. (Show Details)
reames added a reviewer: hfinkel.
reames added a subscriber: Unknown Object (MLST).
hfinkel added inline comments.Oct 23 2014, 10:45 PM
lib/Analysis/ValueTracking.cpp
1551

space after if; no spaces after ( and before ).

1552

Don't return here... there are other checks below that still might provide information.

reames updated this revision to Diff 15423.Oct 24 2014, 10:58 AM

Addressing Hal's review comments.

Thanks (in particular) for catching the early return issue.

hfinkel accepted this revision.Oct 29 2014, 9:58 AM
hfinkel edited edge metadata.

Accounting for comments below, LGTM.

lib/Analysis/ValueTracking.cpp
1542

Let's make this a little future-proof. At some point we'll likely support this range metadata on vectors, etc. So let's make this an if and a dyn_cast.

1544

We don't need to construct the ZeroConstant here, just using something like this should work:

const APInt ZeroValue(Ty->getBitWidth(), 0);
This revision is now accepted and ready to land.Oct 29 2014, 9:58 AM
reames closed this revision.Oct 30 2014, 1:36 PM
reames updated this revision to Diff 15578.

Closed by commit rL220925 (authored by @reames).