This is an archive of the discontinued LLVM Phabricator instance.

[LVI/CVP] Teach LVI about range metadata
ClosedPublic

Authored by reames on Oct 7 2015, 7:36 PM.

Details

Summary

Somewhat shockingly for an analysis pass which is computing constant ranges, LVI did not understand the ranges provided by range metadata.

As part of this change, I included a change to CVP primarily because doing so made it much easier to write small self contained test cases. CVP was previously only handling the non-local operand case, but given that LVI can sometimes figure out information about instructions standalone, I don't see any reason to restrict this.

Note that this patch continues a somewhat bad practice in LVI. In many cases, we know facts about values, and separate context sensitive facts about values. LVI makes no effort to distinguish and will frequently cache the same value fact repeatedly for different contexts. I would like to change this, but that's a large enough change that I want it to go in separately with clear documentation of what's changing. Other examples of this include the non-null handling, and arguments.

As a meta comment: the entire motivation of this change was being able to write smaller (aka reasonable sized) test cases for a future patch teaching LVI about select instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

reames updated this revision to Diff 36820.Oct 7 2015, 7:36 PM
reames retitled this revision from to [LVI/CVP] Teach LVI about range metadata.
reames updated this object.
reames added reviewers: hfinkel, chenli, sanjoy.
reames added a subscriber: llvm-commits.
reames added a subscriber: reames.Oct 7 2015, 10:24 PM

If folks are uncomfortable with the CVP change, I could restructure it
to only try to simplify icmps feeding return instructions. That should
trigger far less often, still be useable for writing tests, and get most
of the actual performance benefit. I'll probably stick with the current
change if no one objects; just throwing out the alternative for discussion.

Philip

ping! I'd really like to get this in so that I can build on it.

chenli added inline comments.Oct 14 2015, 12:43 PM
lib/Analysis/LazyValueInfo.cpp
502 ↗(On Diff #36820)

Do we actually need to check the Opcode? For instructions those cannot have range metadata, getMetadata(LLVMContext::MD_range) will just return a nullptr. If range metadata is extended for other instructions in the future, this switch statement has to be updated as well. I think it might be better to just get rid of the switch.

sanjoy edited edge metadata.Oct 14 2015, 1:07 PM

Minor inline comment inline. I don't really know LVI, so I'll have to read some code before I can review this properly.

lib/Analysis/LazyValueInfo.cpp
507 ↗(On Diff #36820)

I've seen this logic repeated in several places now. I think it's time to refactor out a ConstantRange getRangeFromMetadata() helper function.

However, I think its fine to check this in as is, and then extract out the helper.

reames added inline comments.Oct 14 2015, 2:05 PM
lib/Analysis/LazyValueInfo.cpp
502 ↗(On Diff #36820)

I could go either way on this. The verifier currently enforces these three, but there's no reason the code here needs to. What do others think?

507 ↗(On Diff #36820)

Completely agreed. Will do as a separate follow on change.

sanjoy accepted this revision.Oct 24 2015, 1:22 AM
sanjoy edited edge metadata.

lgtm modulo minor nits inline

lib/Analysis/LazyValueInfo.cpp
507 ↗(On Diff #36820)

I ended up doing this today: http://reviews.llvm.org/rL251180 so you should be able to change this to just use getConstantRangeFromMetadata.

573 ↗(On Diff #36820)

By "should be" do you mean at some point in the future? Because AFAICT today mergeIn will do a union.

If you do mean "at some point in the future", please make that obvious, perhaps by changing this to a TODO or a FIXME.

This revision is now accepted and ready to land.Oct 24 2015, 1:22 AM
This revision was automatically updated to reflect the committed changes.