2343 Commits

Author SHA1 Message Date
Mikhail Gudim
e485d5e77a
[SLPVectorizer] Clear TreeEntryToStridedPtrInfoMap. (#160544)
We need to clear `TreeEntryToStridedPtrInfoMap` in `deleteTree`.
2025-09-30 09:25:32 -04:00
Alexey Bataev
1f82553e38 [SLP]Fix mixing xor instructions in the same opcode analysis
Xor with 0 operand should not be compatible with multiplications-based
instructions, only with or/xor/add/sub.

Fixes #161140
2025-09-29 11:14:06 -07:00
Alexey Bataev
57947ace14 [SLP]Correctly set the insert point for insertlements with copyable arguments
Need to find the last insertelement instruction in the list for the
copyable arguments, otherwise wrong def-use chain may be built

Fixes #160671
2025-09-25 15:09:23 -07:00
Mikhail Gudim
8bbd95a188
[SLPVectorizer] Move size checks (NFC) (#159361)
Move size checks inside `isStridedLoad`. In the future we plan to
possibly change the size and type of strided load there.
2025-09-23 13:15:05 -04:00
Alexey Bataev
8c41859a21 [SLP]Clear the operands deps of non-schedulable nodes, if previously all operands were copyable
If all operands of the non-schedulable nodes were previously only
copyables, need to clear the dependencies of the original schedule data
for such copyable operands and recalculate them to correctly handle
  number of dependecies.

Fixes #159406
2025-09-18 12:11:33 -07:00
Ramkumar Ramachandra
7fb3a91418
[PatternMatch] Introduce match functor (NFC) (#159386)
A common idiom is the usage of the PatternMatch match function within a
functional algorithm like all_of. Introduce a match functor to shorten
this idiom.

Co-authored-by: Luke Lau <luke@igalia.com>
2025-09-17 21:04:33 +01:00
Piotr Fusik
2ce04d0a41
[SLP][NFC] Refactor a long if into an early return (#156410) 2025-09-17 18:31:46 +02:00
Mikhail Gudim
66a8f47066
[SLPVectorizer][NFC] Save stride in a map. (#157706)
In order to avoid recalculating stride of strided load twice save it in
a map.
2025-09-16 09:02:09 -04:00
Alexey Bataev
f2301be0e8 [SLP]Add a check if the user itself is commutable
If the commutable instruction can be represented as a non-commutable
vector instruction (like add 0, %v can be represented as a part of sub
nodes with operation sub %v, 0), its operands might still be reordered
and this should be accounted when checking for copyables in operands

Fixes #158293
2025-09-15 12:50:03 -07:00
Mikhail Gudim
ee3a4f4c94
[SLPVectorizer] Test -1 stride loads. (#158358)
Add a test to generate -1 stride load and flags to force this behaviour.
2025-09-14 15:29:28 -04:00
Garth Lei
8a8a810506
[SLP][NFC] Remove unused local variable in lambda (#156835) 2025-09-11 02:05:55 +00:00
Alexey Bataev
0dddfab54c [SLP]Recalculate deps if the original instruction scheduled after being copyable
If the original instruction is going to be scheduled after same
instruction being scheduled as copyable, need to recalculate
dependencies. Otherwise, the dependencies maybe calculated incorrectly.
2025-09-10 10:18:45 -07:00
Alexey Bataev
d0ea176cce [SLP]Do not consider SExt/ZExt profitable for demotion, if the user is a bitcast to float
If the user node of the SExt/ZExt node is a bitcast to a float point
type, the node itself should not be considered legal to demote, since
still the casting is required to match the size of the float point type.

Fixes #157277
2025-09-08 07:59:01 -07:00
Alexey Bataev
fd93dc5ac5 [SLP]Correctly schedule standalone schedule data, which is part of tree entry
If a standalone schedule data relates to a vectorized instruction, still
need to schedule it as a part of pseudo-bundle to correctly handle
dependencies between its child nodes.
2025-09-07 17:08:37 -07:00
Alexey Bataev
c4d927ce09 Revert "[SLP]Correctly schedule standalone schedule data, which is part of tree entry"
This reverts commit 57cae2b6a275a8eb3bc8935973263ed84535fb81 to fix
a buildbot https://lab.llvm.org/buildbot/#/builders/169/builds/14776
2025-09-07 13:27:12 -07:00
Alexey Bataev
57cae2b6a2 [SLP]Correctly schedule standalone schedule data, which is part of tree entry
If a standalone schedule data relates to a vectorized instruction, still
need to schedule it as a part of pseudo-bundle to correctly handle
dependencies between its child nodes.
2025-09-07 10:54:40 -07:00
Alexey Bataev
9a3aedb093 [SLP]Do not try to schedule bundle with non-schedulable parent with commutable instructions
Commutable instruction can be reordering during tree building, and if
the parent node is not scheduled, its ScheduleData elements are
considered independent and compiler do not looks for reordered operands.
Need to cancel scheduling of copyables in this case.
2025-09-04 12:57:14 -07:00
Mikhail Gudim
fdace1ca45
[SLP][NFC]Extract SCEVExpander from calculateRtStride, NFC
Make `calculateRtStride` return the SCEV of rt stride value and let the
caller expand it where needed.
2025-09-03 09:27:16 -04:00
Alexey Bataev
005f0fa40e [SLP]Improved/fixed FMAD support in reductions
In the initial patch for FMAD, potential FMAD nodes were completely
excluded from the reduction analysis for the smaller patch. But it may
cause regressions.

This patch adds better detection of scalar FMAD reduction operations and
tries to correctly calculate the costs of the FMAD reduction operations
(also, excluding the costs of the scalar fmuls) and split reduction
operations, combined with regular FMADs.

Fixed the handling for reduced values with many uses.

Reviewers: RKSimon, gregbedwell, hiraditya

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/152787
2025-09-02 13:09:57 -07:00
Alexey Bataev
6d902b67cd Revert "[SLP]Improved/fixed FMAD support in reductions"
This reverts commit 74230ff2791384fb3285c9e9ab202056959aa095 to fix the
bugs found during local testing.
2025-09-02 07:58:29 -07:00
Alexey Bataev
74230ff279
[SLP]Improved/fixed FMAD support in reductions
In the initial patch for FMAD, potential FMAD nodes were completely
excluded from the reduction analysis for the smaller patch. But it may
cause regressions.

This patch adds better detection of scalar FMAD reduction operations and
tries to correctly calculate the costs of the FMAD reduction operations
(also, excluding the costs of the scalar fmuls) and split reduction
operations, combined with regular FMADs.

Reviewers: RKSimon, gregbedwell, hiraditya

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/152787
2025-09-01 17:01:36 -04:00
Alexey Bataev
a80a1988f7
[SLP]Better support for copyable values in stores
Currently stores are sorted by the stored values instruction types,
which do not include analysis for copyables. The compiler may miss some
potential vectorization opportunities because of that. Patch adds
detection of the copyables in stored values.

Reviewers: hiraditya, HanKuanChen, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/153213
2025-09-01 16:09:52 -04:00
Piotr Fusik
3fd6828639
[SLP][NFC] Refactor duplicate code into getVectorizedValue (#156277) 2025-09-01 18:00:02 +02:00
Piotr Fusik
6aeea122c5
[SLP][NFC] Simplify population of ReducedVals (#156292) 2025-09-01 16:38:13 +02:00
Piotr Fusik
e82abde494
[SLP][NFC] Refactor ifs into && (#156278) 2025-09-01 09:45:25 +02:00
Alexey Bataev
7730ebce8e [SLP]Do not to try to revectorize previously vectorized phis in loops
No need to try to revectorize previously vectorized phis in loops, it leads to
a compile time blow-up.

Fixes #155998
2025-08-31 10:54:20 -07:00
Alexey Bataev
e5a4ea20c5 [SLP]Do not remove reduced value, if it is a copyable
If the value is checked for the reduction and it is a copyable element
in a root node, it should not be deleted, since it may still be used
after vectorization.

Fixes #155512
2025-08-31 09:09:39 -07:00
Alexey Bataev
eb39605192 [SLP]Do not schedule terminate copyable from main op basic block
If the copyable instruction is a terminate instruction from the same
block, as the potential main instruction, such instruction cannot be
copyable and the value list cannot be modeled as instructions with same
(and copyables) opcodes.

Fixes #155183
2025-08-30 18:05:08 -07:00
Alexey Bataev
2824b3c00e [SLP] Try to recalculate deps only for nodes with previously valid deps
Need to recalculate the dependencies only for nodes, which have valid
deps before they gets cleared because of the copyable nodes. Otherwise,
no need to recaculate the dependencies to prevent a crash.
2025-08-30 14:20:50 -07:00
Piotr Fusik
c825c8a052
[SLP][NFC] Simplify insert(std::make_pair(K, V)) -> try_emplace(K, V) (#155233)
These are equivalent as `MapVector::insert` simply calls
`MapVector::try_emplace`.

BTW, correct a comment typo.
2025-08-26 06:28:06 +02:00
Kazu Hirata
07eb7b7692
[llvm] Replace SmallSet with SmallPtrSet (NFC) (#154068)
This patch replaces SmallSet<T *, N> with SmallPtrSet<T *, N>.  Note
that SmallSet.h "redirects" SmallSet to SmallPtrSet for pointer
element types:

  template <typename PointeeType, unsigned N>
class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N>
{};

We only have 140 instances that rely on this "redirection", with the
vast majority of them under llvm/. Since relying on the redirection
doesn't improve readability, this patch replaces SmallSet with
SmallPtrSet for pointer element types.
2025-08-18 07:01:29 -07:00
Alexey Bataev
b157599156 [SLP]Do not include copyable data to the same user twice
If the copyable schedule data is created and the user is used several
times in the user node, no need to count same data for the same user
several times, need to include it only ones.

Fixes #153754
2025-08-15 12:36:45 -07:00
Alexey Bataev
09f5b9ab0a Revert "[SLP]Do not include copyable data to the same user twice"
This reverts commit 758c6852c3ffe6b5e259cafadd811e60d8c276fb to fix
buildbot  https://lab.llvm.org/buildbot/#/builders/195/builds/13298
2025-08-15 12:08:31 -07:00
Alexey Bataev
758c6852c3 [SLP]Do not include copyable data to the same user twice
If the copyable schedule data is created and the user is used several
times in the user node, no need to count same data for the same user
several times, need to include it only ones.

Fixes #153754
2025-08-15 11:47:35 -07:00
Alexey Bataev
13b54f7dc1 [SLP] Recalculate dependencies for potential control dependencies if cleared
If the control dependecies are cleared after calcellation of the
copyables, need to reclculate them unconditionally.

Fixes #153754 #153676
2025-08-15 07:52:10 -07:00
Alexey Bataev
bf2f241458 [SLP]Support LShr as base for copyable elements
Added support for LShr instructions as base for copyable elements. Also,
added simple analysis for best base instruction selection, if multiple
candidates are available.

Fixed scheduling after cancellation

Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/153393
2025-08-14 19:12:27 -07:00
Alex Bradbury
db5f7dc374 Revert "[SLP]Support LShr as base for copyable elements"
This reverts commit ca4ebf95172d24f8c47655709b2c9eb85bda5cb2.

Causes compile-time crashes for some inputs with RVV zvl512b/zvl1024b
configurations. See here for a minimal reproducer:
https://github.com/llvm/llvm-project/pull/153393#issuecomment-3189898813
2025-08-14 22:18:24 +01:00
Alexey Bataev
ca4ebf9517
[SLP]Support LShr as base for copyable elements
Added support for LShr instructions as base for copyable elements. Also,
added simple analysis for best base instruction selection, if multiple
candidates are available.

Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/153393
2025-08-14 12:35:28 -04:00
Alexey Bataev
d57ab276b6 [SLP] Recalculate cleared deps for potential control schedule data nodes
Need to recalculate the dependencies for all potential control data
schedule nodes to prevent compiler crash.

Fixes #153571
2025-08-14 09:00:42 -07:00
Kazu Hirata
1f04b15c56
[Vectorize] Remove a redundant call to std::unique_ptr<T>::get (NFC) (#153359) 2025-08-13 10:37:31 -07:00
Alexey Bataev
dd5ba694bd [SLP]Recalculate deps for potential control-dependent schedule data
After clearing the dependencies in copyable data, need to recalculate
dependencies for the original ScheduleData, if it can be marked as
control dependent.

Fixes #153289
2025-08-13 08:18:26 -07:00
Sam Tebbs
0bfa1718af
[LV] Create in-loop sub reductions (#147026)
This PR allows the loop vectorizer to handle in-loop sub reductions by
forming a normal in-loop add reduction with a negated input.

Stacked PRs:
1. -> https://github.com/llvm/llvm-project/pull/147026
2. https://github.com/llvm/llvm-project/pull/147255
3. https://github.com/llvm/llvm-project/pull/147302
4. https://github.com/llvm/llvm-project/pull/147513
2025-08-12 10:22:41 +01:00
Alexey Bataev
2d7b55a028
[SLP]Initial support for copyable elements
Adds initial support for copyable elements, both schedulable and
non-schedulable.
Adds support only for add for now, other opcodes will added in future.
Still some cases are not handled, e.g. stores do not include this,
because currently do not check for copyable elements.

Reviewers: hiraditya, RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/147366
2025-08-11 09:41:19 -04:00
Alexey Bataev
67af2f6c5c [SLP]Initial FMAD support (#149102)
Added initial check for potential fmad conversion in reductions and
operands vectorization.

Added the check for instruction to fix #152683

Skipped the code for reduction to avoid regressions.
2025-08-11 05:53:55 -07:00
David Green
cfe190979e Revert "[SLP]Initial FMAD support (#149102)"
This reverts commit 0fffb9f9ed81f4c2084b8fe040c88b60bb6c372a due to major
performance regressions.
2025-08-10 15:16:01 +01:00
Alexey Bataev
0fffb9f9ed [SLP]Initial FMAD support (#149102)
Added initial check for potential fmad conversion in reductions and
operands vectorization.

Added the check for instruction to fix #152683
2025-08-08 10:30:23 -07:00
Alexey Bataev
0419b459be Revert "[SLP]Initial FMAD support (#149102)"
This reverts commit 0bcf45ea3458ba79eb4257afcfd6af954292c9ce to fix the
regresions, reported in https://github.com/llvm/llvm-project/issues/152683
2025-08-08 09:17:59 -07:00
Alexey Bataev
0bcf45ea34
[SLP]Initial FMAD support (#149102)
Added initial check for potential fmad conversion in reductions and
operands vectorization.
2025-08-07 09:51:43 -04:00
Alexey Bataev
4784ce9ebc [SLP][NFC]Check an external user before trying to address it in debug dump, NFC 2025-08-06 08:58:16 -07:00
Alexey Bataev
e27831ff9b [SLP] Fix a check for main/alternate interchanged instruction
If the instruction is checked for matching the main instruction, need to
check if the opcode of the main instruction is compatible with the
operands of the instruction. If they are not, need to check the
alternate instruction and its operands for compatibility and return
alternate instruction as a match.

Fixes #151699

Fixed check for non-supported binary operations.
2025-08-04 11:20:54 -07:00