4708 Commits

Author SHA1 Message Date
Ramkumar Ramachandra
199d6f2c0c
LSV: document hang reported in #37865 (#102479)
LoadStoreVectorizer hangs on certain examples, when its reorder function
goes into a cycle. Detect this cycle and explicitly forbid it, using an
assert, and document the resulting crash in a test-case under AArch64.
2024-08-09 11:34:09 +01:00
Alexey Bataev
2a05971de2 [SLP]Add index of the node to the short name output.
Improves debugging experience, does nothing with the functionality.
2024-08-08 08:57:14 -07:00
Han-Kuan Chen
7a4fc7491c
[SLP][REVEC] Fix insertelement has multiple uses. (#102329) 2024-08-08 23:23:10 +08:00
Jeremy Morse
fd7d7882e7
[DebugInfo][RemoveDIs] Use iterators to insert everywhere (#102003)
These are the final few places in LLVM where we use instruction pointers
to identify the position that we're inserting something. We're trying to
get away from that with a view to deprecating those methods, thus use
iterators in all these places. I believe they're all debug-info safe.

The sketchiest part is the ExtractValueInst copy constructor, where we
cast nullptr to a BasicBlock pointer, so that we take the non-default
insert-into-no-block path for instruction insertion, instead of the
default nullptr-instruction path for UnaryInstruction. Such a hack is
necessary until we get rid of the instruction constructor entirely.
2024-08-08 14:25:06 +01:00
Alexey Bataev
7e7a439705
[SLP][NFC]Introduce CombinedVectorize nodes, NFC. (#99309)
This adds combined vectorized node. It simplifies handling of the
combined nodes, like select/cmp, which can be reduced to min/max,
mul/add transformed to fma, etc. Improves cost mode handling and may end
up with better codegen in future (direct emission of the intrinsics).
2024-08-08 08:05:33 -04:00
Han-Kuan Chen
60ac34701e
[SLP][REVEC] Make getAltInstrMask and getGatherCost vectorize vector instructions. (#99461) 2024-08-08 10:39:01 +08:00
John McIver
bb82c79d3b
[SLP] Enable optimization of freeze instructions (#102217)
Allow SLP optimization to progress in the presence of freeze
instructions. Prior
to this commit, freeze instructions blocked SLP optimization.
    
The following URL shows correctness of the addsub_freeze test:
https://alive2.llvm.org/ce/z/qm38oh
2024-08-07 15:01:37 -04:00
Han-Kuan Chen
97743b8be8
[SLP][REVEC] Make ShuffleCostEstimator and ShuffleInstructionBuilder support vector instructions. (#99499)
1. When REVEC is enabled, we need to expand vector types into scalar
types.
2. When REVEC is enabled, CreateInsertVector (and CreateExtractVector)
is used because the scalar type may be a FixedVectorType.
3. Since the mask indices which are used by processBuildVector expect
the source is scalar type, we need to transform the mask indices into a
form which can be used when REVEC is enabled. The transform is only
called when the mask is really used.
2024-08-07 23:47:57 +08:00
Alexey Bataev
441f94f4bd [SLP]Fix PR102279: check the tracked values for extractelements, not the original values
If the reduced value was replaced by the extractelement instruction
during vectorization and we attempt to check if this is so, need to
check the tracked value, not the original (deleted) instruction.
Otherwise, the compiler may crash

Fixes https://github.com/llvm/llvm-project/issues/102279
2024-08-07 04:21:24 -07:00
tcwzxx
b64ec3c9fa
[SLP] The order of store chains needs to consider the size of the values. (#101810)
When store chains have the same value type ID and pointer type ID, they
may mix different sizes of values, such as i8 and i64. This can lead to
missed vectorization opportunities.
2024-08-07 11:01:53 +08:00
Alexey Bataev
af80d3a248
[SLP]Better sorting of phi instructions by comparing type sizes (#102188)
Currently SLP vectorizer compares phi instructions by the type id of the
compared instructions, which may failed in case of different integer
types,
with the different sizes. Patch adds comparison by type sizes to fix
this.
2024-08-06 16:09:11 -04:00
Alexey Bataev
2601d6f189 [SLP]Fix PR102187: do not insert extractelement before landingpad instruction.
Landingpad instruction must be the very first instruction after the phi
nodes, so need to inser extractelement/shuffles after this instruction.

Fixes https://github.com/llvm/llvm-project/issues/102187
2024-08-06 12:33:13 -07:00
Alexey Bataev
3c3ea7e751
[SLP]Better sorting of cmp instructions by comparing type sizes.
Currently SLP vectorizer compares cmp instructions by the type id of the
compared operands, which may failed in case of different integer types,
for example, which have same type id, but different sizes. Patch adds
  comparison by type sizes to fix this.

Reviewers: RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/102132
2024-08-06 11:03:36 -04:00
Alexey Bataev
daf4a06e5c
[SLP]Try detect strided loads, if any pointer op require extraction.
If any pointer operand of the non-cosencutive loads is an instructions
with the user, which is not part of the current graph, and, thus,
requires emission of the extractelement instruction, better to try to
detect if the load sequence can be repsented as strided load and
extractelement instructions for pointers are not required.

Reviewers: preames, RKSimon, topperc

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/101668
2024-08-06 09:20:50 -04:00
Florian Hahn
241349fff2
[VPlan] Move VPWidenPointerInductionR::execute to VPlanRecipes. (NFC)
Move VPWidenPointerInductionRecipe::execute to VPlanRecipes.cpp in line
with other ::execute implementations that don't depend on anything
defined in LoopVectorization.cpp
2024-08-05 20:42:10 +01:00
Alexey Bataev
badf34a063
[LV]Process alloca in isPredicatedInst for tail-folded analysis.
Patch fixes the compiler crash when it tries to check is alloca in the
loop is a predicated instruction.

Reviewers: fhahn

Reviewed By: fhahn

Pull Request: https://github.com/llvm/llvm-project/pull/101743
2024-08-05 14:04:54 -04:00
Alexey Bataev
799fd3d87b
[SLP]Support vectorization of small strided loads only graph.
If the graph includes only strided loads node, the compiler should still
try to vectorize it.

Reviewers: RKSimon, preames, topperc

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/101659
2024-08-05 12:51:10 -04:00
Florian Hahn
fdb9f96fa2
[LV] Consider earlier stores to invariant reduction address as dead.
For invariant stores to an address of a reduction, only the latest store
will be generated outside the loop. Consider earlier stores as dead.

This fixes a difference between the legacy and VPlan-based cost model.

Fixes https://github.com/llvm/llvm-project/issues/96294.
2024-08-04 20:54:26 +01:00
Kazu Hirata
e525f91640
[llvm] Use llvm::is_contained (NFC) (#101855) 2024-08-04 11:42:48 -07:00
Kazu Hirata
b7146aed5b
[Transforms] Construct SmallVector with ArrayRef (NFC) (#101851) 2024-08-03 15:33:08 -07:00
Florian Hahn
edf46f365c
[SCEV] Use const SCEV * explicitly in more places.
Use const SCEV * explicitly in more places to prepare for
https://github.com/llvm/llvm-project/pull/91961. Split off as suggested.
2024-08-03 20:10:01 +01:00
Mel Chen
e3d9b01a36
[VPlan][NFC] Make VPValue pointer const. (#101334) 2024-08-02 09:34:25 +08:00
Han-Kuan Chen
b5a7d3b6c2
[SLP][REVEC] Make Instruction::Select support vector instructions. (#100507) 2024-07-31 23:03:50 +08:00
Alexey Bataev
6b1d13761a [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value.
When trying to reuse extractelement instruction, need to check that it
is inserted into proper position. Its original vector operand should
come before new vector value, otherwise new extractelement instruction
must be generated.

Fixes https://github.com/llvm/llvm-project/issues/101213
2024-07-30 16:02:46 -07:00
Alexey Bataev
a6ef0864e9 Revert "[SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value."
This reverts commit f70f1228035c9610de38e0e376afdacb647c4ad9 to fix the
crash reported by https://lab.llvm.org/buildbot/#/builders/133/builds/2456.
2024-07-30 15:11:35 -07:00
David Green
89b67a6400
[SLP] Cluster SortedBases before sorting. (#101144)
In order to enforce a strict-weak ordering, this patch clusters the
bases that are being sorted by the root - the first value in a gep
chain. The sorting is then performed in each cluster.
2024-07-30 22:12:20 +01:00
Alexey Bataev
f70f122803 [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value.
When trying to reuse extractelement instruction, need to check that it
is inserted into proper position. Its original vector operand should
come before new vector value, otherwise new extractelement instruction
must be generated.

Fixes https://github.com/llvm/llvm-project/issues/101213
2024-07-30 14:04:50 -07:00
Alexey Bataev
197f4a9051
[SLP]Remove ExtraArgs from reductions.
No need to handle extra arguments during the reductions anymore, the
compiler now can handle all reduced values and reduction operands
correctly, even if they are from different basic blocks.

Simplifies analysis, reduces compiler size, improves overall
vectorization.

Metric: size..text
test-suite :: SingleSource/Benchmarks/Misc-C++/stepanov_container.test    16668.00    17148.00  2.9%
test-suite :: External/SPEC/CINT2006/483.xalancbmk/483.xalancbmk.test  2389675.00  2418683.00  1.2%
test-suite :: MultiSource/Benchmarks/ASCI_Purple/SMG2000/smg2000.test   253517.00   253645.00  0.1%
test-suite :: MultiSource/Benchmarks/Bullet/bullet.test   309678.00   309806.00  0.0%
test-suite :: MultiSource/Applications/JM/ldecod/ldecod.test   389203.00   389363.00  0.0%
test-suite :: MultiSource/Benchmarks/MiBench/consumer-jpeg/consumer-jpeg.test   111120.00   111152.00  0.0%
test-suite :: MultiSource/Benchmarks/tramp3d-v4/tramp3d-v4.test  1039103.00  1039215.00  0.0%
test-suite :: External/SPEC/CFP2017rate/511.povray_r/511.povray_r.test  1155883.00  1155963.00  0.0%
test-suite :: MicroBenchmarks/LoopVectorization/LoopInterleavingBenchmarks.test   276646.00   276662.00  0.0%
test-suite :: MultiSource/Applications/JM/lencod/lencod.test   848691.00   848739.00  0.0%
test-suite :: External/SPEC/CFP2006/453.povray/453.povray.test  1138604.00  1138636.00  0.0%
test-suite :: External/SPEC/CINT2006/445.gobmk/445.gobmk.test   910201.00   910217.00  0.0%
test-suite :: External/SPEC/CFP2017rate/526.blender_r/526.blender_r.test 12385484.00 12385628.00  0.0%
test-suite :: External/SPEC/CINT2017speed/602.gcc_s/602.gcc_s.test  9667580.00  9667676.00  0.0%
test-suite :: External/SPEC/CINT2017rate/502.gcc_r/502.gcc_r.test  9667580.00  9667676.00  0.0%
test-suite :: External/SPEC/CINT2017rate/523.xalancbmk_r/523.xalancbmk_r.test  2856182.00  2856198.00  0.0%
test-suite :: External/SPEC/CINT2017speed/623.xalancbmk_s/623.xalancbmk_s.test  2856182.00  2856198.00  0.0%
test-suite :: External/SPEC/CINT2006/464.h264ref/464.h264ref.test   773224.00   773192.00 -0.0%
test-suite :: MultiSource/Benchmarks/7zip/7zip-benchmark.test  1035148.00  1035084.00 -0.0%
test-suite :: External/SPEC/CINT2017speed/631.deepsjeng_s/631.deepsjeng_s.test    98126.00    98094.00 -0.0%
test-suite :: External/SPEC/CINT2017rate/531.deepsjeng_r/531.deepsjeng_r.test    97966.00    97934.00 -0.0%
test-suite :: MultiSource/Benchmarks/MallocBench/gs/gs.test   167391.00   167215.00 -0.1%
test-suite :: MultiSource/Applications/ALAC/encode/alacconvert-encode.test    56685.00    56605.00 -0.1%
test-suite :: MultiSource/Applications/ALAC/decode/alacconvert-decode.test    56685.00    56605.00 -0.1%
test-suite :: SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20050826-2.test     1302.00     1294.00 -0.6%

Misc-C++/stepanov_container - better code due to cost fixes.
483.xalancbmk - better code due to cost fixes.
ASCI_Purple/SMG2000 - better code due to cost fixes.
Benchmarks/Bullet - better vector code because of the cost.
JM/ldecod - extra code remain scalar, extra reduction vectorized
consumer-jpeg - extra code remain scalar because of the cost.
tramp3d-v4 - better vectorization because of cost fixes.
511.povray_r - better vectorization because of cost fixes.
LoopInterleavingBenchmarks - extra reductions are vectorized
JM/lencod - small changes in vector code because of extract cost fixes.
453.povray - small changes in vector code because of extract cost fixes.
445.gobmk - extra small reduction vectorized
526.blender_r - extra reduced scalars, better small reduction, small
changes in the vetorization because of the fixes for extracts cost
602.gcc_s
502.gcc_r - small changes in reductions vectorization because of the
fixes in the extract cost.
631.deepsjeng_s
623.xalancbmk_s - small changes in reductions vectorization because of
the fixes in the extract cost.
MallocBench/gs - extra code remain scalar because of extracts cost
alacconvert-encode - extra code remain scalar because of extracts cost
alacconvert-decode - extra code remain scalar because of extracts cost
GCC-C-execute-20050826-2 - extra reduction gets vectorized

Reviewers: RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/99923
2024-07-29 13:23:56 -04:00
Yingwei Zheng
62e9f40949
[PatternMatch] Use m_SpecificCmp matchers. NFC. (#100878)
Compile-time improvement:
http://llvm-compile-time-tracker.com/compare.php?from=13996378d81c8fa9a364aeaafd7382abbc1db83a&to=861ffa4ec5f7bde5a194a7715593a1b5359eb581&stat=instructions:u
baseline: 803eaf29267c6aae9162d1a83a4a2ae508b440d3
```
Top 5 improvements:
  stockfish/movegen.ll 2541620819 2538599412 -0.12%
  minetest/profiler.cpp.ll 431724935 431246500 -0.11%
  abc/luckySwap.c.ll 581173720 580581935 -0.10%
  abc/kitTruth.c.ll 2521936288 2519445570 -0.10%
  abc/extraUtilTruth.c.ll 1216674614 1215495502 -0.10%
Top 5 regressions:
  openssl/libcrypto-shlib-sm4.ll 1155054721 1155943201 +0.08%
  openssl/libcrypto-lib-sm4.ll 1155054838 1155943063 +0.08%
  spike/vsm4r_vv.ll 1296430080 1297039258 +0.05%
  spike/vsm4r_vs.ll 1312496906 1313093460 +0.05%
  nuttx/lib_rand48.c.ll 126201233 126246692 +0.04%
Overall: -0.02112308%
```
2024-07-29 10:04:06 +08:00
Florian Hahn
66ce4f771e
[VPlan] Port invalid cost remarks to VPlan. (#99322)
This patch moves the logic to create remarks for instructions with
invalid costs to work on recipes and decoupling it from
selectVectorizationFactor. This is needed to replace the remaining uses
of selectVectorizationFactor with getBestPlan using the VPlan-based cost
model.

The current implementation iterates over all VPlans and their recipes
again, to find recipes with invalid costs, which is more work but will
only be done when remarks for LV are enabled. Once the remaining uses of
selectVectorizationFactor are retired, we can collect VPlans with
invalid costs as part of getBestPlan if we want to optimize the remarks
case a bit, at the cost of adding additional complexity.

PR: https://github.com/llvm/llvm-project/pull/99322
2024-07-27 12:52:12 +01:00
David Green
f2d2ae3f5a
[SLP] Order clustered load base pointers by ascending offsets (#100653)
This attempts to fix a regression from #98025, where the new order of
reduction nodes causes later passes to not be able to produce as nice
shuffles. The issue boils down to picking an order of [0 1 3 2] for
loaded v4i8 values, which meant later parts could not find a simpler
ordering for the shuffles given the legal nodes available in AArch64. If
instead we make sure they are ordered [0 1 2 3] then everything can fall
into place.

In order to produce a better order that is more likely to work in more
cases, this patch takes the existing clustered loads and sort the base
pointers if there is an order between them. i.e if `V2 == gep (V1, X)`
then V1 is sorted before V2.
2024-07-27 11:18:56 +01:00
Florian Hahn
5a9b9ef660
[VPlan] Remove now redundant VF assertion.
The assertion was added in preparation for
https://github.com/llvm/llvm-project/pull/9882. Remove assertion now
the PR has landed.
2024-07-26 21:25:33 +01:00
Alexey Bataev
1e1c8d1615
[SLP]Add external uses cost for the gathered loads.
If the load is a part of the gather node and also a part of the
vectorized subvector, need to add the estimation for the non-vectorized
external uses.

Reviewers: RKSimon

Reviewed By: RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/99889
2024-07-26 11:09:44 -04:00
Florian Hahn
67a55e01e3
[VPlan] Replace getBestPlan by getBestVF use also for epilogue vec. (#98821)
Replace getBestPlan by getBestVF which simply finds the best
VF out of the VFs for the available VPlans.

Then use getBestPlan to retrieve the corresponding VPlan.

This allows using getBestVF & getBestPlan for epilogue vectorization
as well. As the same plan may be used to vectorize both the main
and epilogue loop, restricting the VF of the best plan would cause
issues.

PR: https://github.com/llvm/llvm-project/pull/98821
2024-07-26 14:06:46 +01:00
Florian Hahn
8b02f31aea
[VPlan] Consistently use VF.Width to getting plan for main loop VF (NFC)
Cleanup to make things consistent in preparation for
https://github.com/llvm/llvm-project/pull/98821.
2024-07-26 11:16:45 +01:00
Mel Chen
3834523f77
[LV][EVL] Refine the constructors of EVL recipe to use call by reference. NFC (#100088) 2024-07-26 16:50:21 +08:00
Florian Hahn
a3092152ac
[VPlan] Don't create live-outs for induction increments.
Follow up to fc9cd3272b5 to also skip creating live-outs for IV
increments, as those are also generated independent of VPlan for now.
2024-07-25 21:34:55 +01:00
Florian Hahn
72532c9219
[LV] Don't predicate divs with invariant divisor when folding tail (#98904)
When folding the tail, at least one of the lanes must execute
unconditionally. If the divisor is loop-invariant no predication is
needed, as predication would not prevent the divide-by-0 on the executed
lane.

Depends on https://github.com/llvm/llvm-project/pull/98892.

PR: https://github.com/llvm/llvm-project/pull/98904
2024-07-25 12:21:09 +01:00
Florian Hahn
b72689a5cb
[LV] Ignore live-out users in cost model if scalar epilogue is required.
Follow-up to ba8126b6fef79.

If a scalar epilogue is required, users outside the loop won't use
live-outs from the vector loop but from the scalar epilogue. Ignore them if
that is the case.

This fixes another case where the VPlan-based cost-model more accurately
computes cost.

Fixes https://github.com/llvm/llvm-project/issues/100464.
2024-07-25 11:16:18 +01:00
Ramkumar Ramachandra
e1a3aa8c0f
LV/Legality: fix style after cursory reading (NFC) (#100363) 2024-07-24 16:32:24 +01:00
Florian Hahn
07688d1341
Revert "[LV] Add option to still enable the legacy cost model. (#99536)"
This reverts commit 9ba524427321b931bad156860755adf420aeec6a.

Remove the recently added temporary option vectorize-use-legacy-cost-model
as discussed on the PR adding it, now that we branched for 19.x.
2024-07-24 14:32:36 +01:00
Florian Hahn
ba8126b6fe
[LV] Mark dead instructions in loop as free.
Update collectValuesToIgnore to also ignore dead instructions in the
loop. Such instructions will be removed by VPlan-based DCE and won't be
considered by the VPlan-based cost model.

This closes a gap between the legacy and VPlan-based cost model. In
practice with the default pipelines, there shouldn't be any dead
instructions in loops reaching LoopVectorize, but it is easy to generate
such cases by hand or automatically via fuzzers.

Fixes https://github.com/llvm/llvm-project/issues/99701.
2024-07-24 09:31:32 +01:00
Florian Hahn
bb60dd391f
[VPlan] Only use force-target-instruction-cost for recipes with insts.
To match the behavior of the legacy cost model, only apply
-force-target-instruction-cost to recipes with underlying instructions
for now, as only original IR instructions are considered by the legacy
cost model.

This fixes a difference between legacy and VPlan based cost model,
triggering the verification assertion, reported by @JonPsson1.
2024-07-23 21:05:10 +01:00
Han-Kuan Chen
5fc9502f19
[SLP] NFC. ShuffleInstructionBuilder::add V1->getType() is always a FixedVectorType. (#99842)
castToScalarTyElem has a cast<VectorType>(V->getType()).
2024-07-24 01:40:24 +08:00
Florian Hahn
d89f3e8df3
[VPlan] Remove dead HeaderVPBB argument from addUsersInExitBlock (NFC). 2024-07-23 11:36:43 +01:00
Alexey Bataev
3cb82f49dc [SLP]Fix PR99899: Use canonical type instead of original vector of ptr.
Use adjusted canonical integer type instead of the original ptr type to
fix the crash in the TTI.
Fixes https://github.com/llvm/llvm-project/issues/99899
2024-07-22 13:05:12 -07:00
Florian Hahn
e6fdecd290
[VPlan] Drop references to Ingredient from VPWidenRecipe comments (NFC)
VPWidenRecipe has been updated to use Opcode + operands instead of an
Instruction 'ingredient'. Reword the comments.
2024-07-22 20:33:13 +01:00
Kazu Hirata
5c83498984
[Transforms] Use range-based for loops (NFC) (#99607) 2024-07-21 13:11:25 -07:00
Florian Hahn
a23efcc703
[VPlan] Move VPInterleaveRecipe::execute to VPlanRecipes.cpp (NFC).
Move ::exeute and ::print to VPlanRecipes.cpp in line with other recipe
definitions.
2024-07-20 22:23:02 +01:00
Florian Hahn
1f00c42446
[VPlan] Assert masked interleave accesses are allowed if needed (NFC)
Add assertion at interleave group construction.
2024-07-20 21:42:38 +01:00