34539 Commits

Author SHA1 Message Date
Florian Hahn
b53adf4246
[VPlan] Always process all argmin/argmax reductions in plan.
Follow-up to https://github.com/llvm/llvm-project/pull/170223.
Instead of exiting early, continue processing remaining reductions in
the loop. This ensures all multi-use reductions are properly converted
or the plan is rejected if there are unconvertable patterns.

Fixes https://github.com/llvm/llvm-project/issues/184729.
2026-03-05 22:37:22 +00:00
Florian Hahn
f7560e1795
[LV] Add tests with loops with multiple argmin/argmax.
Add additional tests with multiple argmin/argmax reductions for
https://github.com/llvm/llvm-project/issues/184729.
2026-03-05 18:58:24 +00:00
Alexey Bataev
b7ed29df5d [SLP][NFC]Add a test with a loop with profiling info, NFC 2026-03-05 10:57:19 -08:00
Alexey Bataev
43fc0f32c0 [SLP][NFC]Add a case with a missing matching between shl/add/sub, NFC 2026-03-05 08:44:44 -08:00
Justin Fargnoli
f0265ccb60
[LoopUnroll] Ensure we can accept both llvm.loop.unroll.full and llvm.loop.unroll.enable metadata on the same loop (NFC) (#182381)
Ensure that frontends can request both `PragmaEnable` and `PragmaFull`
semantics on a loop.

FYI: to the best of my knowledge, it's not possible to toggle both
`PragmaEnable` and `PragmaFull` via `clang`.
2026-03-05 16:44:25 +00:00
Shivam Kunwar
e3b62ffcd8
[Reassociate][DebugInfo] Salvage debug info before rewriting expression (#182730)
When RewriteExprTree modifies instruction operands, call
`salvageDebugInfo()` before `setOperand()` so debug value expressions
are rewritten while original operands are still intact. This preserves
variable accessibility in debuggers instead of dropping values to
poison.

Fixes #60532
Fixes #61272
2026-03-05 18:41:57 +05:30
Florian Hahn
d316fb0797
[VPlan] Replicate VPScalarIVStepsRecipe by VF outside replicate regions. (#170053)
Extend replicateByVF to also handle VPScalarIVStepsRecipe. To do so, the
patch adds a new lane operand to VPScalarIVStepsRecipe, which is only
added when replicating. This enables removing a number of lane 0
computations. The lane operand will also be used to explicitly replicate
replicate regions in a follow-up.

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

PR: https://github.com/llvm/llvm-project/pull/170053
2026-03-05 12:42:20 +00:00
David Sherwood
6778c11f5c
[AArch64] Fix SVE cost model for various math intrinsics (#184358)
The implementation of getIntrinsicInstrCost in BasicTTIImpl
assumes that for some intrinsics if we're using custom
lowering for the equivalent DAG node that the cost needs to
be 2, instead of 1 for legal ops. However, even though we
use custom lowering for these scalable vector operations
when SVE is available, we still end up generating the same
efficient codegen as fixed-width. This patch deals with a
few obvious intrinsics that we know get lowered to something
sensible and return the same cost as NEON, i.e. 1.
2026-03-05 08:59:01 +00:00
Luke Lau
825129378e
[VPlan] Move tail folding out of VPlanPredicator. NFC (#176143)
Currently the logic for introducing a header mask and predicating the
vector loop region is done inside introduceMasksAndLinearize.

This splits the tail folding part out into an individual VPlan transform
so that VPlanPredicator.cpp doesn't need to worry about tail folding,
which seemed to be a temporary measure according to a comment in
VPlanTransforms.h.

To perform tail folding independently, this splits the "body" of the
vector loop region between the phis in the header and the branch + iv
increment in the latch:

Before:

```
+-------------------------------------------+
|%iv = ...                                  |
|...                                        |
|%iv.next = add %iv, vfxuf                  |
|branch-on-count %iv.next, vector-trip-count|
+-------------------------------------------+
```

After:
```
+-------------------------------------------+
|%iv = ...                                  |
|%wide.iv = widen-canonical-iv ...          |
|%header-mask = icmp ule %wide.iv, BTC      |---+
|branch-on-cond %header-mask                |   |
+-------------------------------------------+   |
                     |                          |
                     v                          |
+-------------------------------------------+   |
|...                                        |   |
+-------------------------------------------+   |
                     |                          |
                     v                          |
+-------------------------------------------+   |
|%iv.next = add %iv, vfxuf                  |<--+
|branch-on-count %iv.next, vector-trip-count|
+-------------------------------------------+
```

Phis are then inserted in the latch for any value in the loop body that
have outside uses, with poison as their incoming value from the header
edge.

The motivation for this is to allow us to share the same "predicate all
successor blocks" type of predication we do for tail folding, but for
early-exit loops in #172454. This may also allow us to directly emit an
EVL based header mask, instead of having to match + transform the
existing header mask in addExplicitVectorLength.

This also allows us to eventually handle recurrences in the same
transform, avoiding the need to special case tail folding in
addReductionResultComputation.
2026-03-05 08:17:37 +00:00
Joseph Huber
5a88dffc40
[Clang] Only define wchar_size module flag if non-standard (#184668)
Summary:
This PR simply changes the behavior of the `wchar_size` flag. Currently,
we emit this in all cases for all targets. This causes problems during
LLVM-IR linking, specifically because this would vary between Linux and
Windows in unintuitive ways. Now we have an llvm::Triple helper to
determine the size from the known values. The module flag will only be
emitted if these do not match (indicating a non-standard environment).

In addition to fixing AMDGCN bitcode linking, this also means we don't
need to bloat *every* IR module compiled by clang with this flag. The
changed tests reflects this, one less unnecessary piece of metadata.
2026-03-04 16:13:48 -06:00
Alexey Bataev
2714583317 [SLP]Do not consider split vectorize nodes as vector phi nodes
Split vectorize nodes should not be considered as vector PHI nodes, when
trying to find the insertion point for the postpotned nodes.

Fixes #184585
2026-03-04 14:03:20 -08:00
Teresa Johnson
5859284824
[MemProf] Add stack IDs to MemProfUse optimization remarks (#184670)
This makes the remarks more equivalent for analysis to what we emit to
stderr under -memprof-print-match-info.
2026-03-04 12:22:50 -08:00
Matt Arsenault
a212ebd471
ValueTracking: Handle constant structs in computeKnownFPClass (#184192)
Also fix attributor not bothering to deal with structs.
2026-03-04 20:12:28 +01:00
Matt Arsenault
20902f0b72
ValueTracking: Teach computeKnownFPClass to look at bitcast + integer max (#184073)
The returned class will still be one of the bitpatterns.

This pattern is used in rocm device libraries in assorted functions,
e.g.,

https://github.com/ROCm/llvm-project/blob/amd-staging/amd/device-libs/ocml/src/rlen3F.cl#L20

I believe it is blocking the eliminationg of finite checks in some of
the more complex functions.
2026-03-04 19:06:47 +00:00
Matt Arsenault
d9d6b16cc6
ValueTracking: Handle ConstantDataSequential in computeKnownFPClass (#184191) 2026-03-04 17:43:08 +00:00
Matt Arsenault
b9f1199581
InstCombine: Support extractvalue in SimplifyDemandedFPClass (#184171)
Previously this only handled extractvalue of frexp.
2026-03-04 17:52:42 +01:00
Florian Hahn
c370f5af6c
[VPlan] Preserve IsSingleScalar for hoisted predicated load. (#184453)
The predicated loads may be single scalar (e.g. for VF = 1). We should
preserve IsSingleScalar when hoisting them. As all loops access the same
address, IsSingleScalar must match across all loads in the group.

This fixes an assertion when interleaving-only with hoisted loads.

Fixes https://github.com/llvm/llvm-project/issues/184372

PR: https://github.com/llvm/llvm-project/pull/184453
2026-03-04 14:32:00 +00:00
Benjamin Maxwell
c6bb6a7e42
[LV] Add -force-target-supports-masked-memory-ops option (#184325)
This can be used to make target agnostic tail-folding tests much less
verbose, as masked loads/stores can be used rather than scalar
predication.
2026-03-04 13:36:29 +00:00
Graham Hunter
98ed41718b
[LV] Transform tests for early-exit with stores (#183288)
Precommit of transform tests for #178454
2026-03-04 13:04:05 +00:00
Graham Hunter
943eb6fd95
[LV] Use make_early_inc_range in handleFindLastReductions (#184340)
Fixes #182152
2026-03-04 11:28:56 +00:00
Mirko Brkušanin
d0f50d5574
[AMDGPU] Remove DX10_CLAMP and IEEE bits from gfx1170 (#182107)
Add `DX10ClampAndIEEEMode` feature and set it for every subtarget prior
to gfx1170
2026-03-04 12:16:41 +01:00
Antonio Frighetto
e7db3f1d3d
[DSE] Handle provenance when eliminating tautological assignments
Similarly to what already being done in GVN (fb632ed2377d280b581b8d4653b855e60d611f77),
when a dominating equality condition of two pointers holds, and the
value being stored is implied by such a condition, ensure the store
may be removed by leveraging `canReplacePointersIfEqual`, subject to
the known approximations.

Fixes: https://github.com/llvm/llvm-project/issues/184088.
2026-03-04 10:35:52 +01:00
Kiva
b86f24fd0e
[InstCombine] make foldBinOpIntoSelectOrPhi fold on all operands (#183692)
This PR makes `foldBinOpIntoSelectOrPhi` fold to select/phi both for
operands 0 and 1.

Alive2: https://alive2.llvm.org/ce/z/T56TMM
Also fixes #183498
2026-03-04 10:23:57 +01:00
Nikita Popov
deb70a6d64
[InstCombine] Don't strip leading zero index for overaligned vector GEP (#184364)
In this case the stride is not equal to the type alloc size.

Fixes issue reported in:
https://github.com/llvm/llvm-project/pull/180745#discussion_r2860093376
2026-03-04 08:57:27 +01:00
Madhur Amilkanthwar
f5f0930c47
[GVN] Fix crash when svcount is used with globals-aa (#184347)
When -globals-aa is used, `analyzeLoadAvailiability` calls
`analyzeLoadClobberringStore` which in turn calls
`isFirstClassAggregateOrScalableType` which is using
`isa<ScalableVectorType>`. Ideally it should use type's isScalableType()
method.

The crash does not occur when default (BasicAA) is used because
`analyzeLoadAvailiability` function does not take the load clobbering
path as BasicAA returns `Def`.

Fixes #159368
2026-03-04 10:54:16 +05:30
Yoonseo Choi
fdc4a982f5
[AMDGPU] Add dereferenceable retAttr to a call to llvm.amdgcn.implicitarg.ptr (#182206) 2026-03-03 21:58:12 +01:00
Florian Hahn
bbde3e3b59
[VPlan] Preserve IsSingleScalar for sunken predicated stores. (#184329)
The predicated stores may be single scalar (e.g. for VF = 1). We should
preserve IsSingleScalar. As all stores access the same address,
IsSingleScalar must match across all stores in the group.

This fixes an assertion when interleaving-only with sunken stores.

Fixes https://github.com/llvm/llvm-project/issues/184317

PR: https://github.com/llvm/llvm-project/pull/184329
2026-03-03 14:08:00 +00:00
Lewis Crawford
fa6eef8378
Revert "Avoid maxnum(sNaN, x) optimizations / folds (#170181)" (#184125)
This reverts commit ea3fdc5972db7f2d459e543307af05c357f2be26.

Re-enable const-folding for maxnum/minnum in the middle-end, GlobalISel,
and SelectionDAG.

Re-enable optimizations that depend on maxnum/minnum sNaN semantics in
InstCombine and DAGCombiner.

Now that maxnum(x, sNaN) is specified to non-deterministically produce
either NaN or x, these constant-foldings and optimizations are now valid
again according to the newly clarified semantics in #172012 .
2026-03-03 12:45:26 +00:00
David Sherwood
0b36d4265e
[AArch64] Add vector expansion support for ISD::FCBRT when using ArmPL (#183750)
This patch teaches the backend how to lower the FCBRT DAG node to the
vector math library function when using ArmPL. This is similar to what
we already do for llvm.pow/FPOW, however the only way to expose this is
via a DAG combine that converts

  FPOW(<2 x double> %x, <2 x double> <double 1.0/3.0, double 1.0/3.0>)

into

  FCBRT(<2 x double> %x)

when the appropriate fast math flags are present on the node. I've
updated the DAG combine to handle vector types and only perform the
transformation if there exists a vector library variant of cbrt.
2026-03-03 10:39:21 +00:00
Gergo Stomfai
eb1e808fdb
[IR] Mark reduction intrinsics as nocreateundeforpoison (#184173)
In investigating #156233, it came up that select folds like here:
https://alive2.llvm.org/ce/z/Y6jzj6 cannot be carried out, or easily
fixed for now, because integer reductions do not propagate noundef, even
if their arguments are noundef. This patch adds this propagation.
2026-03-03 09:51:12 +01:00
Jameson Nash
6719ec1e95
[Coroutines] Replace struct alloca frame with byte array and ptradd (#178359)
Replace coroutine frame struct type with a simple byte array and use
offset-based ptradd operations instead of struct GEP for all field
access. Alloca types have largely lost all meaning to LLVM (even this
pass merged them and used an arbitrary type to represent all of them),
and so they just makes the code to construct alloca more difficult and
less flexible.

Key changes:
- Remove LayoutFieldIndex from frame field tracking
- Remove StructType usage - frame is now a byte array
- Replace all CreateStructGEP/CreateConstInBoundsGEP with CreatePtrAdd
- Store ResumeOffset/DestroyOffset in SwitchLowering for reuse
- Remove Shape.FrameTy, use Shape.FrameSize directly

Bug fix: Uses pointer size and alignment from data layout for header
pointer offsets in debug info instead of hardcoded 8 byte.

Optimization: Replaces load+store patterns with CreateMemCpy for copying
allocas to the frame more efficiently.

Optimization: Add missing inbounds annotations on existing ptradd calls.

Improvement: Preserve debug info of every alloca, even overlapping ones.

The frame type is now completely opaque at the IR level. All structure
is implicit through computed offsets. Debug info still provides detailed
field information using explicit offsets.

See further information in dependent PR
https://github.com/llvm/llvm-project/pull/178358 as well.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-02 17:45:15 -05:00
Florian Hahn
526a4d4d8a
[LAA] Always use DepCands when grouping runtime checks. (#91196)
Update groupChecks to always use DepCands to try and merge runtime
checks. DepCands contains the dependency partition, grouping together
all accessed pointers to he same underlying objects.

If we computed the dependencies, We only need to check accesses to the
same underlying object, if there is an unknown dependency for this
underlying object; otherwise we already proved that all accesses withing
the underlying object are safe w.r.t. vectorization and we only need to
check that accesses to the underlying object don't overlap with accesses
to other underlying objects.

To ensure runtime checks are generated for the case with unknown
dependencies, remove equivalence classes containing accesses involved in
unknown dependencies.

This reduces the number of runtime checks needed in case non-constant
dependence distances are found, and is in preparation for removing the
restriction that the accesses need to have the same stride which was
added in https://github.com/llvm/llvm-project/pull/88039.

PR: https://github.com/llvm/llvm-project/pull/91196
2026-03-02 21:30:15 +00:00
Igor Kirillov
41fc9b9845
[LAA] Fix recordAnalysis receiving null Instruction pointer (#183512)
When a memory-reading or memory-writing instruction is not a
LoadInst/StoreInst, the dyn_cast to Ld/St returns nullptr, which is then
passed to recordAnalysis. This causes the optimization remark to fall
back to the loop header location instead of pointing at the actual
problematic instruction.

Pass &I (the actual Instruction) instead.
2026-03-02 17:00:29 +00:00
lijinpei-amd
dfcbf6c70e
[CVP] Stop CVP constant propagation from destroying llvm.assume (#183688)
For following code sequence:
```
  %cmp = icmp ugt i64 %idx, 1
  tail call void @llvm.assume(i1 %cmp)
```
CVP may replace all use of `%cmp` with `true`, and the information about
`%idx` is lost. This commit stop CVP from doing that, so that later pass
can exploit the `llvm.assume`.

Fixes https://github.com/llvm/llvm-project/issues/90206.
2026-03-02 14:55:43 +00:00
Nikolas Klauser
ce79fb3712
[InstCombine] Always fold nonnull assumptions into operand bundles (#169923)
Fixes #168688
2026-03-02 13:58:08 +01:00
Jan Patrick Lehr
60fec80bdc
Revert "[VPlan] Remove unused VPExpandSCEVRecipe before expansion" (#184108)
Reverts llvm/llvm-project#181329

Breaks: https://lab.llvm.org/buildbot/#/builders/123/builds/36163
Local revert fixes the issue seen in the buildbot.
2026-03-02 12:45:48 +00:00
Ricardo Jesus
6cce18b9f5
[LoopIdiomVectorize] Avoid wrapping in find_first_of loops. (#180570)
As noted in
https://github.com/llvm/llvm-project/pull/179298#discussion_r2757948654,
use integer induction variables to avoid potential pointer wrap.
2026-03-02 11:04:40 +00:00
David Sherwood
13751c8707
[AArch64] Vectorise llvm.pow using vector intrinsic for ArmPL library (#183319)
When vectorising loops containing calls to the llvm.pow intrinsic we
currently end up with direct calls to the vector math library equivalent
of llvm.pow. This causes problems later on because we then miss out on
optimisations in the backend for things like

  pow(x, 0.25)
  pow(x, 0.75)
  etc.

There are a few different ways of trying to solve this, but I think the
cleanest way is to leave the call in the intrinsic form and then teach
the backend how to lower the FPOW DAG node to the vector math library
function. This is similar to what we already do for llvm.sincos/FSINCOS
today.

I've done this by removing the entries in Analysis/VecFuncs.def that map
the intrinsic to the vector math functions, whilst also teaching the
cost model that the vector intrinsic form of llvm.pow is cheap in the
presence of the library.
2026-03-02 10:34:11 +00:00
Nikita Popov
3ad43f2d1c
[LangRef] Clarify nsz semantics (#180906)
The current LangRef wording says that the sign of a zero argument or
result is "insignificant", which is not really clear on what this means.

Alive2 models this as non-deterministically flipping the zero sign bits
for both inputs and outputs.

This PR proposes to specify this flag as non-deterministically flipping
inputs only. A consequence of this is that fabs is guaranteed to have an
unset sign bit even if the input is zero (that is,
https://alive2.llvm.org/ce/z/irCftQ is no longer a valid transform), and
that the copysign result sign only depends on the second operand (that
is, https://alive2.llvm.org/ce/z/VnHdfh is no longer a valid transform).

These rules are still more liberal than we'd really like them to be, but
at least avoid some of the issues with nsz.

This is based on the discussion in:
https://discourse.llvm.org/t/rfc-clarify-the-behavior-of-fp-operations-on-bit-strings-with-nsz-flag/85981
2026-03-02 10:53:07 +01:00
Mel Chen
c62c00c524
[VPlan] Remove unused VPExpandSCEVRecipe before expansion (#181329)
VPExpandSCEVRecipe may become unused after VPlan optimizations. This
patch removes VPExpandSCEVRecipes with no users before expansion in
expandSCEVs, avoiding generating dead code during VPlan execution.
2026-03-02 09:04:59 +00:00
Mel Chen
f7b1107bf5
[IVDescriptors] Remove function FMF attribute check for FP min/max reduction (#183523)
Remove the use of function attributes no-nans-fp-math and
no-signed-zeros-fp-math in FP min/max reduction detection. The required
fast-math flags nnan and nsz should be present on the intrinsic calls,
fcmp and select instructions themselves.
2026-03-02 08:31:46 +00:00
Tomer Shafir
265c1f4833
[LV] Add debug print for TTI.MaxInterleaveFactor (NFC) (#183309)
As its not currently visible in the debug output.

---------

Co-authored-by: Sander de Smalen <sander.desmalen@arm.com>
2026-03-02 10:21:58 +02:00
Ruiling, Song
686987a540
ValueTracking/AMDGPU: handle mbcnt in computeKnownBitsFromOperator (#183229)
This helps canonicalize some address calculation. This would further
help immediate folding into memory load instructions in the backend.

The order changes to v_mad_u32_u24 is just because
@llvm.amdgcn.mul.u24.i32 was used in codegen prepare after this change.
It does not really change anything important.
2026-03-02 10:48:15 +08:00
Alexey Bataev
789bf51f0c [SLP]Do not consider condition with multiple uses and negate predicate as a candidate for inversed select
If the select/zext comparison has negate predicate and is used in
several places, it should not be considered as a candidate for inversed
zext/select pattern, it will be replaced by a negate vector predicate,
leading to an incorrect codegen for other uses
2026-03-01 12:01:19 -08:00
Alexey Bataev
d1d2a1ed76 [SLP][NFC]Add a test with the incorrect compare, extracted from the transformed vector 2026-03-01 11:44:55 -08:00
Florian Hahn
3cf53f684d
[LV] Handle sunk reverse VPInstruction in planContainsAdditionalSimps.
Licm can now sink reverse VPInstructions outside the loop region; they
won't be considered when computing costs. Account for that in
planContainsAdditionalSimplifications.

Fixes https://github.com/llvm/llvm-project/issues/183592.
2026-03-01 18:44:46 +00:00
Alexey Bataev
a13afe84bb [SLP][NFC]Add more bitcast/bswap tests with immediate loads, NFC 2026-03-01 10:17:09 -08:00
Alexey Bataev
02c7a6cd7f [SLP][NFC]Add tests for bitcasts/bswaps with large target type 2026-03-01 09:02:04 -08:00
Florian Hahn
320220e48b
[VPlan] Support arbitrary predicated early exits. (#182396)
This removes the restriction requiring a single predicated early exit.
Using MaskedCond, we only combine early-exit conditions with block
masks from non-exiting control flow.

This means we have to ensure that we check the early exit conditions in
program order, to make sure we take the first exit in program order that
exits at the first lane for the combined exit condition.

To do so, sort the exits by their reverse post-order numbers.

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

PR: https://github.com/llvm/llvm-project/pull/182396
2026-03-01 16:07:05 +00:00
Alexey Bataev
9730d31284 [SLP]Fix types for reductions in revec
Need to consider vector inputs, when building casts for the reduced
values

Fixes #170828
2026-03-01 07:54:13 -08:00