[SLP] Steer for the best chance in tryToVectorize() when rooting with binary ops.
authorValery N Dmitriev <valery.n.dmitriev@intel.com>
Mon, 25 Apr 2022 19:25:33 +0000 (12:25 -0700)
committerValery N Dmitriev <valery.n.dmitriev@intel.com>
Mon, 25 Apr 2022 19:25:33 +0000 (12:25 -0700)
commit88b9e46fb54c5321742d16016be5b2920facc018
treefb642dfc9f98df68bbb1ce018b28ea287d8fcd5d
parent6035649d4c763dab83376484c5fe515c2469a1bb
[SLP] Steer for the best chance in tryToVectorize() when rooting with binary ops.

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 that 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.

Reviewed By: Alexey Bataev (ABataev), Vasileios Porpodas (vporpo)
Differential Revision: https://reviews.llvm.org/D124309
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/AArch64/invalid_type.ll
llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-inseltpoison.ll
llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector.ll
llvm/test/Transforms/SLPVectorizer/X86/vectorize-pair-path.ll