This is an archive of the discontinued LLVM Phabricator instance.

[SLP] Extend reordering data of tree entry to support PHI nodes
ClosedPublic

Authored by skc7 on Nov 7 2022, 2:33 AM.

Details

Summary

SLPVectorize pass uses the order of vectorizable phi nodes in the basic block to form a tree entry and decides the mask of the resulting shuffle vector.
If tree entry has insertelement instruction sequence, they will be also converted to shufflevector with mask based on insertelement instruction order in BB.

In the BB, if the result of vectorizable phi nodes is used by insertelement instructions, the resulting masks of shuffle vectors after vectorizing these two tree entries can mismatch. This happens if the order of phi nodes and the order of use of results of phi nodes by extractelement/insertelement mismatch.

There will be a scope for optimizing these resulting shuffle vectors in the subsequent passes in the pipeline, if their shuffle masks match.

This change reorders the phinodes in the tree entry, based on the use of the results of phi nodes by extractelement/insertelement.

Fix getInsertIndex() which fails with scalableVectors.

Diff Detail

Event Timeline

skc7 created this revision.Nov 7 2022, 2:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2022, 2:33 AM
skc7 requested review of this revision.Nov 7 2022, 2:33 AM
skc7 set the repository for this revision to rG LLVM Github Monorepo.
skc7 updated this revision to Diff 473617.Nov 7 2022, 4:09 AM

Rebase.

ABataev added inline comments.Nov 7 2022, 6:26 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
289–304

Could precommit this change as a separate NFC change?

292–293

Could you rework this to reduce structured complexity?

292–293

No need for else and return substatement here.

3800–3801

Could precommit this change as a separate NFC change?

3910–3911

you can remove this check, since immediately after you check for exactly one use.

skc7 added inline comments.Nov 7 2022, 9:42 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
289–304

Please review: D137567

3800–3801

Please review: D137569

skc7 updated this revision to Diff 473900.Nov 8 2022, 12:35 AM

Rebase. Moved fixes for scalable vectors to reviews: D137567, D137569

skc7 updated this revision to Diff 473966.Nov 8 2022, 5:27 AM

Rebase. D137567, D137569 commits are merged upstream.

skc7 set the repository for this revision to rG LLVM Github Monorepo.Nov 8 2022, 5:27 AM
This revision is now accepted and ready to land.Nov 8 2022, 5:40 AM