2220 Commits

Author SHA1 Message Date
Florian Hahn
ec1016f7ef
[IVDescriptors] Support reductions with minimumnum/maximumnum. (#137335)
Add a new reduction recurrence kind for reductions with
minimumnum/maximumnum. Such reductions can be vectorized without
nsz/nnans, same as reductions with maximum/minimum intrinsics.

Note that a new reduction kind is needed to make sure partial reductions
are also combined with minimumnum/maximumnum.

Note that the final reduction to a scalar value is performed with
vector.reduce.fmin/fmax. This should be fine, as the results of the
partial reductions with maximumnum/minimumnum silences any sNaNs.

In-loop and reductions in SLP are not supported yet, as there's no
reduction version of maximumnum/minimumnum yet and fmax may be
incorrect.

PR: https://github.com/llvm/llvm-project/pull/137335
2025-04-28 11:16:36 +01:00
Kazu Hirata
5cfd81b0cc
[llvm] Use range constructors of *Set (NFC) (#137552) 2025-04-27 15:59:57 -07:00
Matt Arsenault
4ea2278e39
SLPVectorizer: Use use_empty instead of hasNUses(0) (#137336) 2025-04-25 17:27:01 +02:00
Alexey Bataev
a7a74b349d
[SLP]Improve reordering of the alternate nodes
Better to preserve the original order of the alternate nodes to avoid
inter-lane shuffling, select/insert subvector patterns provide better
perf.

Reviewers: RKSimon, hiraditya

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/136329
2025-04-24 14:33:10 -04:00
Alexey Bataev
f427890a1d [SLP]Fix PHI comparator to make it follow weak strict ordering restriction
Fixes #137164
2025-04-24 11:08:17 -07:00
Alexey Bataev
f52b01b6cf [SLP][NFC]Rename functions/variables, limit visibility to meet the coding standards, NFC 2025-04-22 09:56:31 -07:00
Alexey Bataev
9c388f1f05
[SLP]Prefer segmented/deinterleaved loads to strided and fix codegen
Need to estimate, which one is preferable, deinterleaved/segmented
loads or strided. Segmented loads can be combined, improving
the overall performance.

Reviewers: RKSimon, hiraditya

Reviewed By: hiraditya, RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/135058
2025-04-22 12:11:01 -04:00
Alexey Bataev
0252d338fa
[SLP]Model single unique value insert + shuffle as splat + select, where profitable
When we have the remaining unique scalar, that should be inserted into
non-poison vector and into non-zero position:
```
%vec1 = insertelement %vec, %v, pos1
%res = shuffle %vec1, poison, <0, 1, 2,..., pos1, pos1 + 1, ..., pos1,
...>
```
better to estimate if it is profitable to model it as is or model it as:
```
%bv = insertelement poison, %v, 0
%splat = shuffle %bv, poison, <poison, ..., 0, ..., 0, ...>
%res = shuffle %vec, %splat, <0, 1, 2,..., pos1 + VF, pos1 + 1, ...>
```

Reviewers: preames, hiraditya, RKSimon

Reviewed By: preames

Pull Request: https://github.com/llvm/llvm-project/pull/136590
2025-04-22 11:30:29 -04:00
David Green
d20604e5b6
[CostModel] Plumb CostKind into getExtractWithExtendCost (#135523)
This will likely not affect much with the current uses of the function,
but if we have getExtractWithExtendCost we can plumb CostKind through it
in the same way as other costmodel functions.
2025-04-22 15:09:43 +01:00
Kazu Hirata
b01e25deba
[llvm] Call hash_combine_range with ranges (NFC) (#136511) 2025-04-20 16:36:03 -07:00
Matt Arsenault
e2886705f0
SLPVectorizer: Use use_empty instead of getNumUses (#136336) 2025-04-18 21:14:06 +02:00
Alexey Bataev
fdcee2dd36
[SLP]Reorder tree, if the reorder indices are non empty
Need to consider the ordering for all nodes with the specified ordering,
not only loads/store/extracts.

Reviewers: hiraditya, RKSimon

Reviewed By: hiraditya

Pull Request: https://github.com/llvm/llvm-project/pull/136185
2025-04-18 13:37:08 -04:00
Kazu Hirata
5e1b0f9773
[llvm] Use llvm::less_first and llvm::less_second (NFC) (#136272) 2025-04-18 10:05:55 -07:00
Alexander Kornienko
85110ccee9
[SLP] Replace most uses of for_each with range-for loops. NFC (#136146)
This removes a bit of complexity from the code, where it doesn't seem to
be justified.
2025-04-17 21:38:18 +02:00
Alexey Bataev
5fe91f1b59 [SLP]Check for catchswitch block before doing the analysis of the instructions
Need to skip the analysis of the catchswitch blocks to avoid a compiler
crash when trying to get the first instruction in the block.
2025-04-17 09:10:15 -07:00
Alexey Bataev
1fcf78d153 [SLP]Cache data for compressed loads before codegen
Need to cache and use cached data for compressed loads before codegen to
avoid side-effects, caused by the earlier vectorization, which may
affect the analysis.
2025-04-17 08:43:44 -07:00
Gaëtan Bossu
2ee7fc0456
[SLP] More OOP to simplify vectorizeStores() (NFC) (#134605)
This moves more code into the RelatedStoreInsts helper class. The
FillStoresSet lambda is now only a couple of lines and is easier to
read.
2025-04-17 10:02:53 +01:00
Alexey Bataev
4aca20c8b6 [SLP]Pre-cache the last instruction for all entries before vectorization
Need to pre-cache last instruction to avoid unexpected changes in the
last instruction detection during the vectorization, caused by adding
the new vector instructions, which add new uses and may affect the
analysis.
2025-04-16 11:44:55 -07:00
Alexey Bataev
913dcf1aa3 [SLP]Fix type promotion for smax reduction with unsigned reduced operands
Need to add an extra bit for sign info for unsigned reduced values to
generate correct code.
2025-04-16 10:14:29 -07:00
Alexey Bataev
76b7ae7e45 [SLP][NFC]Remove std::placeholders:: qualifiers, NFC 2025-04-16 09:42:17 -07:00
Kazu Hirata
0045b82a42
[Vectorize] Construct SmallVector with an iterator range (NFC) (#135936) 2025-04-16 08:39:55 -07:00
Alexey Bataev
af28c9c65a [SLP]Do not reorder split node operand with reuses, if not possible
Need to check if the operand node of the split vectorize node has reuses
and check if it is possible to build the order for this node to reorder
it correctly.

Fixes #135912
2025-04-16 06:23:44 -07:00
Alexey Bataev
41c97afea0
[SLP][NFC]Remove handling of duplicates from getGatherCost
Duplicates are handled in BoUpSLP::processBuildVector (see TryPackScalars), support for duplicates in getGatherCost is not needed anymore.

Reviewers: hiraditya, RKSimon

Reviewed By: hiraditya, RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/135834
2025-04-16 06:53:10 -04:00
Alexey Bataev
ddb1267430 [SLP]Insert vector instruction after landingpad
If the node must be emitted in the landingpad block, need to insert the
instructions after the landingpad instruction to avoid a crash.

Fixes #135781
2025-04-15 13:57:53 -07:00
Alexey Bataev
85eb44e304 [SLP]Fix number of operands for the split node
FOr the split node number of operands should be requested via
getNumOperands() function, even if the main op is CallInst.
2025-04-15 13:33:36 -07:00
Alexey Bataev
2271f0bebd [SLP]Check for perfect/shuffled match for the split node
If the potential split node is a perfect/shuffled match of another split
node, need to skip creation of the another split node with the same
scalars, it should be a buildvector.

Fixes #135800
2025-04-15 13:17:46 -07:00
Han-Kuan Chen
d41e517748
[SLP] Make getSameOpcode support interchangeable instructions. (#135797)
We use the term "interchangeable instructions" to refer to different
operators that have the same meaning (e.g., `add x, 0` is equivalent to
`mul x, 1`).
Non-constant values are not supported, as they may incur high costs with
little benefit.

---------

Co-authored-by: Alexey Bataev <a.bataev@gmx.com>
2025-04-16 00:08:59 +08:00
Han-Kuan Chen
bcfc9f4529
[SLP][REVEC] VectorValuesAndScales should be supported by REVEC. (#135762)
We should align REVEC with the SLP algorithm as closely as possible. For
example, by applying REVEC-specific handling when calling IRBuilder's
Create methods, performing cost analysis via TTI, and expanding shuffle
masks using transformScalarShuffleIndicesToVector.

reference commit: 3b18d47ecbaba4e519ebf0d1bc134a404a56a9da
2025-04-15 23:03:55 +08:00
Alexey Bataev
57025b42c4 [SLP]Mark smin reduction as signed compare
Reduction signed min must be marked as signed compare, fixing the
analysis for the cases, where the incoming arguments are unsigned.

Fixes #133943
2025-04-15 07:24:17 -07:00
Han-Kuan Chen
e1382b3b45 Revert "[SLP] Make getSameOpcode support interchangeable instructions. (#133888)"
This reverts commit 123993fd974629ca0a094918db4c21ad1c2624d0.
2025-04-15 06:02:42 -07:00
Han-Kuan Chen
123993fd97
[SLP] Make getSameOpcode support interchangeable instructions. (#133888)
We use the term "interchangeable instructions" to refer to different
operators that have the same meaning (e.g., `add x, 0` is equivalent to
`mul x, 1`).
Non-constant values are not supported, as they may incur high costs with
little benefit.

---------

Co-authored-by: Alexey Bataev <a.bataev@gmx.com>
2025-04-14 19:23:18 +08:00
Alexey Bataev
38e64b1a84 [SLP]Fix minbiwidth analysis for gather nodes with SIToFP users
If the buildvector node has cast to float user, it cannot be considered as safe
for truncation, need to use the original bitwidth here.

Fixes #135410
2025-04-11 11:40:41 -07:00
Alexey Bataev
a2d129b792 [SLP]Fix a crash when trying to reduce in revec after minbitwidth analysis
Need to use the original scalar type, when building the reduction, and
use the scalar type, when performing casting, to avoid compiler crash.
2025-04-11 10:58:39 -07:00
Alexey Bataev
bd0b2bdacc [SLP][NFC]Use VF instead of VL.size and modernize some transformations, NFC. 2025-04-11 10:29:30 -07:00
Alexey Bataev
33af951f3f
[SLP]Synchronize cost of gather/buildvector nodes with codegen
If the buildvector node contains constants and non-constants, need to
consider shuffling of the constant vec and insertion of unique elements
into the vector. Also, if there is an input vector, need to consider the
cost of shuffling source vector and constant vector and then insertion
and shuffling of the non-constant elements.

Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/135245
2025-04-11 09:42:34 -04:00
Han-Kuan Chen
d77dc87511
[SLP][REVEC] Fix type comparison and mask transformation for REVEC. (#135310)
When REVEC is enabled, ScalarTy may be a FixedVectorType. Compare its
element type to decide if casting is needed. Also apply mask
transformation accordingly.
2025-04-11 17:28:34 +08:00
Alexey Bataev
61d04f1aac
[SLP][NFC]Extract preliminary checks from buildTree_rec, NFC
Moved check from buildTree_rec function to a separate
isLegalToVectorizeScalars function.

Reviewers: RKSimon, hiraditya

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/134132
2025-04-10 16:05:01 -04:00
Alexey Bataev
aaaa2a325b
[SLP]Support vectorization of previously vectorized scalars in split nodes
Patch removes the restriction for the revectorization of the previously
vectorized scalars in split nodes, and moves the cost profitability
check to avoid regressions.

Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/134286
2025-04-10 12:06:38 -04:00
Alexey Bataev
4ea57b3481 [SLP]Fix detection of matching splat vector
Need to check, that the mask of the potentially matching splat node is
not less defined than the requested mask to avoid poison propagation and
incorrect code.

Fixes #135113
2025-04-10 08:30:43 -07:00
Han-Kuan Chen
a693f23ef2
[SLP][REVEC] Fix CompressVectorize does not expand mask when REVEC is enabled. (#135174) 2025-04-10 23:07:45 +08:00
Han-Kuan Chen
d02a704ec9
[SLP][REVEC] Make getExtractWithExtendCost support FixedVectorType as Dst. (#134822) 2025-04-10 18:54:45 +08:00
Alexey Bataev
9dc6551fa8
[SLP][NFC]Extract a check for a SplitVectorize node, NFC
Reviewers: RKSimon, hiraditya

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/134896
2025-04-09 14:05:02 -04:00
Alexey Bataev
076318bd78 [SLP]Use proper order when calculating costs for geps/extracts to correctly identify profitability
Need to reorder properly the scalars, when evaluating the costs for the
external uses/geps to prevent differences in the calculating of the
profitability costs, used to choose between gather/compressed loads.

Fixes https://github.com/llvm/llvm-project/pull/132099#issuecomment-2789627454
2025-04-09 07:43:23 -07:00
Alexey Bataev
edcbd4a211
[SLP][NFC]Extract a check for strided loads into separate function, NFC
Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/134876
2025-04-08 13:02:31 -04:00
Alexey Bataev
02a708b93b
[SLP][NFC]Extract TryToFindDuplicates lambda into a separate function, NFC
Reviewers: RKSimon, hiraditya

Reviewed By: hiraditya, RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/134873
2025-04-08 13:01:54 -04:00
Han-Kuan Chen
2347aa1fcc
[SLP][REVEC] Fix the mismatch between the result of getAltInstrMask and the VecTy argument of TargetTransformInfo::isLegalAltInstr. (#134795)
We cannot determine ScalarTy from VL because some ScalarTy is determined
from VL[0]->getType(), while others are determined from
getValueType(VL[0]).

Fix "Mask and VecTy are incompatible".
2025-04-08 22:29:11 +08:00
Han-Kuan Chen
97c4cb4d13
[SLP][REVEC] getNumElements should not be used as VF when REVEC is enabled. (#134763) 2025-04-08 22:29:03 +08:00
Han-Kuan Chen
d7354e337a
[SLP][REVEC] Fix ShuffleVector does not consider alternate instruction. (#134599) 2025-04-08 08:04:43 +08:00
Alexey Bataev
f413772b31 [SLP]Fix last instruction selection for vectorized last instruction in SplitVectorize nodes
If the last instruction in the SplitVectorize node is vectorized and
scheduled as part of some bundles, the SplitVectorize node might be
placed in the wrong order, leading to a compiler crash. Need to check if
the vectorized node has vector value and place the SplitVectorize node after the vector instruction to prevent a compile crash.

Fixes issue reported in https://github.com/llvm/llvm-project/pull/133091#issuecomment-2782826805
2025-04-07 09:27:08 -07:00
Han-Kuan Chen
5748ddbab4
[SLP] NFC. Add a comment to introduce the alternate instruction. (#134572) 2025-04-07 18:03:26 +08:00