This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Switch to checking sinking legality for recurrences in VPlan.
ClosedPublic

Authored by fhahn on Jan 30 2023, 5:20 AM.

Details

Summary

Building on D142885 and D142589, retire the SinkAfter map from the
recurrence handling code. It is replaced by checking whether it is
possible to sink all users of a recurrence directly in VPlan. This
results in simpler code overall and allows to handle additional cases
(see the improvements in @test_crash).

Depends on D142885.
Depends on D142589.

Diff Detail

Event Timeline

fhahn created this revision.Jan 30 2023, 5:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2023, 5:20 AM
fhahn requested review of this revision.Jan 30 2023, 5:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2023, 5:20 AM
fhahn updated this revision to Diff 506718.Mar 20 2023, 2:14 PM

Rebase and ping :)

Ayal added inline comments.Mar 26 2023, 9:23 AM
llvm/include/llvm/Analysis/IVDescriptors.h
189–193

Leave a comment that this optimistically assumes instructions may be reordered successfully if needed?

llvm/lib/Analysis/IVDescriptors.cpp
967

(Relying here on Previous is fragile as it may have been considered for sinking.)

985

nit: such a set can be used to store "Seen" recipes avoiding revisiting recipes as they are added to the worklist and then iterating over them in dominance order to sink them.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
647–648

nit: is this consideration of replicate regions is still needed here, or can be replaced by an assert?

689–690

Is this change to support multiple def'd recipes independent of the rest of this patch?

735

Is SeenPrevious really needed, to make sure chained FORs are processed in order, or can it be removed - given that every FOR takes care of its own sinkings followed by introducing its splice hooking it up to defs and uses? Potentially sinking candidates multiple times.

llvm/lib/Transforms/Vectorize/VPlanTransforms.h
79

Explain return value?

llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll
649–650

nit: update name of test, and its comment?

fhahn updated this revision to Diff 511085.Apr 5 2023, 6:41 AM
fhahn marked 7 inline comments as done.

Address latest comments, thanks!

llvm/include/llvm/Analysis/IVDescriptors.h
189–193

Added, thanks!

llvm/lib/Analysis/IVDescriptors.cpp
967

Agreed, but I think until we fully check legality in VPlan I think it is needed for now here (and I think it is not different to the current handling)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
647–648

Thanks, adjusted in c18bc7f7feac.

689–690

Yep that's independent of the patch, I restored the original code here.

735

I checked and it is not needed in the latest version indeed! It also yields a nice improvement in @test_pr54223_sink_after_insertion_order! Updated to remove it.

llvm/lib/Transforms/Vectorize/VPlanTransforms.h
79

Added a comment, thanks!

llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll
649–650

Added, thanks!

Ayal accepted this revision.Apr 8 2023, 11:29 AM

LGTM

llvm/lib/Analysis/IVDescriptors.cpp
967

(Above comment refers to ignoring if SinkAfter(Previous), which is the source of fragility/optimism.)

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9071

TODO (Independent of this patch): Consider moving this potentially bailing-out check earlier to save compile-time for bailed-out cases, which would avoid vectorizing altogether.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
654–655

Add meaning of return value?

667–671

"cannot" >> "must not"?
If SinkCandidate equals Previous a cycle is closed and phi is not a fixed order recurrence.

735

Very well! A direct consequence of VPlan's design to rely on updated def-use IR rather than recorded maps and sets.

This revision is now accepted and ready to land.Apr 8 2023, 11:29 AM
fhahn updated this revision to Diff 513326.Apr 13 2023, 12:13 PM
fhahn marked 2 inline comments as done.

Address latest comments and rebase, thanks! I am planning on landing this shortly.

Heads up: This change is causing a clang hang when building xz utils (https://github.com/tukaani-project/xz). I'll file a bug and attach a repro asap.

fhahn added a comment.Apr 20 2023, 1:38 AM

Thanks for the report! I recommitted the change with a fix for the compile-time issue in 6b8d19d2b57ecd45eb2ff1964798f3cd8c907ac4. The new version of the patch adds a set to avoid duplicating work in isFixedOrderRecurrence, which was previously done through the removed SinkAfter map.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
654–655

Thanks, documented!

667–671

Adjusted the comment, thanks!