This is an archive of the discontinued LLVM Phabricator instance.

[LV] Update dominator tree before fixing external IV users
ClosedPublic

Authored by mssimpso on Dec 29 2016, 2:03 PM.

Details

Summary

This patch delays the fix-up step for external induction variable users until after the dominator tree has been properly updated. This should fix PR30742. The SCEVExpander in InductionDescriptor::transform can generate code in the wrong location if the dominator tree is not up-to-date.

I'm not quite sure if the is the right approach or not. In particular, we use InductionDescriptor::transform in other locations before the dominator tree has been updated. Maybe this isn't a problem because the vector loop is still detached from the dominator tree? In any case, I made an attempt to keep the dominator tree up-to-date at the outset when creating the structure of the vector loop, but that caused the SCEVExpander to generate worse code (the expander was either crashing or creating a new canonical induction variable for every loop). The use of InductionDescriptor::transform when fixing the external induction variable users may be unique in that the insertion point is outside the loop (it's in the middle block). I'm not sure if this would make a difference, though. Please take a look.

Reference: https://llvm.org/bugs/show_bug.cgi?id=30742

Diff Detail

Repository
rL LLVM

Event Timeline

mssimpso updated this revision to Diff 82694.Dec 29 2016, 2:03 PM
mssimpso retitled this revision from to [LV] Update dominator tree before fixing external IV users.
mssimpso updated this object.
mssimpso added a reviewer: mkuper.
mssimpso added subscribers: llvm-commits, mcrosier.
mssimpso updated this object.Dec 29 2016, 2:03 PM
mkuper edited edge metadata.Jan 3 2017, 1:44 PM

My gut feeling is that we really want to update DT as we go.
Even if all current uses of transform() except this one are safe (and I'm not at all sure about that), leaving this as is sounds very brittle, since any additional use of transform() can potentially break it.

My gut feeling is that we really want to update DT as we go.
Even if all current uses of transform() except this one are safe (and I'm not at all sure about that), leaving this as is sounds very brittle, since any additional use of transform() can potentially break it.

I totally agree. I'm happy to continue looking at this, but when I updated the DT at the beginning (right after we create the new loop structure), subsequent calls to transform caused the Expander to generate "new" canonical IVs in addition to the ones we already create. Any idea why it would do this? I haven't yet figured out why the Expander would be generating worse code after such a change.

For the Expander, it wants an IV that starts at zero and steps by one. But LV generates IVs that step by VFxUF.

mkuper added a comment.Jan 3 2017, 1:59 PM

My gut feeling is that we really want to update DT as we go.
Even if all current uses of transform() except this one are safe (and I'm not at all sure about that), leaving this as is sounds very brittle, since any additional use of transform() can potentially break it.

I totally agree. I'm happy to continue looking at this, but when I updated the DT at the beginning (right after we create the new loop structure), subsequent calls to transform caused the Expander to generate "new" canonical IVs in addition to the ones we already create. Any idea why it would do this? I haven't yet figured out why the Expander would be generating worse code after such a change.

For the Expander, it wants an IV that starts at zero and steps by one. But LV generates IVs that step by VFxUF.

I'm not really familiar with the expander, unfortunately.
In any case, I'm ok with this patch going in in the meanwhile. I think it still moves us in the right direction of updating DT earlier. :-)

mssimpso updated this revision to Diff 83616.Jan 9 2017, 5:52 AM
mssimpso edited edge metadata.

Added a FIXME comment indicating that we should work towards updating the dominator tree earlier.

Should we commit this now so we can close the PR before the 4.0 branch? We can later try to resolve the SCEV issues and keep the dominator tree up-to-date as we go.

mkuper accepted this revision.Jan 9 2017, 10:51 AM
mkuper edited edge metadata.

SGTM

This revision is now accepted and ready to land.Jan 9 2017, 10:51 AM
This revision was automatically updated to reflect the committed changes.