This is an archive of the discontinued LLVM Phabricator instance.

Teach ScalarEvolution to use !range metadata.
ClosedPublic

Authored by sanjoy on Oct 6 2014, 7:04 PM.

Details

Reviewers
atrick
hfinkel
Summary

This patch teaches ScalarEvolution to pick and use !range metadata. It also makes it more aggressive in querying range information by adding a call to isKnownPredicateWithRanges to isLoopBackedgeGuardedByCond and isLoopEntryGuardedByCond.

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 14485.Oct 6 2014, 7:04 PM
sanjoy retitled this revision from to Teach ScalarEvolution to use !range metadata..
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added a reviewer: atrick.
sanjoy added a subscriber: Unknown Object (MLST).
hfinkel added a subscriber: hfinkel.Oct 9 2014, 4:37 PM

Could you please post this patch with full context (see http://llvm.org/docs/Phabricator.html).

sanjoy updated this revision to Diff 14687.Oct 9 2014, 4:42 PM
sanjoy added a reviewer: hfinkel.

Added full context.

hfinkel edited edge metadata.Oct 9 2014, 5:03 PM

Also, looking at this patch made me think: We don't handle range metadata in LazyValueInfo, do we? And we don't seem to, and I think your GetRangeFromMetadata will be useful for both cases. You might consider making it a general utility function somewhere.

lib/Analysis/ScalarEvolution.cpp
3561

You don't need {} here.

3562

More importantly, don't return here. ValueTracking might be able to refine the range even more, and we want the range information to be additive.

3717

Same comments apply here.

sanjoy updated this revision to Diff 14690.Oct 9 2014, 5:20 PM
sanjoy edited edge metadata.

Address review.

sanjoy added a comment.Oct 9 2014, 5:27 PM
In D5638#9, @hfinkel wrote:

Also, looking at this patch made me think: We don't handle range metadata in LazyValueInfo, do we? And we don't seem to, and I think your GetRangeFromMetadata will be useful for both cases.

The only other use I could find was in ValueTracking.cpp where the range metadata is used to compute "known bits". This information could be indirectly flowing in into LazyValueInfo, but I could not find any direct reference. I haven't look very hard either. :)

You might consider making it a general utility function somewhere.

What is a good place for that?

What is a good place for that?

Given that ConstantRange is in lib/IR, I think you could just add it to ConstantRange itself (as a static function, or a special intersection function, etc.).

atrick accepted this revision.Oct 9 2014, 5:44 PM
atrick edited edge metadata.

The indvars test is great. Can you add more specific unit tests with -scalar-evolution -analyze to cover the cases that you analyze more aggressively now?

Otherwise LGTM. Thanks!

This revision is now accepted and ready to land.Oct 9 2014, 5:44 PM
sanjoy closed this revision.Dec 11 2014, 10:22 PM