This is an archive of the discontinued LLVM Phabricator instance.

[GVN] Try to use an equivalent PHI after constructing one for load set
Needs RevisionPublic

Authored by dmakogon on Dec 9 2021, 3:09 AM.

Details

Summary

With this patch GVN looks for an equivalent PHI after it inserts one
for load set. If such PHI is found, it's used instead of the inserted one.
We say the PHI that should replace the load is equivalent to some other PHI
simply if their incoming values match. But if the incoming values
are binary operators, we do a special check: we assume that the load
operand of an operator is equal to the PHI we are checking against
(we can do this, because we are asked whether this inserted PHI is equivalent
to some other one and we know that the load is equivalent to the
inserted PHI).

Diff Detail

Event Timeline

dmakogon created this revision.Dec 9 2021, 3:09 AM
dmakogon requested review of this revision.Dec 9 2021, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2021, 3:09 AM
reames requested changes to this revision.Dec 10 2021, 9:18 AM
reames added inline comments.
llvm/lib/Transforms/Scalar/GVN.cpp
897

Doing this specifically for PRE/FRE is definitely the wrong place. Particularly, doing so by hacking up the implementation this way.

I think you should look at extending EliminateDuplicatePHINodes, or adding something new which matches recurrences at about the same call point. That is, let the phi-cycle be created, but then erase it again on the next iteration.

This revision now requires changes to proceed.Dec 10 2021, 9:18 AM