This is an archive of the discontinued LLVM Phabricator instance.

[GVN] Propagate simple equalities from assumes within the tail of the block
ClosedPublic

Authored by reames on Aug 29 2019, 3:20 PM.

Details

Summary

This extends the existing logic for propagating constant expressions in an analogous manner for what we do across basic blocks. The core point is that we chose some order of operands, and canonicalize uses towards that one.

The heuristic used is inspired by the one used across blocks; in a follow up change, I'd like to common them so that the cross block version uses the slightly stronger ordering herein. If preferred, I can weaken this one to match the cross block, then strengthen both in a single patch.

As noted by the TODOs in the code, there's a good amount of room for improving the existing code and making it more powerful. Unless there's strong objection, I'd like to land this first, then iterate. I am willing to commit to the findLeader change, and *maybe* the general restructure of propagateEqualities (depending on how much that snowballs - the tests are *super fragile*).

Diff Detail

Repository
rL LLVM

Event Timeline

reames created this revision.Aug 29 2019, 3:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2019, 3:20 PM
lebedev.ri added inline comments.
lib/Transforms/Scalar/GVN.cpp
1448 ↗(On Diff #217984)

s/const/???/

reames updated this revision to Diff 218113.Aug 30 2019, 9:04 AM

Remove copied comment which doesn't make sense in new context

reames marked an inline comment as done.Aug 30 2019, 9:04 AM
fhahn accepted this revision.Sep 1 2019, 9:02 AM

LGTM, with a few nits/suggestions for comments. Also, it would be great if you could also add a test case with floats.

lib/Transforms/Scalar/GVN.cpp
1390 ↗(On Diff #218113)

could just be something like the snippet below, which might be short & explicit enough to have inline.

any_of(I.users(), [B](User *U) {
return isa<Instruction>(U) &&  cast<Instruction>(U)->getParent() == B;
});
1438 ↗(On Diff #218113)

We only replace the uses that come after in the current BB, right? I think it would be better to say that, instead of talking about replacing all dominated uses

1439 ↗(On Diff #218113)

It might be worth mentioning what we mean by oldest here (seen earlier during value numbering)

1450 ↗(On Diff #218113)

Shouldn't that be %0? Did I miss where %v is coming from in the example?

1458 ↗(On Diff #218113)

Typo Hueristically

1479 ↗(On Diff #218113)

Could you add a test case for this case?

1482 ↗(On Diff #218113)

Again I think mentioning that we only replacing uses in the current BB would be slightly clearer.

This revision is now accepted and ready to land.Sep 1 2019, 9:02 AM
This revision was automatically updated to reflect the committed changes.

LGTM, with a few nits/suggestions for comments. Also, it would be great if you could also add a test case with floats.

Landed w/comments applied and one additional fix noticed when writing your requested floating point test case.

It turned out the code I was extending had a bug where it didn't account for the fact that +0.0 compares equal to -0.0. I went ahead and added a bailout since the none of the existing tests were effected.

The extra bit seemed obvious. If anyone thinks it warrants re-review, let me know and I'll revert.