This is an archive of the discontinued LLVM Phabricator instance.

NewGVN: Start making use of predicateinfo pass.
ClosedPublic

Authored by dberlin on Feb 7 2017, 2:00 PM.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

dberlin created this revision.Feb 7 2017, 2:00 PM

We don't yet pass edge.ll because we don't handle switch statements in predicateinfo.
condprop.ll also has one silly testcase :)

dberlin updated this revision to Diff 87656.Feb 8 2017, 7:08 AM
  • Update with fixes for botched logic
dberlin updated this revision to Diff 87960.Feb 9 2017, 9:01 PM
  • Convert to early exit form for better formatting
  • NewGVN: Update for ranking being committed
davide edited edge metadata.Feb 12 2017, 12:23 PM

THis needs some tests (unless there are some which are are XFAIL'D and now pass). Other than that, great to see this making progress =)
Some comments inline.

lib/Transforms/Scalar/NewGVN.cpp
867–895 ↗(On Diff #88092)

I starred at this for long, and I think it's correct. I do also think you can simplify this to make it *slightly* more readable, at least in my opinion, removing the else after return.

903 ↗(On Diff #88092)

s/Things/intrinsics/ (or instructions)? Also, full stop at the end of the comment I think (nit)

1110–1113 ↗(On Diff #88092)

I'm not sure this is entirely right, do you have a test where this triggers so I can take a look?

1841 ↗(On Diff #88092)

Any chance you can use something like unique_ptr<> instead of naked new (or something similar)?

2480–2481 ↗(On Diff #88092)

s/it's/its/

davide requested changes to this revision.Feb 12 2017, 12:24 PM

Marking as request changes so that I can keep track of what I need to review from the Phab UI

This revision now requires changes to proceed.Feb 12 2017, 12:24 PM
dberlin marked 3 inline comments as done.Feb 12 2017, 12:49 PM
dberlin added inline comments.
lib/Transforms/Scalar/NewGVN.cpp
867–895 ↗(On Diff #88092)

Yeah, i think, over time, we should try to move a lot of this logic to some central place.

Simplify* knows how to do a *lot* of it (and sadly, does it's own walking to try to figure out some cases), but it's a complex maze of twisty passages, and it's not clear to me how to shove predicate info into it in a sane way.

Most of these tests are covered by edge.ll, which we'll pass once the switch stuff goes in

903 ↗(On Diff #88092)

Fixed.

1110–1113 ↗(On Diff #88092)

This is from GVN:

02244 // If "A >= B" is known true, replace "A < B" with false everywhere.
02245 CmpInst::Predicate NotPred = Cmp->getInversePredicate();
02246 Constant *NotVal = ConstantInt::get(Cmp->getType(), isKnownFalse);

It does not restrict itself to equality predicates.

I'll grab the appropriate testcases, but the only cases i believe this could be false is somewhere in the land of floating point.

I also thought it was weird, but:

Looking at it from the perspective of truth tables, inverse predicate just returns a truth table that has true and false swapped.

So if the other comparison is false, and it has the same operands, the inverse predicate must be true (because every place that predicate has false in the truth table, this one has true)

1841 ↗(On Diff #88092)

Yes, i'll fix

dberlin marked 2 inline comments as done.Feb 12 2017, 12:59 PM

Also, i was kind of hoping to be able to make the testcases a non-issue by just passing them, but instead, for most, we are now passing 9/10 in a file, and there's no way to xfail the single testcase :(

I may move them into -xfail.ll tests for now or something, just so we have passing testcases.

Other suggestions welcome.

Also, i was kind of hoping to be able to make the testcases a non-issue by just passing them, but instead, for most, we are now passing 9/10 in a file, and there's no way to xfail the single testcase :(

I may move them into -xfail.ll tests for now or something, just so we have passing testcases.

Other suggestions welcome.

Splitting the test seems the best strategy to me.

davide accepted this revision.Feb 12 2017, 1:07 PM

This LGTM with the comments addressed. Feel free to commit without updating the review to phab.

This revision is now accepted and ready to land.Feb 12 2017, 1:07 PM
dberlin added inline comments.Feb 12 2017, 10:44 PM
lib/Transforms/Scalar/NewGVN.cpp
882 ↗(On Diff #88092)

For the record: The above part is true, but this is wrong.
It's only true for equality (ICMP_EQ and ICMP_NE)
After your comment below, I wrote a little fuzzer that tested every variant, and .... it flagged this (the part you mentioned below is definitely correct)
Trivial example:
%tmp3 = load i32, i32* %tmp, align 4
%tmp5 = icmp ult i32 %tmp3, 16

%tmp5 is false when equal.
That does not imply that tmp3 == 16.

The more i stare at this, the more unhappy i am that all this logic is not somewhere else.
I added it to my todo list to see about trying to plumb this through various parts of simplifyinst, which already has well tested logic for these simplifications, it just needs to know we know something about the value.

This revision was automatically updated to reflect the committed changes.