This is an archive of the discontinued LLVM Phabricator instance.

[SLP] Steer for the best chance in tryToVectorize() when rooting with binary ops.
ClosedPublic

Authored by vdmitrie on Apr 22 2022, 3:48 PM.

Details

Summary

tryToVectorize() method implements one of searching paths for vectorizable tree roots in SLP vectorizer,
specifically for binary and comparison operations. Order of making probes for various scalar pairs
was defined by its implementation: the instruction operands, then climb over one operand if
the instruction is its sole user and then perform same actions for another operand if previous
attempts failed. Problem with this approach is that among these options we can have more than a
single vectorizable tree candidate and it is not necessarily the one which encountered first.
Trying to build vectorizable tree for each possible combination for just evaluation is expensive.
But we already have lookahead heuristics mechanism which we use for finding best pick among
operands of commutative instructions. It calculates cumulative score for candidates in two
consecutive lanes. This patch introduces use of the heuristics for choosing the best pair among
several combinations. We only try one that looks as most promising for vectorization.
Additional benefit is that we reduce total number of vectorization trees built for probes
because we skip those looking non-profitable early.

Diff Detail

Event Timeline

vdmitrie created this revision.Apr 22 2022, 3:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 3:48 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
vdmitrie requested review of this revision.Apr 22 2022, 3:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 3:48 PM

Hi Valery, thanks for the patch. This looks good! Could you split it into 2 patches: one that renames lookahead heuristics (NFC) and the second (functional) one?

llvm/test/Transforms/SLPVectorizer/AArch64/invalid_type.ll
7

Do you need to update this test?

Hi Valery, thanks for the patch. This looks good! Could you split it into 2 patches: one that renames lookahead heuristics (NFC) and the second (functional) one?

Hi Alexey,
yeah, will do that. I actually have it split locally exactly like you suggested.

vdmitrie added inline comments.Apr 22 2022, 4:30 PM
llvm/test/Transforms/SLPVectorizer/AArch64/invalid_type.ll
7

I added check for vector types at line 9176 so we now are not reaching emission of the remark.

vporpo added inline comments.Apr 22 2022, 4:38 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1046–1047

nit: It also holds the operands of a VL, so it is probably best to mention this here too.

2016

nit: perhaps findBestRootPair ?

2018

We could also have a separate max-depth limit for this, because I guess it will not ran as frequently as the other one, so we could have a higher depth if required.

9227

nit: I think we can drop .hasValue(), if (!BestCandidate) should work fine.

vdmitrie added inline comments.Apr 22 2022, 5:13 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1046–1047

Hm, I'm not sure I understand what you mean here. You might be mislead by the way diff is shown here.
This is not renaming of existing VLOperands.
This new helper class formed basically by couple routines: getShallowScore and getScoreAtLevelRec which were pulled out of VLOperands along with score constants. The class does not store anything from VL.
It only needs total number of lanes for scoring. I even changed both methods to be const.

2016

Thanks for suggestion. Will apply it with next rebase.

2018

Will do. Any suggestion about option name?

9227

sure

vporpo added inline comments.Apr 22 2022, 5:22 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1046–1047

Oops, yeah you are right, I got confused by the diff, sorry about that.
Nice, thanks for refactoring it, it looks much better this way :D

2018

Hmm if we are sticking to using root to describe this, perhaps RootLookAheadMaxDpeth?

vdmitrie updated this revision to Diff 424685.Apr 22 2022, 7:46 PM

rebased + applied suggestions

This revision is now accepted and ready to land.Apr 25 2022, 4:17 AM
This revision was landed with ongoing or failed builds.Apr 25 2022, 12:26 PM
This revision was automatically updated to reflect the committed changes.