1396 Commits

Author SHA1 Message Date
Alexey Bataev
9d4fbcd5ff Revert "[SLP]Fix PR63141: compareCmp is not strict weak ordering."
This reverts commit f3ebd88064d7f1c36a8272b3e5f7d53501c3f53b to pacify
windows-based buildbots.
2023-06-28 04:37:27 -07:00
Alexey Bataev
f3ebd88064 [SLP]Fix PR63141: compareCmp is not strict weak ordering.
Added some extra checks for comapreCMP function if IsCompatibility is
false to make it meat the strict weak ordering requirements to be
correctly used in sort functions.
2023-06-27 14:31:55 -07:00
Anna Thomas
0ce2ce2a47 Revert "Fix mlir windows buildbot after ec146cb7c0b4"
This reverts commit 46c2e1fdb3065542bed96ba944ae4a58465d2b5e.

The fix was already landed in 51e917d4af.
2023-06-20 15:29:53 -04:00
Anna Thomas
b6979698ea Fix mlir windows buildbot after ec146cb7c0b4
ec146cb7c0b4 added two new ReducKinds for float maximum and minimum
(along with support in loop vectorizer).

Enumerate these kinds in SLPVectorizer to fix mlir windows build bot
errors:

C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Vectorize\SLPVectorizer.cpp(13883): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Vectorize\SLPVectorizer.cpp(13883): warning C4062: enumerator 'llvm::RecurKind::FMinimum' in switch of enum 'llvm::RecurKind' is not handled
2023-06-20 15:24:36 -04:00
Benjamin Kramer
51e917d4af [SLP] Silence -Wswitch warning after ec146cb7c0b4a162ee73463e6c7bb306b99e013b
{min,max}imum(X, X) is X so we can take the same path as min/max.
2023-06-20 19:51:08 +02:00
Mikael Holmen
ac9b9e3aad [SLPVectorizer] Don't include isAssumeLikeIntrinsics in ScheduleRegionSize
We don't want the existence of debug instructions affect codegen so we now
ignore debug instructions and other "isAssumeLikeIntrinsics in the
"extend schedule region" search loop in
BoUpSLP::BlockScheduling::extendSchedulingRegion.

Differential Revision: https://reviews.llvm.org/D152441
2023-06-14 13:00:15 +02:00
Ivan Kelarev
884bf2e1f1 [NFC][SLP] Fix a few minor formatting issues
Differential Revision: https://reviews.llvm.org/D152395
2023-06-12 14:22:46 -07:00
Alexey Bataev
95b631181a [SLP]Fix getSpillCost functions.
There are several issues in the current implementation. The instructions
are not properly ordered, if they are placed in different basic blocks,
need to reverse the order of blocks. Also, need to exclude
non-vectorizable nodes and check for CallBase, not CallInst, otherwise
invoke calls are not handled correctly.
2023-05-26 12:19:28 -07:00
Alexey Bataev
ae5ff3ca0c [SLP]Fix PR62665: compiler crash when trying to access non-existing mask
element.

Need to check at first if the SubMask element is PoisonMaskElem to avoid
compiler crash.
2023-05-22 13:43:25 -07:00
Luke Lau
c27a0b21c5 [SLP][RISCV] Account for offset folding in getPointersChainCost
For a GEP in a pointer chain, if:
1) a pointer chain is unit-strided
2) the base pointer wasn't folded and is sitting in a register somewhere
3) the distance between the GEP and the base pointer is small enough and
   can be folded into the addressing mode of the using load/store

Then we can exclude that GEP from the total cost of the pointer chain,
as it will likely be folded away.

In order to check if 3) holds, we need to know the type of memory access
being made by the users of the pointer chain. For that, we need to pass
along a new argument to getPointersChainCost. (Using the source pointer
type of the GEP isn't accurate, see https://reviews.llvm.org/D149889 for
more details).

Also note that 2) is currently an assumption, and could be modelled more
accurately.

This prevents some unprofitable cases from being SLP vectorized on
RISC-V by making the scalar costs cheaper and closer to the actual
codegen.

For now the getPointersChainCost hook is duplicated for RISC-V to prevent
disturbing other targets, but could be merged back in and shared with
other targets in a following patch.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D149654
2023-05-22 13:55:30 +01:00
Vasileios Porpodas
806dea46be [SLP] Cleanup: Remove tryToVectorizePair(), most probably NFC
`tryToVectorizePair()` adds a level of indirection over `tryToVectorizeList()`.
I am not really sure why it is needed, it looks redundant.

I replaced all calls to `tryToVectorizePair()` with calls to
`tryToVectorizeList()` and I am not seeing any failures.

Differential Revision: https://reviews.llvm.org/D151004
2023-05-19 20:25:20 -07:00
Vasileios Porpodas
338fc76200 [SLP][NFC] Cleanup: Remove KeyNodes set.
I don't see a good reason form having the `KeyNodes` set.
This patch removes the set.

Differential Revision: https://reviews.llvm.org/D150918
2023-05-19 10:30:02 -07:00
Alexey Bataev
9a7248f561 [SLP]Fix crash for scalarized vectors.
Need to remove insertion of the nodes to the InVector in case of
scalarized vectors too to avoid compiler crashes.
2023-05-17 06:32:22 -07:00
Luke Lau
d088b8af93 [SLP] Rename IsUniformStride to IsUnitStride. NFCI
IsUniformStride is only used when the stride is a unit-stride, i.e. in a
plain wide vector load. This tightens the condition and renames it to
isUnitStride. It removes the old unused getUniformStrided() variant, as
isUnitStride should now imply that the stride is known.

Reviewed By: vdmitrie, ABataev

Differential Revision: https://reviews.llvm.org/D150662
2023-05-17 13:21:33 +01:00
Alexey Bataev
6c7acc6409 [SLP][NFC]Add missing finalize params in the CostEstimator, NFC.
Prepare functions for generalization of codegen/cost estimation.

Differential Revision: https://reviews.llvm.org/D150121
2023-05-15 11:17:37 -07:00
Vasileios Porpodas
ddb2188afc [SLP][NFC] Cleanup: Separate vectorization of Inserts and CmpInsts.
This deprecates `vectorizeSimpleInstructions()` and replaces it with separate
functions that vectorize CmpInsts and Inserts.

Differential Revision: https://reviews.llvm.org/D149993
2023-05-15 10:12:34 -07:00
Vasileios Porpodas
dda2a5d457 [SLP][NFC] Rename a couple of variables and replace an if-else with an std::min
- Rename `LimitForRegisterSize` to `MaxVFOnly` to make the meaning of the limit less ambiguous
- Rename `OpsWidth` to `ActualVF`, which makes it clear that this is the VF we are using for vectorization.
- Replace the if-else code for the initialization of OpsWidth with an std::min.

Differential Revision: https://reviews.llvm.org/D150241
2023-05-10 09:37:58 -07:00
Alexey Bataev
2672c6e4dc [SLP][NFC]Add processBuildVector member function, NFC.
Introduce processBuildVector as a next step to generalize code for cost
estimation and code emission for gather/buildvector nodes.

Differential Revision: https://reviews.llvm.org/D149973
2023-05-05 11:00:53 -07:00
Vasileios Porpodas
7749f6e976 [SLP][NFC] Cleanup: Outline the code that vectorizes CmpInsts into a seaparate function.
Differential Revision: https://reviews.llvm.org/D149919
2023-05-05 09:56:41 -07:00
Alexey Bataev
ca3f4236e4 [SLP][NFC]Add/use gather and createFreeeze member functions in
ShuffleInstructionBuilder, NFC.
2023-05-05 09:12:54 -07:00
Alexey Bataev
d726f99d43 [SLP][NFC]Do not try to revectorize instructions with constant operands, NFC.
The pass should not try to revectorize instructions with constant
operands, which were not folded by the IRBuilder. It prevents the
non-terminating loop in the SLP vectorizer for non foldable constant
operations.
2023-05-04 13:52:42 -07:00
Alexey Bataev
c0e5e7db9a [SLP]Fix a crash trying finding insert point for GEP nodes with non-gep
insts.

If the vectorizable GEP node is built, which should not be scheduled,
and at least one node is a non-gep instruction, need to insert the
vectorized instructions before the last instruction in the list, not
before the first one, otherwise the instructions may be emitted in the
wrong order.
2023-05-04 09:43:37 -07:00
Vasileios Porpodas
ce46e1aa76 [NFC][SLP] Cleanup: Simplify traversal loop in SLPVectorizerPass::vectorizeHorReduction().
This includes a couple of changes:
1. Moves the code that changes the root node out of the `TryToReduce` lambda and out of the traversal loop.
2. Since that code moved, there isn't much left in `TryToReduce` so the code was inlined.
3. The phi node variable `P` was also being used as a flag that turns on/off the exploration of operands as new seeds. This patch uses a new variable `TryOperandsAsNewSeeds` for this.
4. Simplifies the code executed when vectorization fails.

The logic of the code should be identical to the original, but I may be missing something not caught by tests.

Differential Revision: https://reviews.llvm.org/D149627
2023-05-03 12:48:01 -07:00
Alexey Bataev
d62734800c [SLP][NFC]Add ShuffleCostBuilder and generalize BaseShuffleAnalysis::createShuffle function, NFC.
Added basic implementation of ShuffleCostBuilder class in
ShuffleCostEstimator and generalized BaseShuffleAnalysis::createShuffle
function to support emission of Value */InstructionCost for the
vectorization/cost estimation.

Differential Revision: https://reviews.llvm.org/D149171
2023-05-03 12:30:54 -07:00
Vasileios Porpodas
07484d249b [NFC][SLP] Fix typo
Differential Revision: https://reviews.llvm.org/D149670
2023-05-02 11:14:08 -07:00
Vasileios Porpodas
fe1e50cd15 [NFC][SLP] Cleanup: Replace Value* operand with Instruction* in vectorizeRootInstruction() and vectorizeHorReduction()
This makes it explicit that these functions work with instructions, and avoids
calling them if the operand is not an instruction.

Differential Revision: https://reviews.llvm.org/D149465
2023-04-28 12:35:09 -07:00
Vasileios Porpodas
92b2a266e9 [NFC][SLP] Cleanup: Moves code that changes the reduction root into a separate function.
This makes `matchAssociativeReduction()` a bit simpler.

Differential Revision: https://reviews.llvm.org/D149452
2023-04-28 10:05:32 -07:00
Alexey Bataev
8bacd75125 [SLP][NFC]Fix a warning because of the missing parens, NFC. 2023-04-27 16:59:37 -07:00
Alexey Bataev
1604a100f1 [SLP][NFC]Avoid extra useless ConstantVector creation, use PointerUnion
instead, NFC.

Better to use PointerUnion<Value *, const TreeEntry *> instead of extra
attempts of creating null vector values, where possible.
2023-04-27 10:48:14 -07:00
ManuelJBrito
d22edb9794 [IR][NFC] Change UndefMaskElem to PoisonMaskElem
Following the change in shufflevector semantics,
poison will be used to represent undefined elements in shufflevector masks.

Differential Revision: https://reviews.llvm.org/D149256
2023-04-27 18:01:54 +01:00
Alexey Bataev
cf792f664a [SLP]Fix a crash for the replaced vectorized value.
If two nodes share the same value, which is replaced in one of the
nodes, need to automatically replace same value in all nodes. Btter to
use WeakTrackingVH for this to fix compiler crash.
2023-04-27 09:32:00 -07:00
Luke Lau
5a4b7e1f2e [SLP] Deduplicate loads subkey generator. NFCI
Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D148923
2023-04-25 09:34:40 +01:00
Alexey Bataev
b1abc2beaf [SLP]Fix PR58616: assert for gep nodes with different basic blocks.
Need to relax the assertion check in the FindFirstInst lambda for GEP
nodes with non-GEP instruction to avoid compiler crash.
2023-04-24 07:41:06 -07:00
Jay Foad
593e25ffae [Vectorize] Fix vectorization, scalarization and folding of llvm.is.fpclass
llvm.is.fpclass is different from other vectorizable intrinsics in that
it is overloaded on an argument type, not on the return type.

Differential Revision: https://reviews.llvm.org/D148905
2023-04-24 13:42:08 +01:00
Alexey Bataev
851a12138a [SLP]Fix the cost for the extractelements, used in several nodes.
Currently the compiler calculates the compensation cost for the
extractelements, removed during vectorization. But if the extractelement
instruction is used in several nodes, we can calculate the compensation
for them several times.

Differential Revision: https://reviews.llvm.org/D148806
2023-04-21 09:05:03 -07:00
Alexey Bataev
403bd583a8 [SLP]Fix a crash on scalarized vectors.
Need to register in-vector for scalarized types to avoid crash in
further analysis.
2023-04-21 08:13:48 -07:00
Alexey Bataev
3b7d298322 [SLP][NFC]Make computeExtractCost a member of ShuffleCostEstimator, NFC.
Moved computeExtractCost to ShuffleCostEstimator class as another step
for unifying actual codegen/cost estimation for buildvectors.

Differential Revision: https://reviews.llvm.org/D148864
2023-04-21 06:52:53 -07:00
Alexey Bataev
0e1312fbe0 [SLP][X86]Fix the cost of reused gathers/buildvectors and floats insert.
There are 2 problems in the cost estimation for buildvector/gather.
1. If the buildvector/gather node is the same as another one node, need
   to estimate the cost of this node as 0.
2. The cost of inserting float point register to non-poison vector is
   not 0, it should not be considered free.

Differential Revision: https://reviews.llvm.org/D148801
2023-04-20 09:34:46 -07:00
Alexey Bataev
8cf0290c4a [SLP]Fix cost estimation for buildvectors with extracts and/or constants.
If the partial matching is found and some other scalars must be
inserted, need to account the cost of the extractelements, transformed
to shuffles, and/or reused entries and calculate the cost of inserting
constants properly into the non-poison vectors.
Also, fixed the cost calculation for final gather/buildvector sequence.

Differential Revision: https://reviews.llvm.org/D148362
2023-04-19 05:54:58 -07:00
Alexey Bataev
1ce4b26a21 [SLP]Add final resize to ShuffleCostEstimator::finalize member function and basic add member functions.
Implemented the reshuffling in finalize member function + add basic
support for add member functions, used during vector build.

Part of D110978

Differential Revision: https://reviews.llvm.org/D148279
2023-04-18 11:52:04 -07:00
Alexey Bataev
d7a40a447f Revert "[SLP]Add final resize to ShuffleCostEstimator::finalize member function and basic add member functions."
This reverts commit cd341f3f4878137d1c9e7a05c4c3a7bd8ff216dc to fix
a crash revealed by buildbot https://lab.llvm.org/buildbot#builders/124/builds/7108.
2023-04-18 10:41:00 -07:00
Alexey Bataev
cd341f3f48 [SLP]Add final resize to ShuffleCostEstimator::finalize member function and basic add member functions.
Implemented the reshuffling in finalize member function + add basic
support for add member functions, used during vector build.

Part of D110978

Differential Revision: https://reviews.llvm.org/D148279
2023-04-18 05:51:23 -07:00
Bjorn Pettersson
21a6890856 [Vectorize] Clean up Transforms/Vectorize.h
Removed definitions of vectorizeBasicBlock and VectorizeConfig
(possibly a remnant from the BBVectorize pass that was removed
way back in 2017).

Also reduced amount of include dependencies to Transforms/Vectorize.h.
2023-04-17 13:54:19 +02:00
Vasileios Porpodas
7e67a9473d [SLP][NFC] Remove Limit from tryToVectorizeSequence() arguments.
Limit turns out to be implemented in the exact same way for all calls to
tryToVectorizeSequence(). So this patch removes it and implements it internally
as a lambda function.

Differential Revision: https://reviews.llvm.org/D148382
2023-04-14 14:58:57 -07:00
Alexey Bataev
a4eff2b56c [SLP][NFC]Remove extra semicolons after function definitions, NFC 2023-04-13 11:33:25 -07:00
Alexey Bataev
f82eb7e066 [SLP]Introduce gather cost estimation function.
Introduced BoUpSLP::ShuffleCostEstimator::gather function as an initial
implementation of the gather/buildvector cost estimation for buildvector
nodes. It will allow to use general codegen infrastructure for better
cost estimation + it improves the cost estimation for the
gathers/buildvectors.

Improved part of D110978.

Differential Revision: https://reviews.llvm.org/D148174
2023-04-13 10:16:00 -07:00
Simon Pilgrim
b3480d5ede [SLP] Compute min/max scalar reduction costs using min/max intrinsics instead of expanded cmp+sel
By default these will expand back to cmp/sel, but some targets (X86) has optimized costs for scalar integer min/max patterns which are lower than the default expansion (pre-SSE41 is particularly weak for vector min/max support).

Differential Revision: [SLP] Compute min/max scalar reduction costs using min/max intrinsics instead of expanded cmp+sel
2023-04-13 17:00:39 +01:00
Simon Pilgrim
9e30b87afb [TTI] getMinMaxReductionCost - add FastMathFlag argument
Similar to the getArithmeticReductionCost / getExtendedReductionCost calls (which really don't need to use std::optional<>).

This will be necessary to correct recognize fast/nnan fmax/fmul reductions which can avoid nan handling - which will allow us to remove the fmax/fmin special case in X86TTIImpl::getMinMaxCost and use getIntrinsicInstrCost like we do for integer reductions (63c3895327839ba5b57f5b99ec9e888abf976ac6).

Differential Revision: https://reviews.llvm.org/D148149
2023-04-13 10:42:42 +01:00
Alexey Bataev
b28f407df9 [SLP]Improve reduction cost model for scalars.
Instead of abstract cost of the scalar reduction ops, try to use the
cost of actual reduction operation instructions, where possible. Also,
remove the estimation of the vectorized GEPs pointers for reduced loads,
since it is already handled in the tree.

Differential Revision: https://reviews.llvm.org/D148036
2023-04-12 11:32:51 -07:00
Alexey Bataev
d00158cd28 [SLP][NFC]Introduce ShuffleCostEstimator and adjustExtracts member function.
Added ShuffleCostEstimator class and the first adjustExtracts member,
which is just a copy of previous AdjustExtractCost lambda.

Differential Revision: https://reviews.llvm.org/D147787
2023-04-11 12:47:07 -07:00