206171 Commits

Author SHA1 Message Date
Yury Plyakhin
81f445b7df
[clang-sycl-linker][offload] Set TheImageKind based on IsAOTCompileNeeded flag (#180269)
Previously, TheImageKind was set to IMG_None and relied on a runtime
heuristic to determine the correct image type. This commit sets it
explicitly to IMG_Object for AOT-compiled images and IMG_SPIRV for
SPIR-V images based on the IsAOTCompileNeeded flag.

Also it adds test for this change, which required minor changes in
OffloadBinary and OffloadDump.
2026-02-11 10:21:22 -08:00
Justin Fargnoli
45412b6790
[LoopUnrollPass] Indent LLVM_DEBUG() messages based on our depth in the tryToUnrollLoop() call graph (#178945)
Unify the ad-hoc use of whitespace in `LLVM_DEBUG()` messages. 

This approach should also make it easier to see which loop debug
messages correspond to and which part of the loop unrolling heuristics
each message corresponds to.
2026-02-11 17:59:42 +00:00
vangthao95
90a56a18ee
AMDGPU/GlobalISel: RegBankLegalize for global atomic ordered add (#180829) 2026-02-11 09:30:11 -08:00
Simon Pilgrim
182eb9d21a
[X86] Move getTargetVShift helpers earlier in the source file. NFC. (#180972)
Avoid having to add forward declarations for earlier functions to use them.
2026-02-11 17:19:32 +00:00
vangthao95
0286641f5c
[AMDGPU] Add known bits for G_AMDGPU_COPY_SCC_VCC (#180560) 2026-02-11 09:06:28 -08:00
Folkert de Vries
6a81656f7d
[RISCV] improve musttail support (#170547)
Basically https://github.com/llvm/llvm-project/pull/168506 but for
riscv, so to be clear the hard work here is @heiher 's. I figured we may
as well get some extra eyeballs on this from riscv too.

Previously the riscv backend could not handle `musttail` calls with more
arguments than fit in registers, or any explicit `byval` or `sret`
parameters/return values. Those have now been implemented.

This is part of my push to get more LLVM backends to support `byval` and
`sret` parameters so that rust can stabilize guaranteed tail call
support. See also:

- https://github.com/llvm/llvm-project/pull/168956
- https://github.com/rust-lang/rust/issues/148748

---------

Co-authored-by: WANG Rui <wangrui@loongson.cn>
2026-02-11 17:27:51 +01:00
Florian Hahn
54177e95d1
[Matrix] Use tiled loops automatically for large kernels. (#179325)
Update LowerMatrixIntrinsics to use tiled loops automatically in for
larger matrixes. The fully unrolled codegen creates a huge amount of
code, which performs noticably worse then the tiled loop nest variant.

We new try to estimate the number of instructions needed for the
multiply, and if it is too large, tiled loops are used. The current
threshold is anything roughly larger than 6x6x6 double multiply.

Eventually I think we want to only generate tiled loops. This patch is a
first step, trying to opt in for cases where we know it is beneficial.
Checked on AArch64, but should help on other architectures similarly,
and also drastically reduce binary size + compile time.

PR: https://github.com/llvm/llvm-project/pull/179325
2026-02-11 15:36:34 +00:00
Nikita Popov
a8f211904a
[ExpandIRInsts] Support saturating fptoi (#179710)
Add support for expanding fptosi.sat and fptoui.sat via IR expansions.
Similar to fptosi/fptoui we would get legalization errors otherwise.

The previous expansion for fptosi/fptoui was already saturating -- but
those instructions do not actually require saturation, and the
implementation of the saturation was incorrect in lots of ways. What
this PR does is:

* For fptosi, remove the unnecessary saturation handling.
* For fptoui, remove the unnecessary saturation handling and sign
multiplication.
* For fptosi, use the previous saturation handling with fixes: We need
to map NaNs to 0 and the saturation condition on the exponent was
incorrect. (I'm performing the NaN check via fcmp -- there's no
requirement to do everything bitwise here.)
* For fptoui use a variation of the signed saturation handling: Negative
values need to go to zero and we saturate to unsigned max.

Proofs: https://alive2.llvm.org/ce/z/Xv9FNd
2026-02-11 14:51:30 +01:00
Tomer Shafir
5456d6352a
[AArch64] Lower factor-of-2 interleaved stores to STNP (#177938)
This patch prioritizes lowering to `stnp` over `st2` store instructions
marked !nontemporal.

From performance perspective, we should conservatively prioritize STNP
lowering for non-temporal stores, because currently NT stores requires
explicit usage of `__builtin_nontemporal_store()` intrinsic, so I think
its reasonable to assume the developer explicitly intends to optimize
D-cache usage of some hot non-temporal execution. He can rollback if it
doesnt help.

The cost here is it adds a few instructions for code size (thus we
predicate when not optimizing for code size), few extra fast
instructions to execute, few extra short dep chains - should be commonly
handled by OOO execution, I-cache alignment effects, few extra
registers. In the future we can may be able to approximate a cost model
to select by.

The patch implements an AArch64 specific static function to model what
NT stores are directly legal on the backend currently, and
`AArch64TargetLowering::lowerInterleavedStore` to conditionally skip st2
lowering.
2026-02-11 15:37:13 +02:00
Juan Manuel Martinez Caamaño
7f2b875c7d
[SPIRV] Replace SPIRVType with SPIRVTypeInst as much as we can (#180721)
Second part of https://github.com/llvm/llvm-project/pull/179947 where we
use `SPIRVTypeInst` as much as we can.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-11 14:05:08 +01:00
Alexey Bataev
54cdd903b8 [SLP]Skip operands comparing on non-matching (but compatible) instructions
If the instructions are compatible but non-matching (zext-select pair as
example), no need to perform operands analysis, just return that they
are matching.
2026-02-11 04:55:29 -08:00
Florian Hahn
2dcf858ba0
[LAA] Use SCEVPtrToAddr in tryToCreateDiffChecks. (#178861)
The checks created by LAA only compute a pointer difference and do not
need to capture provenance. Use SCEVPtrToAddr instead of SCEVPtrToInt
for computations.

To avoid regressions while parts of SCEV are migrated to use PtrToAddr
this adds logic to rewrite all PtrToInt to PtrToAddr if possible in the
created expressions. This is needed to avoid regressions.

Similarly, if in the original IR we have a PtrToInt, SCEVExpander tries
to re-use it if possible when expanding PtrToAddr.

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

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

PR: https://github.com/llvm/llvm-project/pull/178861
2026-02-11 11:51:51 +00:00
Juan Manuel Martinez Caamaño
77513e7d74
[SPIRV] Add a SPIRVTypeInst type with some guardrails (#179947)
The idea behind this PR is to propose a type that we can deploy
gradually to add some guardrails and enforce invariants in the SPIRV
backend.

The PR has 3 commits:
* A first commit where the `SPIRVTypeInst` type is proposed. It's just a
wrapper around `MachineInstr` that adds an assert to check that a
`SPIRVTypeInst` defines a register with the type register class.
* A second commit that shows how the migration could look like for a
single function.
* A third commit that motivates why: we have a `SPIRVType *TypeInst`
that never defines a type in a function whose intention looks very
confusing.
2026-02-11 12:30:42 +01:00
Ricardo Jesus
eed35c9e7f
[AArch64] Avoid selecting XAR for reverse operations. (#178706)
Rotations that implement reverse operations, for example:
```c
uint64x2_t foo(uint64x2_t r) {
  return (r >> 32) | (r << 32);
}
```
Are currently lowered as XAR (when available):
```gas
foo:
  movi    v1.2d, #0000000000000000
  xar     v0.2d, v0.2d, v1.2d, #32
  ret
```
This is suboptimal as REV* instructions typically have higher throughput
than XAR and do not require the zero operand.

This patch combines half-rotations to Neon or SVE REVs so that they're
no longer selected as XAR.
2026-02-11 11:18:55 +00:00
Pengcheng Wang
e84659b71b
[RISCV][CodeGen] Combine vwaddu+vabd(u) to vwabda(u)
Note that we only support SEW=8/16 for `vwabda(u)`.

Reviewers: topperc, lukel97, preames

Reviewed By: topperc, lukel97

Pull Request: https://github.com/llvm/llvm-project/pull/180162
2026-02-11 18:53:29 +08:00
David Sherwood
6f0b8a7ebc
[SLP] Use the correct calling convention for vector math routines (#180759)
When vectorising calls to math intrinsics such as llvm.pow we
correctly detect and generate calls to the corresponding vector
math variant. However, we don't pick up and use the calling
convention for the vector math function. This matters for veclibs
such as ArmPL where the aarch64_vector_pcs calling convention
can improve codegen by reducing the number of registers that
need saving across calls.
2026-02-11 10:52:58 +00:00
Anshil Gandhi
4f551b55ae
[IndVarSimplify] Add safety check for getTruncateExpr in genLoopLimit (#172234)
getTruncateExpr may not always return a SCEVAddRecExpr when truncating
loop bounds. Add a check to verify the result type before casting, and
bail out of the transformation if the cast would be invalid.

This prevents potential crashes from invalid casts when dealing with
complex loop bounds.

Co-authored by Michael Rowan

Resolves [#153090](https://github.com/llvm/llvm-project/issues/153090)
2026-02-11 10:08:41 +00:00
Jim Lin
6b6efcd743
[RISCV] Add sp register as implicit/implicit-def register to save/restore call (#180667)
This is a follow-up PR for
https://github.com/llvm/llvm-project/pull/180133.
2026-02-11 17:17:12 +08:00
Jim Lin
c3b6f14a89
[RISCV] Remove explicitly adding spilled registers as liveins. (#180483)
We didn't explicitly add spilled registers as liveins for CM_PUSH as
well. The liveins of the basic block will be updated by updateLiveness
in PrologEpilogInserter.
2026-02-11 17:16:38 +08:00
Luke Lau
cd2761f7ab
[RISCV] Remove vp.reverse mask check in performVP_REVERSECombine (#180724)
Similar to #180706, the masked off lanes in vp.reverse are poison so can
be replaced with anything. Because of this, we should be able to fold a
masked vp.reverse(vp.load) into a vp.strided.load stride=-1 even when
the mask isn't all ones.
2026-02-11 09:13:42 +00:00
Ben Dunbobbin
8b57b97302
[DTLTO][NFC] Minor improvements to the input file preparation class (#180824)
This change performs a small set of NFC refactors to improve clarity. In
particular, we make it clear that the responsibilities of this class now
extend beyond its original archive-handling role.
2026-02-11 09:02:19 +00:00
Luke Lau
ffe446e734
[RISCV] Relax reversed mask's mask requirement in reverse to strided load/store combine (#180706)
We have combines for vp.reverse(vp.load) -> vp.strided.load stride=-1
and vp.store(vp.reverse) -> vp.strided.store stride=-1.

If the load or store is masked, the mask needs to be also a vp.reverse
with the same EVL. However we also have the requirement that the mask's
vp.reverse is unmasked (has an all-ones mask).

vp.reverse's mask only sets masked off lanes to poison, and doesn't
affect the permutation of elements. So given those lanes are poison, I
believe the combine is valid for any mask, not just all ones.

This is split off from another patch I plan on posting to generalize
those combines to vector.splice+vector.reverse patterns, as part of
#172961
2026-02-11 16:43:02 +08:00
yingopq
1e42c76d61
[Mips] Fix cttz.i32 fails to lower on mips16 (#179633)
MIPS16 cannot handle constant pools created by CTTZ table lookup
expansion. This causes "Cannot select" errors when trying to select
MipsISD::Lo nodes for constant pool addresses.
    
Modify the table lookup conditions to check ConstantPool operation
status, and only set ConstantPool to Custom in non-MIPS16 mode in MIPS
backend.
    
This ensures MIPS16 uses the ISD::CTPOP instead of attempting
unsupported constant pool operations.

Fix #61055.
2026-02-11 16:27:57 +08:00
JaydeepChauhan14
7353ca74ad
[NFC][TableGen] Use std::move to avoid copy (#180785) 2026-02-11 13:45:24 +05:30
Matt Arsenault
17a9170a7e
InstCombine: Fix wrong insert point for sqrt -> copysign simplify (#180838) 2026-02-11 09:15:11 +01:00
Matt Arsenault
bd4fe78c84
InstCombine: Fix wrong insert point for various fmul->copysign simplifies (#180840) 2026-02-11 09:14:55 +01:00
Matt Arsenault
8503cb6ad5
InstCombine: Fix wrong insert point for fdiv->copysign simplify (#180839) 2026-02-11 09:14:39 +01:00
Matt Arsenault
1f0577836c
InstCombine: Fix insert point for rounding intrinsic -> copysign (#180837)
This would use the wrong insert point if reached in a recursive
call.
2026-02-11 09:14:12 +01:00
Nikita Popov
ad1e107a8c
[PowerPC] Require PPC32 for 32-bit addc/adde/subc/sube (#179186)
Unlike the base add/sub opcodes which will just overflow, these will
produce incorrect results, because the carry operates on the full
64-bits. Trying to use these with i32 operands on PPC64 should result in
a selection failure instead of a silent miscompile, like the one seen in
https://github.com/llvm/llvm-project/pull/178979.
2026-02-11 09:06:03 +01:00
fogsong233
680124ca9a
[Option] Fix param name mismatch & coding style (NFC) (#180746)
Align parameter names between the declaration and
definition in Option.cpp.
Also, update variable names to adhere to the LLVM
Coding Standards regarding casing.
See
6c0ff8d12f/llvm/include/llvm/Option/Option.h (L242).

However the defination is:

6c0ff8d12f/llvm/lib/Option/Option.cpp (L112-L114)
2026-02-11 15:01:29 +07:00
Sameer Sahasrabuddhe
128437fb6a
[AMDGPU] Introduce asyncmark/wait intrinsics (#180467)
Asynchronous operations are memory transfers (usually between the global
memory and LDS) that are completed independently at an unspecified
scope. A thread that requests one or more asynchronous transfers can use
async marks to track their completion. The thread waits for each mark to
be completed, which indicates that requests initiated in program order
before this mark have also completed.

For now, we implement asyncmark/wait operations on pre-GFX12
architectures that support "LDS DMA" operations. Future work will extend
support to GFX12Plus architectures that support "true" async operations.

This is part of a stack split out from #173259
- #180467
- #180466

Co-authored-by: Ryan Mitchell ryan.mitchell@amd.com

Fixes: SWDEV-521121
2026-02-11 07:15:51 +00:00
Kyungtak Woo
70b96befd8
[NewPM] Port x86-insert-x87-wait (#180128)
Similar to other portings created by @aidenboom154. No specific test
coverage as there are no MIR->MIR tests that exercise this pass. Going
with other naming conventions, I renamed WaitInsert to
X86InsertX87WaitLegacy
2026-02-10 22:58:02 -08:00
Sam Elliott
0d08cb0e70
[outliners] Turn nooutline into an Enum Attribute (#163665)
This change turns the `"nooutline"` attribute into an enum attribute
called `nooutline`, and adds an auto-upgrader for bitcode to make the
same change to existing IR.

This IR attribute disables both the Machine Outliner (enabled at Oz for
some targets), and the IR Outliner (disabled by default).
2026-02-10 21:44:17 -08:00
Sameer Sahasrabuddhe
b02b395a1e
[AMDGPU] Asynchronous loads from global/buffer to LDS on pre-GFX12 (#180466)
The existing "LDS DMA" builtins/intrinsics copy data from global/buffer
pointer to LDS. These are now augmented with their ".async" version,
where the compiler does not automatically track completion. The
completion is now tracked using explicit mark/wait intrinsics, which
must be inserted by the user. This makes it possible to write programs
with efficient waits in software pipeline loops. The program can now
wait for only the oldest outstanding operations to finish, while
launching more operations for later use.

This change only contains the new names of the builtins/intrinsics,
which continue to behave exactly like their non-async counterparts. A
later change will implement the actual mark/wait semantics in
SIInsertWaitcnts.

This is part of a stack split out from #173259:
- #180467
- #180466

Fixes: SWDEV-521121
2026-02-11 05:26:58 +00:00
Sam Elliott
ab33f1e427
[IROutliner] Add TTI Hook for Propagating Attributes (#153985)
On RISC-V, the interrupt attribute relates only to the prolog and epilog
of the attributed function (and has specific restrictions on the
function's signature). It does not change how that function calls other
functions, and when outlining, the outlined function must not have this
attribute.

This adds a target-independent hook to TTI so targets can choose which
attributes to propagate (by default all are propagated).

Fixes #149969
2026-02-10 19:49:16 -08:00
Anshul Nigham
ac85248f11
[NewPM] Port x86-winehstate (#180687)
x86-winehstate has been converted to a module pass for NewPM since it
uses data from the Module by overriding `doInitialization` and
`doFinalization`.
2026-02-10 18:50:34 -08:00
woruyu
1094775692
[X86] Fix lower1BitShuffle blend-with-zero shuffles to AND mask (#180472)
### Summary
This PR resolves https://github.com/llvm/llvm-project/issues/180426.
2026-02-11 09:49:29 +08:00
Mitchel Dickerson
f932646bf6
[SimplifyCFG][PGO] Add missing overflow check to ConstantFoldTerminator (#178964)
Branch weight metadata can overflow when folding large branch weights.
Updated branch weights to uint64_t, added check for overflow, and then
set branch weights using setFittedBranchWeights to ensure branch weight
metadata is not lost.
2026-02-11 01:17:12 +00:00
Ben Langmuir
59bcec2685
[llvm][cas] Validate OnDiskKeyValueDB against the corresponding OnDiskGraphDB (#180852)
We were previously using the primary OnDiskGraphDB when validating the
upstream OnDiskKeyValueDB, which is incorrect since the values being
stored are direct offsets and therefore cannot be used across DBs
without translating to a hash value first.

rdar://170067863
2026-02-10 15:38:31 -08:00
Alexander Weinrauch
979132a02d
[AMDGPU] Fix LDS address correction in promoteConstantOffsetToImm for async stores (#180220)
`updateAsyncLDSAddress`, introduces by
https://github.com/llvm/llvm-project/pull/176816, previously only
handled async loads , where the LDS address is in the `vdst` operand.
Therefore Async stores produced a nullptr dereference since the LDS
address is in `vdata` for those instructions.

---------

Co-authored-by: Jay Foad <jay.foad@gmail.com>
2026-02-10 13:53:51 -08:00
Alexander Weinrauch
1e086d06e9
[DAGCombiner] Fix crash in reassociationCanBreakAddressingModePattern for multi-memop nodes (#180268)
Two code paths in `reassociationCanBreakAddressingModePattern` were
missing a `hasUniqueMemOperand()` guard before calling
`getAddressSpace()`. Note that on `L1214` we already have the same guard
in place.

`getAddressSpace()` chains through `getPointerInfo()` to
`getMemOperand()`, which asserts that the node has exactly one memory
operand.
2026-02-10 13:53:36 -08:00
Craig Topper
31e1bcfd09
[RISCV] Add basic scalar support for MERGE, MVM, and MVMN from P extension (#180677)
These are 3 variations of the same operation with a different operand
tied to the destination register. We need to pick the one that
minimizes the number of mvs.

To do this we take the approach used by AArch64 to select between
BIT, BIF, and BSL which the same operations. We define a pseudo
with no tied constraint and expand it after register allocation based
on where the destination register ended up. If the destination
register is none of the operands, we'll insert a mv.

I've replaced RISCVISD::MVM with RISCVISD::MERGE and updated the operand
order accordingly. I find the MERGE name easier to read so I've made it
the canonical name.

Ideally we could use commuteInstructionImpl and the
TwoAddressInstructionPass
to select the opcode before register allocation. That only works if
you can commute exactly 2 operands and maybe change the opcode in the MI
representation of any of the forms to get to the either of the other 2
forms.
That is not possible. We'd need to define 3 more pseudoinstructions
with different permutations.

With the current approach it might be possible that we insert a mv
not because all of the operand registers we needed by later
instructions,
but because the register allocator needed to put the result in a
different register. It's possible a different allocation for other
instructions might have avoided the mv.

I wrote the patch based on the AArch64, but the tests were generated
by AI.
2026-02-10 13:39:34 -08:00
Faijul Amin
643c235694
[SPIRV] Legalize extended integers for compare instructions. (#180254)
Currently, legalization fails for integer (lower than 8 bit) comparison
with extensions, for example, SPV_INTEL_int4. This PR extends integers
for supported extensions.

---------

Co-authored-by: Michal Paszkowski <michal@michalpaszkowski.com>
2026-02-10 13:29:25 -08:00
Florian Hahn
61521a94af
[VPlan] Ensure countable region in narrowInterleaveGroups.
This tightens the legality checks. Currently should not have any impact,
but is needed to avoid mis-compiles in follow-up changes.
2026-02-10 21:24:54 +00:00
Florian Hahn
a1fc5b4a48
[VPlan] Reject partial reductions with invalid costs in getScaledReds. (#180438)
Check if costs for partial reductions are valid up-front in
getScaledReductions instead when transforming each link in the chain in
transformToPartialReduction. This ensures that we either transform all
entries in the chain together, or none via the existing invalidation
logic.

This fixes a crash when a link in the chain would have invalid cost, as
in the added test cases.

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

PR: https://github.com/llvm/llvm-project/pull/180438
2026-02-10 21:16:21 +00:00
Matt Arsenault
7f9965c73d
InstCombine: Fix broken insert point for fdiv replacement (#180830)
SimplifyDemandedFPClass isn't properly adjusting the IRBuilder
insert point, so this could insert at the wrong point if the
simplification happens in one of the recursive calls. There are a few
more of these to fix.
2026-02-10 21:15:58 +00:00
Sam Elliott
49c052363b
[RISCV] Use ADDD for GPR Pair Move with P (#180671) 2026-02-10 12:59:06 -08:00
Alexey Bataev
78490acb32 [SLP]Support for zext i1 %x modeling as select %x, 1, 0
Model zext i1 %x to in as select i1 %x, in 1, in 0 in case, if there are
other select instructions, which can be combined into a bundle.

Fixes #178403

Recommit after revert in 993e1f66afcfe9da03bd813e669eada341b11d2f

Reviewers: hiraditya, RKSimon

Pull Request: https://github.com/llvm/llvm-project/pull/180635
2026-02-10 12:54:12 -08:00
Stanislav Mekhanoshin
058cad9f82
Add "noconvergent" flag to MachineInstr::print() (#180818) 2026-02-10 12:37:40 -08:00
Craig Topper
f134b802ee
[RISCV] Refactor the MC layer SiFive VCIX classes. (#180433)
My initial goal was to name bits {19-15} as either rs1, vs1, or imm as
appropriate.

The VCIX instructions effectively have 3 properties that are combined:
the type of bits 19-15 (determined by funct3), how many vector registers
are sources (determined by funct6), and whether vd is a written or not
(determined by vm).

I found the VCIXInfo class very hard to read and understand. This patch
breaks it up into simpler steps and moves some properties to flags in
the existing VCIXType classs. A new VCIXRs1Info class is added to
contain the properties for bits 19-15. The VCIXInfo now combines the
properties from these 2 classes and the HaveOutputDst flag to create the
various things needed to build the final instruction. To reduce the
number of template arguments, the VCIXInfo is passed all the way down to
the base class.

Much of the refactoring in this patch was accomplished with AI. I have
looked at the diffs in the output tablegen files to verify it works as
expected. RISCVGenInstrInfo.inc only changes line number comments.
RISCVGenDisassembler.inc doesn't change at all as expected.
RISCVGenMCCodeEmitter.inc changes due to the different field names and
orders in the record.
2026-02-10 12:34:15 -08:00