This is an archive of the discontinued LLVM Phabricator instance.

[SLP]Outline and fix code for finding common insertelement vectors.
ClosedPublic

Authored by ABataev on Dec 1 2021, 1:48 PM.

Details

Summary

Need to outline the code for finding common vectors in insertelement
instructions into a separate function for future patches. It also
improves the process by adding some extra checks for early exit and
fixes a bug where it always finds the match because of erroneous compare
of the same values.

Diff Detail

Event Timeline

ABataev created this revision.Dec 1 2021, 1:48 PM
ABataev requested review of this revision.Dec 1 2021, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2021, 1:48 PM
RKSimon added inline comments.Dec 1 2021, 2:35 PM
llvm/test/Transforms/SLPVectorizer/X86/cmp_commute.ll
2–3

looks like you need to add --check-prefixes=CHECK,SSE + --check-prefixes=CHECK,AVX

RKSimon added inline comments.Dec 1 2021, 2:38 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5460–5461

If this better?

if (auto *VU = dyn_cast_or_null<InsertElementInst>(EU.User)) {
ABataev added inline comments.Dec 1 2021, 2:42 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5460–5461

Yes, definitely!

llvm/test/Transforms/SLPVectorizer/X86/cmp_commute.ll
2–3

Yep, forgot to update, thanks!

vporpo added inline comments.Dec 1 2021, 4:16 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5392

Could you fix the comment. I guess it meant to say something like: "Go through *the vector operand* of insertelement instructions..."

5398

Just curious, why do we need to check for for a single use except for VU and V? Is this related to the bug you mentioned in the patch summary?

ABataev marked an inline comment as done.Dec 2 2021, 5:50 AM
ABataev added inline comments.
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5398

It is an early exit (which can be considered as a bugfix but not one mentioned in the description). Insertelements with multiple uses are not the part of the buildvector, they can only be used as an initial element for the buildvector sequence. We have a similar check in findBuildAggregate_rec function (requires only a single use for the insertelement instruction).
The bugfix I mentioned in the description relates to line 5395. Previously, the check there was IE1 == VU || IE2 == V, which is not correct.

ABataev updated this revision to Diff 391297.Dec 2 2021, 5:59 AM

Rebase + address comments

RKSimon requested changes to this revision.Dec 2 2021, 6:50 AM
This revision now requires changes to proceed.Dec 2 2021, 6:50 AM

Ah, yes, forgot to update the test

ABataev updated this revision to Diff 391317.Dec 2 2021, 6:56 AM

Fix test checks

RKSimon accepted this revision.Dec 2 2021, 7:13 AM

LGTM - cheers

This revision is now accepted and ready to land.Dec 2 2021, 7:13 AM