5276 Commits

Author SHA1 Message Date
Florian Hahn
f8d5a003fa
[SCEV] Don't create SCEVPtrToAddr for unstable pointer representations. (#180718)
Conservatively treat unstable pointers as SCEVCouldNotCompute in
getPtrToAddrExpr, and return SCEVUnknown when constructing from IR.

This surfaced as part of the discussion in
https://github.com/llvm/llvm-project/pull/178861.

PR: https://github.com/llvm/llvm-project/pull/180718
2026-02-10 13:46:42 +00:00
Florian Hahn
ceec2c72d2
[SCEV] Add ptrtoaddr tests with external state/unstable addrspaces.
Add ptrtoaddr tests with address spaces with unstable and external but
stable pointer representations.

Currently we incorrectly form ptrtoaddr for unstsable pointers. See
discussion in https://github.com/llvm/llvm-project/pull/178861 for more
details.
2026-02-10 10:25:23 +00:00
CarolineConcatto
570fffe044
[MemorySSA] Relax clobbering checks for calls to consider writes only (#179721)
Now that getModRefInfo for calls handles read and write effects by
examining both calls, the clobbering query no longer needs to treat
reads as clobbers. Update the check to consider writes only, aligning
call handling with other instructions
2026-02-10 09:19:01 +00:00
Diana Picus
24405f070f
[AMDGPU] Add intrinsic exposing s_alloc_vgpr (#163951)
Make it possible to use `s_alloc_vgpr` at the IR level. This is a huge
footgun and use for anything other than compiler internal purposes is
heavily discouraged. The calling code must make sure that it does not
allocate fewer VGPRs than necessary - the intrinsic is NOT a request to
the backend to limit the number of VGPRs it uses (in essence it's not so
different from what we do with the dynamic VGPR flags of the
`amdgcn.cs.chain` intrinsic, it just makes it possible to use this
functionality in other scenarios).
2026-02-10 09:28:31 +01:00
Simon Pilgrim
d8e679c286
[CostModel][X86] getShuffleCost - SK_Transpose v4f64/v4i64 matches UNPCK - don't generalise to SK_PermuteTwoSrc (#180514)
Other SK_Transpose shuffles can be cheaper than SK_PermuteTwoSrc but this is the easy one to handle

Fixes #161980
2026-02-09 14:09:49 +00:00
Nikolas Klauser
6dbdfd824a
[InstCombine] Drop nonnull assumes if the pointer is already known to be nonnull (#180434) 2026-02-09 13:13:32 +01:00
Benjamin Maxwell
233a9918bc
[AArch64] Tweak fixed-length loop.dependence.mask costs (#175538)
For fixed-length masks we need to AND the result of the whilewr/rw with
`ptrue vl*` (which is at least one more instruction).
2026-02-09 09:58:57 +00:00
Luke Lau
f2d5b3952b
[RISCV] Add cost for @llvm.vector.splice.{left,right} (#179219)
Currently vector splice intrinsics are costed through getShuffleCost
when the offset is fixed. When the offset is variable though we can't
use a shuffle mask so it currently returns invalid.

This implements the cost in RISCVTTIImpl::getIntrinsicInstrCost as the
cost of a slideup and a slidedown, which matches the codegen.

It also implements the type based cost whenever the offset argument
isn't available.

It may be possible to reduce the cost in future when one of the vector
operands is known to be poison, in which case we only generate a single
slideup or slidedown.
2026-02-09 16:11:15 +08:00
Pengcheng Wang
e16f35493c
[RISCV][TTI] Adjust the cost of llvm.abs intrinsic when Zvabd exists
When `Zvabd` exists, `llvm.abs` is lowered to `vabs.v` so the cost
is 1.

Reviewers: mshockwave, topperc, lukel97, skachkov-sc, preames

Reviewed By: topperc

Pull Request: https://github.com/llvm/llvm-project/pull/180146
2026-02-09 15:50:14 +08:00
Ricardo Jesus
f6a9cbb6e5
[AArch64][SDAG] Legalise BSWAP for Neon types. (#179702)
GlobalISel legalised BSWAP for Neon types in #80036.

Legalising the types keeps them from being expanded to vector_shuffle
before being matched to REVs, and allows half-rotations on i16 vectors
to be combined to bswap (see
https://github.com/llvm/llvm-project/pull/178706#discussion_r2742804463).
2026-02-06 12:26:01 +00:00
SiliconA-Z
37aba1b5d4
[ARM] Set operation action for UMULO and SMULO as Custom if not Thumb1 (#154253)
We should specify a custom lowering for SMULO and UMULO like we do for
AArch64, but only if not Thumb 1 obviously.
2026-02-05 08:47:56 -08:00
Matt Arsenault
2502e3b7ba
IR: Promote "denormal-fp-math" to a first class attribute (#174293)
Convert "denormal-fp-math" and "denormal-fp-math-f32" into a first
class denormal_fpenv attribute. Previously the query for the effective
denormal mode involved two string attribute queries with parsing. I'm
introducing more uses of this, so it makes sense to convert this
to a more efficient encoding. The old representation was also awkward
since it was split across two separate attributes. The new encoding
just stores the default and float modes as bitfields, largely avoiding
the need to consider if the other mode is set.

The syntax in the common cases looks like this:
  `denormal_fpenv(preservesign,preservesign)`
  `denormal_fpenv(float: preservesign,preservesign)`
  `denormal_fpenv(dynamic,dynamic float: preservesign,preservesign)`

I wasn't sure about reusing the float type name instead of adding a
new keyword. It's parsed as a type but only accepts float. I'm also
debating switching the name to subnormal to match the current
preferred IEEE terminology (also used by nofpclass and other
contexts).

This has a behavior change when using the command flag debug
options to set the denormal mode. The behavior of the flag
ignored functions with an explicit attribute set, per
the default and f32 version. Now that these are one attribute,
the flag logic can't distinguish which of the two components
were explicitly set on the function. Only one test appeared to
rely on this behavior, so I just avoided using the flags in it.

This also does not perform all the code cleanups this enables.
In particular the attributor handling could be cleaned up.

I also guessed at how to support this in MLIR. I followed
MemoryEffects as a reference; it appears bitfields are expanded
into arguments to attributes, so the representation there is
a bit uglier with the 2 2-element fields flattened into 4 arguments.
2026-02-05 13:31:26 +00:00
Ryotaro Kasuga
37bbeb31f3
[DA] Add tests for dependencies are missed due to large BTC (NFC) (#179664)
For some dependence tests, there are corner cases where `BTC <s 0`. This
patch adds test cases for those situations. Notably, in these tests,
dependencies are missed even though no overflow occurs.
2026-02-05 12:48:15 +09:00
Andreas Jonson
faa4b97b10
[InstCombine] fold icmp ne (and X, 1), 0 --> trunc X to i1 (#178977)
Remove vector check so this fold always is done.

proof: https://alive2.llvm.org/ce/z/oabD6J
closes #172888
2026-02-03 19:14:27 +01:00
Tomer Shafir
e706614f2f
[Analysis][CostModel] Add insert-extract runlines for Apple CPUs (NFC) (#179236)
Including `apple-latest` to cover new processors until (if) they
diverge.
2026-02-03 12:18:33 +02:00
Simon Pilgrim
1bcff55db1
[CostModel][X86] clmul.ll - add i16 and 128/256/512-bit vector cost tests (#179283) 2026-02-02 17:26:01 +00:00
niqiangpro-cell
603b625b21
[Analysis] Add Intrinsics::CLMUL case to cost calculations to getIntrinsicInstrCost / getTypeBasedIntrinsicInstrCost (#176552)
This patch adds a case in getIntrinsicInstrCost and
getTypeBasedIntrinsicInstrCost in
llvm/include/llvm/CodeGen/BasicTTIImpl.h for Intrinsic::clmul. This
patch uses TLI->isOperationLegalOrCustom to check if the instruction is
cheap. If not cheap, it sums up the cost of the arithmetic operations
(AND, SHIFT, XOR) multiplied by the bit width.

Fixes #176354
2026-02-01 12:56:41 +00:00
Ryan Buchner
2753e1dedf
[RISCV] Set the reciprocal throughtput cost for division to TTI::TCC_Expensive (#177516)
Fixes #176208. Scaled back version of #176515 that only affects the RISCV backend.

Only modifies the cost for cases when DIV is a legal operation.

Updates the cost for both Scalar and Vector types.

Used `TTI::TCC_Expensive` as suggested by
https://github.com/llvm/llvm-project/issues/176208#issuecomment-3760902537.

---------

Co-authored-by: Luke Lau <luke_lau@icloud.com>
2026-01-27 11:01:19 -08:00
Florian Hahn
b794baf8e7
[TTI] Add VectorInstrContext for context-aware insert/extract costs. (#175982)
This commit introduces the VectorInstrContext (VIC) infrastructure to
improve cost estimates for insert/extracts based on the context
instruction in which the insert/extract is used.

This is similar to CastContextHint, and allows providing context on how
the insert/extract is going to be used before creating IR. This is
useful in the LoopVectorizer, where costs need to estimated before
creating IR.

The new hint currently only replaces an existing check in AArch64,
but new uses will be introduced in follow-ups, including
https://github.com/llvm/llvm-project/pull/177201.

PR: https://github.com/llvm/llvm-project/pull/175982
2026-01-27 16:30:29 +00:00
Lleu Yang
b8cccd6cef
[Analysis] computeKnownBitsFromOperator - add @llvm.clmul knownbits handling and tests (#177893)
This adds knownbits handling for `Intrinsic::clmul` inside
`computeKnownBitsFromOperator`. Tests are also included.

Closes #177550
2026-01-27 11:54:24 +00:00
Florian Hahn
7fd2056efa
[SCEV] Sink SCEVPtrToAddr to leaf SCEVUnknowns. (#174437)
Use CastSinkingRewriter for SCEVPtrToAddr expressions as well, sinking
them the same as SCEVPtrToInt expressions.

Depends on https://github.com/llvm/llvm-project/pull/174435 
and https://github.com/llvm/llvm-project/pull/158032.

PR: https://github.com/llvm/llvm-project/pull/174437
2026-01-26 19:01:38 +00:00
Walter Lee
313bec1c9a
Add quotes around "print<cost-model>" argument
This is consistent with other tests and is required for some test runners.
2026-01-26 00:48:54 -05:00
ChaseYalon
2deae0baf7
X86: Fix VSCALE insert element crash in codegen (#177705)
When inserting elements into <vscale x N x i64> scalable vectors, the X86 backend now returns InstructionCost::getInvalid() instead of panicking.

Fixes #176823
2026-01-24 15:13:45 +00:00
David Green
f6f5ad3e0b [AArch64] Add some basic i128 arithmetic cost test cases. NFC 2026-01-23 18:44:22 +00:00
Changpeng Fang
2ee329fc51
[AMDGPU] Remove intrinsic declarations in a couple tests, NFC (#177218)
There is no need to explicitly declare intrinsic now. In this PR, we
only
remove intrinsic declarations in the two tests recently touched.
2026-01-21 12:16:26 -08:00
Luke Lau
cee36b23cc
[IR] Allow non-constant offsets in @llvm.vector.splice.{left,right} (#174693)
Following on from #170796, this PR implements the second part of
https://discourse.llvm.org/t/rfc-allow-non-constant-offsets-in-llvm-vector-splice/88974
by allowing non-constant offsets in the vector splice intrinsics.

Previously @llvm.vector.splice had a restriction enforced by the
verifier that the offset had to be known to be within the range of the
vector at compile time. Because we can't enforce this with non-constant
offsets, it's been relaxed so that offsets that would slide the vector
out of bounds return a poison value, similar to
insertelement/extractelement.

@llvm.vector.splice.left also previously only allowed offsets within the
range 0 <= Offset < N, but this has been relaxed to 0 <= Offset <= N so
that it's consistent with @llvm.vector.splice.right.

In lieu of the verifier checks that were removed, InstSimplify has been
taught to fold splices to poison when the offset is out of bounds.

The cost model isn't implemented in this PR, and just returns invalid
for any non-constant offsets for now. I think the correct way to cost
these non-constant offets isn't through getShuffleCost because they
can't handle variable masks, but instead just through
getIntrinsicInstCost.
2026-01-21 10:58:40 +00:00
RolandF77
106120784b
[PowerPC] cost modeling for length type VP intrinsic load/store (#168938)
Override and fill in the target hooks for PPC that allow opt to cost
using length style VP intrinsics for load/store.
2026-01-20 15:40:49 -05:00
Luke Lau
0c1257cd46
[RISCV] Fix i64 gather/scatter cost on rv32 (#176105)
Fixes #175909

We compute the cost of a gather/scatter by multiplying the cost of the
scalar element type memory op by the estimated number of elements. On
rv32 though a scalar i64 load costs 2, even if we have zve64x.

This causes the cost to diverge between a vector of f64 and vector of
i64, even though both are the same. This fixes it by just using
TTI::TCC_Basic as the scalar memory op cost. The element type is checked
to be legal at this point.

I think we have the same issue for the strided op cost, but we don't
have test coverage for it yet.
2026-01-20 08:00:05 +00:00
Florian Hahn
9aadbb716d
[LAA] Check if access is part of loop in isNoWrap.
blockNeedsPredication does not support blocks outside of the loop. Bail
out for users outside the loop.

Fixes https://github.com/llvm/llvm-project/issues/174760.
2026-01-19 20:21:09 +00:00
David Green
59e855729d
[AArch64] Remove AdjustCost from getCastInstrCost. (#143073)
This adds costsize (and latency / code-lat) costs for AArch64's
getCastInstr. This mostly affects how much unrolling is performed, and
helps bring the codesize cost in line with the number of instructions we
generate.
2026-01-17 16:28:44 +00:00
Florian Hahn
586bdf0de5
[AArch64] Treat LD1 as cheap in getVectorInstrCostHelper on Apple cores. (#175970)
On Apple Silicon cores, single-element LD1 have should have the same
performance characteristics as regular loads. Consider the insert for
insertelement (load) as free

In terms of additional code-gen changes, this enables unrolling in more
cases, due to the dynamic cost of vector loops with scalar loads +
insert being estimated more accurately.

PR: https://github.com/llvm/llvm-project/pull/175970
2026-01-16 17:31:09 +00:00
Florian Hahn
3fb914d851
[SCEV] Add initial support for ptrtoaddr. (#158032)
Add initial support for PtrToAddr to SCEV, including a new
SCEVPtrToAddrExpr and SCEV expansion support for it.

PR: https://github.com/llvm/llvm-project/pull/158032
2026-01-16 11:58:04 +00:00
Ryotaro Kasuga
6934c36a86
[DA] Use ScalarEvolution::isKnownPredicate (#170919)
DA uses `DependenceInfo::isKnownPredicate` instead of
`ScalarEvolution::isKnownPredicate` in several places. The former is
intended to be a "wrapper" for the later. Specifically, it performs the
following processes:

- Replace `zext(X) cmp zext(Y)` with `X cmp Y`.
- Replace `X >=s Y` with `X - Y >=s 0`
- Replace `X <=s Y` with `X - Y <=s 0`
- Replace `X >s Y` with `X - Y >s 0`
- Replace `X <s Y` with `X - Y <s 0`

The first one can return an incorrect result when the most significant
bit of `X` and `Y` are different. Everything other than the first one
can be incorrect when `X - Y` overflows. Actually, when a `SCEVUnknown`
is involved (e.g., `%n <s %n + 1` will be `0 <s 1`), this function often
returns a result that ignore the possibility of overflow.

This patch removes `DependenceInfo::isKnownPredicate` and replace all
uses of it with `ScalarEvolution::isKnownPredicate`. There is a
degradation in some test cases, but this should be correct.

Resolve #169810
2026-01-16 10:58:51 +00:00
Luke Lau
3ad6d350c4 [RISCV] Add tests for rv32 gather/scatter costs. NFC
There's a divergence with the rv32 costs that I plan on fixing in
another patch, so this precommits the tests for them.

The zve32f RUN lines were split off into another file so the check prefixes
are easier to reason about.

The -riscv-v-vector-bits-max RUN lines were also removed to simplify the
check prefixes since I'm not sure if they were intentionally testing any
specific logic.
2026-01-15 16:10:24 +08:00
Nikolas Klauser
d2afc3e84b
[ValueTracking] Allow dereferenceable(0) to be applied to a null pointer (#175913)
`dereferenceable(<n>)` with n being potentially zero can come up when
using an operand bundle with a variable size. Currently this implies
that the pointer is non-null, even though `[nullptr, nullptr)` is a
valid range in any programming language I'm aware of. This patch removes
this implication and updates the language reference to reflect that
`dereferenceable` with a zero argument is valid.
2026-01-14 15:58:39 +01:00
Sjoerd Meijer
e4a7541950
[Delinearization] Enable delinearize-use-fixed-size-array-heuristic (#175770)
It's time to enable this option so we can take the next steps,
see also the discussion in #175173. I.e., this is required to see
if we can take advantage of the size of statically declared
arrays during delinearization.
2026-01-14 09:40:29 +00:00
Sjoerd Meijer
1e96ee67a1
[Delinearization] Precommit global decl test. NFC. (#175173)
This precommits a test that should demonstrate that Delinearization can
succeed when we analyse the size of the global variable definition.
2026-01-14 08:39:17 +00:00
Ryotaro Kasuga
f07877b2ea
[DA] Add tests for nsw doesn't hold on entire iteration space (NFC) (#162281)
The monotonicity definition states its domain as follows:

```
/// The property of monotonicity of a SCEV. To define the monotonicity, assume
/// a SCEV defined within N-nested loops. Let i_k denote the iteration number
/// of the k-th loop. Then we can regard the SCEV as an N-ary function:
///
///   F(i_1, i_2, ..., i_N)
///
/// The domain of i_k is the closed range [0, BTC_k], where BTC_k is the
/// backedge-taken count of the k-th loop
```

Current monotonicity check implementation doesn't match this definition
because:

- Just checking nowrap property of addrecs recursively is not sufficient
to ensure monotonicity over the entire domain. The nowrap property may
hold for certain paths but not for all possible iteration combinations
of nested loops.
- It doesn't consider cases where exact backedge-taken counts are
unknown.

Therefore we need to fix either the definition or the implementation.
This patch adds the test cases that demonstrate this mismatch.
2026-01-13 17:18:05 +00:00
Sameer Sahasrabuddhe
da94edf535
[UniformityAnalysis] Jump over reducible cycles when locating join blocks (#174938)
When locating the join blocks of a divergent block, the algorithm relies
on pseudo-edges from the header of a reducible cycle to the cycle exits.
This was missed in the actual traversal, producing unnecessary joins
inside the reducible cycle. This caused an assert in the included test,
which expected that if a join existed in a reducible cycle for a
divergent branch outside the cycle, then it must be header.

This fixes the reverted commit from #174117
2026-01-13 07:49:58 +05:30
Ryan Buchner
278946408e
[RISCV] Improve cost modeling of RISCVTTIImpl::getConstantPoolLoadCost() (#174438)
Some machines are able to make use of AUIPC + ADDI or LUI + ADDI fusion, make sure to consider that in the cost model for `RISCVTTIImpl::getConstantPoolLoadCost()`.
2026-01-07 16:50:47 -08:00
Florian Hahn
1dea577186
[SCEV] Handle URem pattern in getRangeRef. (#174456)
Check if an scAddExpr expressions represents an URem, and
if it does, use the divisor to limit the conservative range.

https://alive2.llvm.org/ce/z/VPxe7C

PR: https://github.com/llvm/llvm-project/pull/174456
2026-01-07 11:32:43 +00:00
Sameer Sahasrabuddhe
050195053c Revert "[UniformityAnalysis] Remove an incorrect assertion in uniformity analysis (#174117)"
This reverts commit 371fad28244a16f64e707eb8e9889202fdacf85f.

The change only fixes the superficial assertion. The real problem is that bb.3
and bb.4 should not have been identified as joins of bb.5
2026-01-07 12:33:33 +05:30
Shilei Tian
5a63367b15
Reapply "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674) (#174697)
This reverts commit 0b2f3cfb72a76fa90f3ec2a234caabe0d0712590.
2026-01-07 06:12:19 +00:00
dyung
0b2f3cfb72
Revert "[AMDGPU] Rework the clamp support for WMMA instructions" (#174674)
Reverts llvm/llvm-project#174310

This change is causing 2 cross-project-test failures on
https://lab.llvm.org/buildbot/#/builders/174/builds/29695
2026-01-07 01:18:23 +00:00
Shilei Tian
ccca3b8c67
[AMDGPU] Rework the clamp support for WMMA instructions (#174310)
Fixes #166989.
2026-01-06 15:46:40 -05:00
Shilei Tian
371fad2824
[UniformityAnalysis] Remove an incorrect assertion in uniformity analysis (#174117)
The join block could be not a header of a cycle, as shown in the newly
added test case.
2026-01-06 15:44:08 -05:00
Matt Arsenault
56ce7ed72b
llvm: Convert some assorted lit tests to opaque pointers (#174564)
Some of the MIR test hit a bug where it errors if there is a
raw global reference as the referenced value. Worked around some
of those by just keeping a no-op bitcast constant expression.
2026-01-06 11:41:27 +00:00
Luke Lau
ad4bfac732
[IR] Split vector.splice into vector.splice.left and vector.splice.right (#170796)
This PR implements the first change outlined in
https://discourse.llvm.org/t/rfc-allow-non-constant-offsets-in-llvm-vector-splice/88974?u=lukel

In order to allow non-immediate offsets in the llvm.vector.splice
intrinsic, we need to separate out the "shift left" and "shift right"
modes into two separate intrinsics, which were previously determined by
whether or not the offset is positive or negative.

The description in the LangRef has also been reworded in terms of
sliding elements left or right and extracting either the upper or lower
half as opposed to extracting from a certain index, which brings it
inline with the definition of `llvm.fshr.*`/`llvm.fshl.*`.

This patch teaches AutoUpgrade.cpp to upgrade the old intrinsics into
their new equivalent one based on their offset, so existing uses of
vector.splice should still work.

Uses of llvm.vector.splice in `llvm/test/CodeGen` haven't been replaced
in this PR to keep the diff small and kick the tyres on the AutoUpgrader
a bit. I planned to do this in a follow up NFC but can include it in
this PR if reviewers prefer.

Similarly the shuffle costing kind `SK_Splice` has just been kept the
same for now, to be split into `SK_SpliceLeft` and `SK_SpliceRight`
later.
2026-01-06 15:41:26 +08:00
Nikita Popov
e65317acbb
[ValueTracking] Support ptrtoaddr in computeKnownBits() (#173358)
ptrtoaddr can be handled the same as ptrtoint here. The pointer known
bits cover the full pointer width, and ptrtoaddr either passes those
through directly or truncates to the address size.
2026-01-05 09:37:34 +01:00
Shilei Tian
c97de4387b
Revert "[AMDGPU] add clamp immediate operand to WMMA iu8 intrinsic (#171069)" (#174303)
This reverts commit 2c376ffeca490a5732e4fd6e98e5351fcf6d692a because it
breaks assembler.

```
$ llvm-mc -triple=amdgcn -mcpu=gfx1250 -show-encoding <<< "v_wmma_i32_16x16x64_iu8 v[16:23], v[0:7], v[8:15], v[16:23] matrix_b_reuse"
  v_wmma_i32_16x16x64_iu8 v[16:23], v[0:7], v[8:15], v[16:23] clamp ; encoding: [0x10,0x80,0x72,0xcc,0x00,0x11,0x42,0x1c]
```

We have a fundamental issue in the clamp support in VOP3P instructions,
which will need more changes.
2026-01-04 02:13:21 +00:00