This is an archive of the discontinued LLVM Phabricator instance.

GVN-hoist: use a DFS numbering of instructions (PR28670)
ClosedPublic

Authored by sebpop on Jul 25 2016, 1:50 PM.

Details

Summary

Instead of DFS numbering basic blocks we now DFS number instructions that avoids the costly operation of which instruction comes first in a basic block.

Patch mostly written by Daniel Berlin.

Diff Detail

Repository
rL LLVM

Event Timeline

sebpop updated this revision to Diff 65413.Jul 25 2016, 1:50 PM
sebpop retitled this revision from to GVN-hoist: use a DFS numbering of instructions (PR28670).
sebpop updated this object.
sebpop added reviewers: dberlin, majnemer.
sebpop added a subscriber: llvm-commits.
dberlin added inline comments.Jul 25 2016, 2:16 PM
llvm/lib/Transforms/Scalar/GVNHoist.cpp
787 ↗(On Diff #65413)

Oh, this is the part i forgot :)
Oh well.

One thought:

If we are always inserting at the end of a block (i didn't look), btw, we'd be better off having a per-block numbering.

If we make "I" (here) a member variable called LastDFSNumber, we can then just update the per-block numberings by using ++LastDFSNumber as the number for the hoisted instruction. This avoids walking the instruction stream again on every iteration.

llvm/test/Transforms/GVN/hoist.ll
638 ↗(On Diff #65413)

So wait, this hoists more than we did before?

sebpop added inline comments.Jul 25 2016, 2:24 PM
llvm/lib/Transforms/Scalar/GVNHoist.cpp
787 ↗(On Diff #65413)

Yes, that would work.
I was also thinking along the lines of how we locally update the MSSA, we could also locally update the DFS numbers.
In that case we should compute both a DFS for BBs that will not change with hoisting, and then a DFS for instructions local to a BB and we could locally patch when hoisting instructions.

llvm/test/Transforms/GVN/hoist.ll
638 ↗(On Diff #65413)

No. I added this missing gep because I changed the CHECK into a CHECK-NEXT, and we now pattern match all the basic block where we hoist.

dberlin accepted this revision.Jul 25 2016, 2:33 PM
dberlin edited edge metadata.

Gotcha.
We should land this and then update the DFS numbers in the patch where do you MSSA updates.

This revision is now accepted and ready to land.Jul 25 2016, 2:33 PM
This revision was automatically updated to reflect the committed changes.