2004 Commits

Author SHA1 Message Date
Frederik Harwath
6ad41bcc49
[CodeGen] expand-fp: Change frem expansion criterion (#158285)
The existing condition for checking whether or not to expand an frem
instruction in expand-fp is not sufficiently precise.
The expansion on other targets than AMDGPU - which is the only intended
user right now - is only prevented due to the interaction with the
MaxLegalFpConvertBitWidth check.  Relying on this is conceptually wrong
and limits the use of the pass for other targets and further expansions
(e.g. merging with the similar ExpandLargeDivRem pass).

Change the expansion criterion to always expand frem of a given type
for targets that use "Expand" as the legalization action for the 
underlying scalar type and use this to exit the pass early for targets 
which do not require any expansions. This requires to change the
frem legalization action for all targets which do not want frem to 
be expanded in this pass from "Expand" to "LibCall".

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-12-16 17:31:26 +01:00
Philip Ginsbach-Chen
1d821b0c6b
[AArch64] use isTRNMask to calculate shuffle costs (#171524)
This builds on #169858 to fix the divergence in codegen
(https://godbolt.org/z/a9az3h6oq) between two very similar
functions initially observed in #137447 (represented in the diff by test
cases `@transpose_splat_constants` and `@transpose_constants_splat`:
```
int8x16_t f(int8_t x)
{
  return (int8x16_t) { x, 0, x, 1, x, 2, x, 3,
                       x, 4, x, 5, x, 6, x, 7 };
}

int8x16_t g(int8_t x)
{
  return (int8x16_t) { 0, x, 1, x, 2, x, 3, x,
                       4, x, 5, x, 6, x, 7, x };
}
```

The PR uses an additional `isTRNMask` call in
`AArch64TTIImpl::getShuffleCost` to ensure that we treat shuffle masks
as transpose masks even if `isTransposeMask` fails to recognise them
(meaning that `Kind == TTI::SK_Transpose` cannot be relied upon).

Follow-up work could consider modifying `isTransposeMask`, but that
would also impact other backends than AArch64.
2025-12-15 05:34:30 +00:00
Sam Tebbs
71c3acb18b
[Analysis][AArch64] Add cost model for loop.dependence.{war/raw}.mask (#167551)
This PR adds the cost model for the loop dependence mask intrinsics,
both for cases where they must be expanded and when they can be lowered
for AArch64.

---------

Co-authored-by: Benjamin Maxwell <benjamin.maxwell@arm.com>
2025-12-12 09:15:16 +00:00
Luke Lau
86c5539aa8
[IR][RISCV] Remove @llvm.experimental.vp.splat (#171084)
@llvm.experimental.vp.splat was originally added in #98731 in order to
prevent VL toggles when optimizing a zero strided load to a scalar load
+ splat on RISC-V: #101329

However, the need to explicitly set the VL operand has been superseded
by RISCVVLOptimizer which can infer this automatically based on the
splat's users, and the use of the vp.splat intrinsic was removed in
#170543.

Now that there are no users of @llvm.experimental.vp.splat internal to
LLVM and it's unlikely we will need it in future due to
RISCVVLOptimizer, this patch removes the intrinsic. I couldn't find any
publicly available out-of-tree users of the intrinsic with a quick
search on GitHub.
2025-12-09 14:01:54 +08:00
Sudharsan Veeravalli
e546d0f5d4
[RISCV][TTI] Add cost model for ROTL/ROTR (#170824)
A funnel shift with the same first two operands is a rotate. When
`Zbb/Zbkb` is enabled we can use the `ROL(W)/ROR(I)(W)` instruction to
represent this. Add cost model support for this.

Similar to https://github.com/llvm/llvm-project/pull/169335 for AArch64.
2025-12-06 07:47:56 +05:30
Sam Elliott
a15a6c870b
[RISCV] Rename SFB Base Feature (#169607)
New SFB subsets are being added with the scheduler class name as a
suffix, so now is the time to go back to the base extension and add IALU
to its name.

This also:
- Drops a hyphen from the other SFB features for mul and minmax, to more
closely match their scheduling classes.
- Updates the predicates on specific SFB pseudos so we get verifier
errors if we introduce the pseudos when we don't have the right
subtarget feature.
- Updates the SFB Documentation comment to make it no longer
SiFive-specific.
2025-12-01 09:18:02 -08:00
Shih-Po Hung
76d5dd5f9e
[TTI][RISCV] Add cost modelling for intrinsic vp.load.ff (#169890)
This patch is a rework of #160470 (which was reverted).
With getMemIntrinsicCost() now available, we can re‑land the change and
reduce vp_load_ff boilerplate.
2025-11-30 17:46:46 +00:00
David Green
0085ecaa5e
[AArch64] Add costs for ROTR and ROTL. (#169335)
A funnel shift with the first two operands is a rotate. AArch64 has
scalar instructions for ror so can handle a ROTR by a constant or
variant amount cheaply. A ROTL is a ROTR by the opposite amount, which
for constants is cheap and for variable shifts requires an extra neg.
2025-11-28 11:22:42 +00:00
David Green
1580f4b038 [AArch64] Update costs for fshl/r and add rotr/l variants. NFC 2025-11-24 14:42:37 +00:00
Nicolai Hähnle
69589dd2c0
AMDGPU: Improve getShuffleCost accuracy for 8- and 16-bit shuffles (#168818)
These shuffles can always be implemented using v_perm_b32, and so this
rewrites the analysis from the perspective of "how many v_perm_b32s does
it take to assemble each register of the result?"

The test changes in Transforms/SLPVectorizer/reduction.ll are
reasonable: VI (gfx8) has native f16 math, but not packed math.
2025-11-21 19:33:13 +00:00
Nicolai Hähnle
07e893205a
AMDGPU: Expand cost model shufflevector test (#168816)
Add a few corner cases of the "simplified" shuffle kinds.
2025-11-20 06:58:33 -08:00
Pawan Nirpal
124fa5ce5f
[AArch64] - Improve costing for Identity shuffles for SVE targets. (#165375)
Identity masks can be treated as free when scalable vectorization is
possible making the check agnostic of the vectorization policy
fixed/scalable, This allows for aggressive vector combines for identity
shuffle masks.
2025-11-18 11:52:43 -08:00
Benjamin Maxwell
26e42c7e53
[CostModel][AArch64] Remove promotion cost for SVE bfloat arith supported with +sve-b16b16 (#167717)
The resulting costs are the same as the standard SVE costs for `half`
types.
2025-11-17 09:00:36 +00:00
Benjamin Maxwell
efc0ab0f81
[AArch64][CostModel] Add SVE bfloat arithmetic tests (NFC) (#166951)
This patch adds cost model tests for `bfloat` operations with
`+sve-b16b16`. Currently, some of these costs are higher than they
should be as the cost model is assuming `bfloat`s need promotion, but
some of these operations are natively supported with `+sve-b16b16`.
2025-11-11 10:43:31 +00:00
Elvis Wang
3637f66b4d
[RISCV][TTI] Fix crash of non-built-in vector type cost quering. (#167258)
For the non-built-in vector type, the RISCV cost model cannot handle
this properly.
So fall back to the BasicTTI for this situation.

Fixes: #166732
2025-11-10 17:01:43 +08:00
Benjamin Maxwell
21aa788ae0
[AArch64][CostModel] Replace undef with poison in sve-arith-fp.ll (NFC) (#166930)
`undef` values are now deprecated (see
https://llvm.org/docs/UndefinedBehavior.html#undef-values). Updating
this file to avoid triggering the `undef` deprecation warning on future
changes.
2025-11-07 15:04:21 +00:00
Matt Arsenault
92a1eb3712 AArch64: Regenerate cost model tests
Broken by 831e79adff4506a0b22a770dcaa46bf5a37257cb, though
presubmit was somehow green.
2025-11-04 11:08:47 -08:00
Matt Arsenault
fe106b6e73
BasicTTI: Cleanup multiple result intrinsic handling (#165970)
Avoid weird lambda returning function pointer and sink the libcall
logic to where the operation is handled. This allows chaining the
libcall logic to try sincos_stret and fallback to sincos. The resulting
cost seems too low.
2025-11-04 10:19:32 -08:00
David Green
6ad25c5912
[AArch64] Improve the cost model for extending mull (#125651)
We already have cost model code for detecting extending mull multiplies
for the form `mul(ext, ext)`. Since it was added the codegen for mull
has been improved, this attempts to catch the cost model up.

The main idea is to incorporate extends of larger sizes. A vector `v8i32
mul(zext(v8i8), zext(v8i8))` will be code-generated as `zext (v8i16
mul(zext(v8i8), zext(v8i8))`, or umull+ushll+ushll2.

So the total cost should be 3ish if each instruction costs 1. Where
exactly we attribute the costs is dependable, this patch opts to sets
the cost of the extend to 0 (or the cost of the extend not included in
the mull) and the mul gets the cost of the mull+extra extends.

isWideningInstruction is split into two functions for the two types of
operands it supports. isSingleExtWideningInstruction now handles addw
instructions that extend the second operand, isBinExtWideningInstruction
is for instructions like addl that extend both operands.
2025-11-04 07:50:51 +00:00
David Green
f3b407f8f4 [AArch64] Remove old non-power2 aarch64-sve-vector-bits-min tests. NFC 2025-11-03 07:58:01 +00:00
Graham Hunter
9eb3aee101
[CostModel][AArch64] Model cost of extract.last.active intrinsic (clastb) (#165739)
Adds some aarch64 cost model tests for extract.last.active, and produces
a lower cost when SVE is available (expecting clastb to be generated).
2025-10-31 13:49:26 +00:00
Kerry McLaughlin
5f8b3c11ad
[AArch64][CostModel] Reduce cost of wider than legal get.active.lane.mask (#163786)
getIntrinsicInstrCost should halve the cost returned by getTypeLegalizationCost
when the return type requires splitting, but we know that the whilelo
(predicate pair) instruction can be used.

When splitting is still required, the cost get_active_lane_mask should also
reflect the additional saturating add required to increment the start value.
2025-10-24 10:06:34 +01:00
David Green
57ccb4624f [ARM] Update remaining cost tests with -cost-kind=all. NFC 2025-10-24 06:47:38 +01:00
David Green
a242a20f21 [ARM] Update more MVE costmodel tests with -cost-kind=all. NFC 2025-10-23 14:00:11 +01:00
paperchalice
14ed67411c
[Analysis][test] Remove unsafe-fp-math uses (NFC) (#164605)
Post cleanup for #164534.
2025-10-23 00:57:39 +00:00
Nikita Popov
573ca36753
[IR] Replace alignment argument with attribute on masked intrinsics (#163802)
The `masked.load`, `masked.store`, `masked.gather` and `masked.scatter`
intrinsics currently accept a separate alignment immarg. Replace this
with an `align` attribute on the pointer / vector of pointers argument.

This is the standard representation for alignment information on
intrinsics, and is already used by all other memory intrinsics. This
means the signatures now match llvm.expandload, llvm.vp.load, etc.
(Things like llvm.memcpy used to have a separate alignment argument as
well, but were already migrated a long time ago.)

It's worth noting that the masked.gather and masked.scatter intrinsics
previously accepted a zero alignment to indicate the ABI type alignment
of the element type. This special case is gone now: If the align
attribute is omitted, the implied alignment is 1, as usual. If ABI
alignment is desired, it needs to be explicitly emitted (which the
IRBuilder API already requires anyway).
2025-10-20 08:50:09 +00:00
Nikita Popov
a26f4a4c2c [CostModel] Generate test checks (NFC) 2025-10-15 14:54:21 +02:00
David Sherwood
f29f23711d
[Analysis][AArch64][NFC] Change undef to poison in most tests (#163532)
Whenever someone modifies an existing test that has `undef` in it the
github code formatter will complain so it's not easy to know if it's due
to a new or old use. I figured I may as well just do a simple sed
replace of undef with poison in all the tests to clean them up.
Hopefully it makes the contribution process a bit easier.
2025-10-15 12:39:52 +01:00
Kerry McLaughlin
ad2986f73c
[AArch64] Replace undef with poison in sve-intrinsics.ll (NFC) (#163399) 2025-10-15 09:20:06 +01:00
ShihPo Hung
2be906b255 Revert "[TTI][RISCV] Add cost modelling for intrinsic vp.load.ff (#160470)"
This reverts commit aa08b1a9963f33ded658d3ee655429e1121b5212.
2025-09-26 17:24:56 -07:00
Shih-Po Hung
aa08b1a996
[TTI][RISCV] Add cost modelling for intrinsic vp.load.ff (#160470)
Split out from #151300 to isolate TargetTransformInfo cost modelling for
fault-only-first loads from VPlan implementation details. This change
adds costing support for vp.load.ff independently of the VPlan work.

For now, model a vp.load.ff as cost-equivalent to a vp.load.
2025-09-26 16:47:10 +08:00
Giuseppe Rossini
e94a0b300a
[AMDGPU] Fix vector legalization for bf16 valu ops (#158439)
Add v4,v8,v16,v32 legalizations for the following operations:
- `FADD`
- `FMUL`
- `FMA`
- `FCANONICALIZE`
2025-09-25 10:07:11 +01:00
AZero13
733c1aded1
[ARM] Replace ABS and tABS machine nodes with custom lowering (#156717)
Just do a custom lowering instead.

Also copy paste the cmov-neg fold to prevent regressions in nabs.
2025-09-19 19:43:36 +01:00
David Green
2c764c6faf [ARM] Correct attributes on abs.ll costmodel test. NFC
Adding mve was a mistake and preventing it from testing the expected
architecture levels.
2025-09-17 11:19:32 +01:00
David Green
22625538cb [ARM] Add a quick abs scalar costmodel test. NFC 2025-09-16 22:35:27 +01:00
David Green
f562e2a6f5 [ARM] Update a number of reduction tests to use -cost-kind=all. NFC 2025-09-16 21:50:38 +01:00
Simon Pilgrim
dfbefe4a65
[CostModel][X86] Add missing AVX1 costs for PMULUDQ v4i64 pattern (#157475)
We need to account for AVX1 targets splitting 256-bit PMULUDQ style
patterns - we included a AVX2 cost, but missed out AVX1 despite v4i64
being a legal type

Noticed while working on #156568
2025-09-08 15:06:33 +00:00
David Green
4436d1d1cd
[AArch64] Give a higher cost for more expensive SVE FCMP instructions (#153816)
This tries to add a higher cost for SVE FCM** comparison instructions
that often have a lower throughput than the Neon equivalents that can be
executed on more vector pipelines.

This patch takes the slightly unorthodox approach of using the
information in the scheduling model to compare the throughput of a
FCMEQ_PPzZZ_S (SVE) and a FCMEQv4f32 (Neon). This isn't how things will
(probably) want to work in the long run, where all the information comes
more directly from the scheduling model, but that still needs to be
proven out. The downsides of this approach of using the scheduling model
info is if the core does not have a scheduling model but wants a
different cost - then an alternative approach will be needed (but then
maybe that is a good reason to create a new scheduling model).

The alternative would either be to make a subtarget feature for the
affected cores or just always enable it.
2025-09-04 19:50:39 +01:00
Gaëtan Bossu
3bb6e60c16
[AArch64] Update cost model for extracting halves from 128+ bit vectors (#155601)
Previously, only 128-bit "NEON" vectors were given sensible costs.
Cores with vscale>1 can use SVE's EXT instruction to perform a
fixed-length subvector extract.

This is a follow-up from the codegen patches at #152554. They show that
with the help of MOVPRFX, we can do subvector extracts with roughly one
instruction. We now at least give sensible costs for extracting 128-bit
halves from a 256-bit vector.
2025-09-03 12:00:17 +01:00
David Green
aa14b3eed9 [ARM] Update a number of MVE tests to use -cost-kind=all. NFC 2025-08-26 20:43:27 +01:00
Mary Kassayova
98867bf8de
[AArch64] [CostModel] Fix cost modelling for saturating arithmetic intrinsics (#152333)
The cost model previously overestimating throughput costs to wide
fixed-length saturating arithmetic intrinsics when using SVE with a
fixed vscale of 2. These costs ended up much higher than for the same
operations using NEON, despite being fully legal and efficient with SVE.
This patch adjusts the cost model to avoid penalising these intrinsics
under SVE.
2025-08-21 11:31:34 +01:00
David Green
c856e8def4 [ARM] Update cmps.ll, control-flow.ll and divrem.ll to use -cost-kind=all. NFC 2025-08-20 12:59:32 +01:00
David Green
5836bae463
[AArch64] Change the cost of fma and fmuladd to match fmul. (#152963)
As fmul and fmadd are so similar, their performance characteristics tend
to be the same on most platforms, at least in terms of reciprocal
throughputs. Processors capable of performing a given number of fmul per
cycle can usually perform the same number of fma, with the extra add
being relatively simple on top. This patch makes the scores of the two
operations the same, which brings the throughput cost of a fma/fmuladd
to 2, and the latency to 3, which are the defaults for fmul.

Note that we might also want to change the throughput cost of a fmul to
1, as most processors have ample bandwidth for them, but they should
still stay in-line with one another.
2025-08-14 21:53:45 +01:00
David Green
d9d9d9ad19
[ARM][MVE] Add shuffle costs for LDn and STn instructions. (#145304)
LD2 is represented in IR as deinterleave-shuffle(load), and ST2 as
store(interleave-shuffle). Whilst the shuffle would be expensive in
general for MVE (it does not have zip/uzp instructions), it should be
treated as cheap when part of the LD2/ST2 pattern. This borrows some
code from the AArch64 backed to produce lower costs. (Some of which
still shows as higher than it should - that just shows how broken the
generic shuffle costs are at the moment, they would be lower if
getShuffleCost was called directly as opposed to going through
getInstructionCost).
2025-08-14 06:59:37 +01:00
Luke Lau
81b576e66b
[RISCV] Cost casts with illegal types that can't be legalized (#153030)
If we have a floating point vector and no zve32f/zve64f/zve64d, we can
end up with an invalid type-legalization cost from
getTypeLegalizationCost.

Previously this triggered an assertion that the type must have been
legalized if the "legal" type is a vector, but in this case when it's
not possible to legalize the original type is spat back out.

This fixes it by just checking that the legalization cost is valid.

We don't have much testing for zve64x, so we may have other places in
the cost model with this issue.

Fixes #153008
2025-08-12 00:29:39 +08:00
David Green
7f1638efc1
[AArch64] Generalize costing for FP16 instructions (#150033)
This extracts the code for modelling a fp16 operation as
`fptrunc(fpop(fpext,fpext))` into a new function named
getFP16BF16PromoteCost so that it can be reused by the
arithmetic instructions. The function takes a lambda to
calculate the cost of the operation with the promoted type.
2025-08-08 13:40:07 +01:00
Graham Hunter
de72cca671
[CostModel] Provide a default model for histogram intrinsics (#149348)
Since we scalarize these intrinsics when the target does not support
them, we should model that for costing purposes.
2025-08-08 11:00:00 +01:00
Nikita Popov
c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
Now that #149310 has restricted lifetime intrinsics to only work on
allocas, we can also drop the explicit size argument. Instead, the size
is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead.
We never used that capability, so we should remove the need to handle
that possibility everywhere (though many key places, including stack
coloring, did not actually respect this).
2025-08-08 11:09:34 +02:00
David Green
6a32e2225e [AArch64] Add SVE fmuladd and fma cost tests. NFC 2025-08-08 08:52:28 +01:00
David Green
fcae1ba775 [ARM] Use -cost-kind=all for cast and active_lane_mask tests. NFC 2025-08-05 08:14:47 +01:00