26296 Commits

Author SHA1 Message Date
Simon Pilgrim
7d2e182b04
[X86] SimplifyDemandedVectorEltsForTargetNode - add handling for vpmaddwd/vpmaddubsw/vpmulhrsw vector width reduction (#180738) 2026-02-10 14:25:40 +00:00
JaydeepChauhan14
6d5bb4def1
[X86] Fixed flags issue of onlyZeroFlagUsed (#180405)
Fixes
https://github.com/llvm/llvm-project/pull/173543#discussion_r2670058843
2026-02-10 17:53:01 +05:30
Kyungtak Woo
a56b877056
[NewPM] Port x86-global-base-reg (#180119)
Had to move X86GlobalBaseRegPass to its own file like in
https://github.com/llvm/llvm-project/pull/179864

No test coverage added for now as there are no MIR->MIR tests exercising
this pass and we do not have enough ported to run any end to end tests.

This is a redo of https://github.com/llvm/llvm-project/pull/180070
2026-02-09 22:54:41 -08:00
Simon Pilgrim
a911fc12ec
[X86] Fold expand(splat,passthrough,mask) -> select(splat,passthrough,mask) (#180238)
If all elements of the expansion vector are already splatted in place then we can use a vselect directly
2026-02-09 16:15:41 +00: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
Simon Pilgrim
964651ad51
[X86] Allow handling of i128/256/512 SELECT on the FPU (#180197)
If the scalar integer selection sources are freely transferable to the
FPU, then splat to create an allbits select condition and create a
vector select instead
2026-02-09 10:34:02 +00:00
JaydeepChauhan14
fad32ff3ea
[X86] Optimized ADC + ADD to ADC (#176713) 2026-02-09 11:43:56 +05:30
paperchalice
c53acf0443
[SelectionDAGBuilder] Remove NoNaNsFPMath uses (#169904)
Replaced by checking fast-math flags or value tracking results.
2026-02-09 09:48:07 +08:00
Folkert de Vries
0d94148b63
[X86] optimize 512-bit masked truncated saturating stores (#179130)
an oversight in https://github.com/llvm/llvm-project/pull/169827, for
the 512-bit version the `vl` target feature is not needed.


https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_mask_cvtsepi16_storeu_epi8&expand=1811&ig_expand=2150,2151
2026-02-08 12:04:16 +01:00
Ganesh
a362593e0d
[X86] AMD Zen 6 Initial enablement (#179150)
This patch adds initial support for AMD Zen 6 architecture (znver6):

- Added znver6 CPU target recognition in Clang and LLVM
- Updated compiler-rt CPU model detection for znver6
- Added znver6 to target parser and host CPU detection
- Added znver6 to various optimizer tests

znver6 features: FP16, AVXVNNIINT8, AVXNECONVERT, AVXIFMA (without BMM).
2026-02-07 09:38:10 +05:30
Peter Collingbourne
191af6c254
Add llvm.cond.loop intrinsic.
The llvm.cond.loop intrinsic is semantically equivalent to a conditional
branch conditioned on ``pred`` to a basic block consisting only of an
unconditional branch to itself. Unlike such a branch, it is guaranteed
to use specific instructions. This allows an interrupt handler or
other introspection mechanism to straightforwardly detect whether
the program is currently spinning in the infinite loop and possibly
terminate the program if so. The intent is that this intrinsic may
be used as a more efficient alternative to a conditional branch to
a call to ``llvm.trap`` in circumstances where the loop detection
is guaranteed to be present. This construct has been experimentally
determined to be executed more efficiently (when the branch is not taken)
than a conditional branch to a trap instruction on AMD and older Intel
microarchitectures, and is also more code size efficient by avoiding the
need to emit a trap instruction and possibly a long branch instruction.

On i386 and x86_64, the infinite loop is guaranteed to consist of a short
conditional branch instruction that branches to itself. Specifically,
the first byte of the instruction will be between 0x70 and 0x7F, and
the second byte will be 0xFE.

Part of this RFC:
https://discourse.llvm.org/t/rfc-optimizing-conditional-traps/89456

Reviewers: arsenm, RKSimon, fmayer, vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/177686
2026-02-06 17:11:15 -08:00
Kyungtak Woo
d64a609b2b
[NewPM] Uninitialize x86-cleanup-local-dynamic-tls in llvm/lib/Target/X86/X86.h (#180122)
I believe I exposed in
https://github.com/llvm/llvm-project/pull/179864/changes#diff-5b9707ff829bc5b6523a59982f375d99d6b4ded670fbd91dd095555f4ac80a14R428
. Getting rid of it to avoid possible undefined reference/linker errors.
2026-02-06 10:14:49 +00:00
Kyungtak Woo
4092a6398c
[NewPM] Port x86-indirect-branch-tracking (#179874)
Similar to other portings created by @aidenboom154. No specific test
coverage as there are no MIR->MIR tests that exercise this pass.
2026-02-06 07:37:58 +00:00
Simon Pilgrim
cc4b98e505
[X86] combineSetCC - attempt to match more complex icmp_eq/ne patterns before falling back to PTEST/PMOVMSKB patterns (#180034)
combineVectorSizedSetCCEquality attempts to convert equality comparisons
of larger-than-legal scalar integers to PTEST/PMOVMSKB vector
comparisons.

However, combineSetCC has a number of other folds with more complex
icmp_eq/ne patterns that work with big integers (including bit test and
reduction patterns) that don't get a change to match as
combineVectorSizedSetCCEquality is run first, and the other folds are
then more difficult to match from PTEST/PMOVMSKB nodes.

This patch moves the combineVectorSizedSetCCEquality fold later to give
other icmp_eq/ne folds a chance to run first.
2026-02-06 07:20:14 +00:00
Kyungtak Woo
eb9e98f62e
[NewPM] Port x86-cleanup-local-dynamic-tls (#179864)
Port x86-cleanup-local-dynamic-tls to the new pass manager.
I moved LDTLSCleanup to a new
llvm/lib/Target/X86/X86CleanupLocalDynamicTLS.cpp file and renamed it to
X86CleanupLocalDynamicTLSPass. Then I renamed the legacy pass, and
adding a NewPM wrapper around the impl.

No test coverage added for now as there are no MIR->MIR tests exercising
this pass and we do not have enough ported to run any end to end tests.
2026-02-06 08:31:01 +08:00
Simon Pilgrim
c662f11c7d
[X86] mayFoldIntoVector - ensure we check for custom lowering to logic/add/sub ops (#179988)
As noted on #174761 - we need to ensure custom lowering to logic/add/sub
ops might actually occur before assuming the node will have been on the
vector unit
2026-02-05 17:42:26 +00:00
Phoebe Wang
744827e22f
[X86] Fixed truncated masked stores (#179853)
Fixes: #179489
2026-02-05 21:06:17 +08:00
Simon Pilgrim
9e052debf0
[X86] lower1BitShuffle - recognise a blend shuffle that can lower to AND/MASKZ pattern (#179717)
Part of the missed-optimisation mentioned on #179630 - if the shuffle is
a blend with zero, then lower as a ISD::AND pattern
2026-02-05 09:42:31 +00:00
Anshul Nigham
34523c200b
[NewPM] Port x86-lvi-load (#179371) 2026-02-04 19:02:00 -08:00
Jay Foad
7ea33e6848
[CodeGen] Remove unused first operand of SUBREG_TO_REG (#179690)
The first input operand of SUBREG_TO_REG was an immediate that most
targets set to 0. In practice it had no effect on codegen. Remove it.
2026-02-04 17:35:21 +00:00
Islam Imad
3c0e3268a5
[X86] Lower i512 ADD/SUB using Kogge-Stone on AVX512 (#174761)
Closes #173996
2026-02-04 16:07:59 +00:00
Simon Pilgrim
0fe9454c56
[X86] Fold EXPAND(X,Y,M) -> SELECT(M,X,Y) when M is a lowest bit mask (#179630)
If a EXPAND node mask is just the lowest bits, then we can replace it
with a more general SELECT node, which can be cheaper and potentially
allow predication.

Fixes #179008
2026-02-04 11:45:13 +00:00
Shamshura Egor
280833247d
[X86] computeKnownBitsForTargetNode - extend X86ISD::BZHI handling. Fixes 177364. (#179444)
Fixes #177364
2026-02-04 10:55:23 +00:00
bala-bhargav
a631f3e434
[X86] Fold vgf2p8affineqb XOR with splat constant into immediate (#179103)
The vgf2p8affineqb instruction performs an affine transformation on each
byte and then XORs the result with an 8-bit immediate operand. When this
instruction is followed by a standalone XOR with a splatted constant,
LLVM currently generates extra instructions instead of folding the
constant into the instruction's immediate.
This PR adds a DAG combine optimization that detects the pattern
vgf2p8affineqb(x, m, imm8) ^ C where C is a splatted 8-bit constant and
transforms it to vgf2p8affineqb(x, m, imm8 ^ C), eliminating the
unnecessary XOR instruction.
- The optimization runs during the combine phase after type legalization
- Handles XOR with the constant on either side (commutative)
- Only applies when the GFNI instruction has a single use to avoid
de-optimization
- Validates that the XOR operand is a splatted 8-bit constant before
folding
- Includes test coverage for positive cases and negative cases
(multi-use, non-splat constant, variable XOR)
2026-02-04 10:11:48 +00:00
Simon Pilgrim
dd02b404b0
[X86] Lower CTTZ/CTLZ vXi8 vectors using GF2P8AFFINEQB (#118012)
CTTZ can be lowered using GF2P8AFFINEQB if we isolate the lowest set bit
(or is zero) and then use GF2P8AFFINEQB to perform a look up

With CTTZ, CTLZ can be lowered as CTTZ(BITREVERSE())

As discussed on #110308
2026-02-04 09:14:32 +00:00
Juan Manuel Martinez Caamaño
04c56505f8
[NFC][LLVM] Make constrainSelectedInstRegOperands return void (#179501)
`constrainSelectedInstRegOperands` always returns `true`; so it can be
safely transformed to return `void` instead.

A follow-up patch should update `MachineInstrBuilder::constrainAllUses`.
2026-02-04 08:59:16 +01:00
Simon Pilgrim
5586d4ace9
[X86] mayFoldIntoVector - recognise larger than legal logic ops may fold to vectors (#179503)
Inspired by the hack to #174761 - move the custom operation handling
inside mayFoldIntoVector where we can more accurately predict ops that
can be moved to the vector unit
2026-02-03 17:50:59 +00:00
Fangrui Song
0b4147e0bc
[X86] Restrict offset folding into address mode in 16-bit mode (#179399)
106549a436/src/pnpbios.c (L70)
has code that looks like
```
extern int X;
unsigned f(void) { return (unsigned)&X - 0xf0000; }
```

which compiles (-O1 or above, -fno-pic) to

```
.code16
leal X-983040, %eax  # R_386_16 relocation, [-65535,65535]
```
in 16-bit mode. This is rejected by both GNU Assembler and LLVM
integrated assembler (after #176827).

Restrict offset folding in 16-bit mode to the range [-65535, 65535].
2026-02-03 17:07:09 +00:00
Anshul Nigham
26921d74ef
[NewPM] Fix callsite for x86-lvi-ret (#179383) 2026-02-02 21:05:04 -08:00
Nicolai Hähnle
6f0b873f1c
[CodeGen] Refactor targets to override the new getTgtMemIntrinsic overload (NFC) (#175844)
This is a fairly mechanical change. Instead of returning true/false,
we either keep the Infos vector empty or push one entry.
2026-02-02 17:40:02 -08:00
Anshul Nigham
266a45128a
[NewPM] Port x86-wineh-unwindv2 (#179172) 2026-02-02 07:24:23 -08:00
Mahesh-Attarde
9d5a42c841
[X86][GISEL] Enable PostLegalize Combiner (#174696)
This patch adds post legalize combiner for X86 Target.

Use case for OptNone Combine: I am curious about OptNone usecase,
specifically when we are using -On on command line and no opt on
specific function.
2026-02-02 10:49:08 +00:00
Phoebe Wang
2f3935bcee
[X86][APX] Disable PP2/PPX generation on Windows (#178122)
The PUSH2/POP2/PPX instructions for APX require updates to the Microsoft
Windows OS x64 calling convention documented at
https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-170
due to lack of suitable unwinder opcodes that can support APX
PUSH2/POP2/PPX.

The PR request disables this support by default for code robustness;
workloads that choose to explicitly enable this support can change the
default behavior by explicitly specifying the flag options that enable
this support e.g. for experimentation or code paths that do not need
unwinder support.
2026-02-02 18:01:44 +08:00
Abhiram Jampani
3377756a5b
[X86] checkSignTestSetCCCombine - handle SIGN_EXTEND_INREG/SHL patterns inside CMP(X,0) (#178710)
Handle SIGN_EXTEND_INREG and SHL patterns inside CMP(X,0) cases in checkSignTestSetCCCombine.

Fixes #178246
2026-02-02 09:31:39 +00:00
Anshul Nigham
85545d4c84
[NewPM] Port MachineDominanceFrontierAnalysis (#177709) 2026-02-01 22:02:45 -08:00
Simon Pilgrim
49d2323447
[X86] getScalarMaskingNode - FIXUPIMM scalar ops take upper elements from second operand (#179101)
FIXUPIMMSS/SD instructions passthrough the SECOND operand upper elements, and not the first like most (2-op) instructions

Fixes #179057
2026-02-01 14:00:53 +00:00
Mahesh-Attarde
4ea1791890
[X86] Truncate unused bit for blendw mask (#178883)
While tuning ProcessBLENDWToBLENDD 

07ec2fa144/llvm/lib/Target/X86/X86FixupInstTuning.cpp (L262)
we creating mask from `getImm()` which returns 64bit int and APInt
accept 64 bit int.
```
    APInt MaskW =
        APInt(8, MI.getOperand(NumOperands - 1).getImm(), /*IsSigned=*/false);
```
It fails with MIR for BLENDW instruction that requires8 bit mask 0xAA
from 64 bit Imm.
```
  renamable $xmm2 = VPBLENDWrri renamable $xmm1, killed renamable $xmm2, -86
```
APInt construction complains since higher bits of are also set for
transformations where mask bits are set (results in negative values).

07ec2fa144/llvm/include/llvm/ADT/APInt.h (L125)

This patch uses implictTruncate from APInt constructor to get around.

other approach could have been using direct mask(same effect as implicit
truncate) `AND` with Imm or use signed version (not applicable since
mask).

This case was generate using bisect so most of test excercises, i tried
with VPBLEND generating IR refuse to generate mask in range 0b10101010,
so patch lacks test.
2026-01-30 17:20:30 +00:00
Simon Pilgrim
91dad7e7ca
[X86] canonicalizeLaneShuffleWithRepeatedOps - avoid folding vperm2x128(vpshufd(load()),undef) -> vpshufd(vperm2x128(load(),undef)) (#178675)
There's no benefit to letting vperm2x128 handle the fold in an unary
shuffle and llvm-mca assumes there's an extra register dependency, which
confuses analysis.

Fixes #178632
2026-01-29 15:52:09 +00:00
Simon Pilgrim
a8768c4838
[X86] Canonicalise insertps(insertps(v,s,c0),s,c1) patterns to blend(v,splat(s)) (#178649)
Avoid situations where SimplifyDemandedVectorElts / shuffle combining
keeps messing with the zero masks of inner insertps - usually this is
benign but if they share operands it can cause infinite loops

Fixes #178538
2026-01-29 15:05:25 +00:00
Simon Pilgrim
7e3859cee2
[X86] LowerBUILD_VECTORvXbf16 - pull out repeated MVT::f16/bf16 selection. NFC. (#178467) 2026-01-28 17:29:56 +00:00
Simon Pilgrim
ef6d452768
[X86] vectorizeExtractedCast - don't assume vector source type is simple (#178414)
Fixes #178410
2026-01-28 13:59:46 +00:00
Simon Pilgrim
11081eb1d3
[CostModel][X86] reduce_add(vXi1) will lower as a scalar ctpop (#178400)
Fixes #176906
2026-01-28 11:43:30 +00:00
Julian Pokrovsky
c064244fa2
[X86] X86FixupInstTunings - attempt to convert VPERMQri to VINSERTI128rri (#177327)
When the immediate is 0x44, VPERMQ/VPERMPD duplicates the lower 128-bit
lane to both lanes. This is equivalent to inserting the lower 128-bits
into the upper 128-bit position, which VINSERTI128/VINSERTF128 can
potentially do more efficiently on some targets.

This patch enables X86FixupInstTuning to convert:
  VPERMQ  ymm, ymm, 0x44 -> VINSERTI128 ymm, ymm, xmm, 1
  VPERMPD ymm, ymm, 0x44 -> VINSERTF128 ymm, ymm, xmm, 1

Resolves #159410
2026-01-28 10:03:55 +00: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
serge-sans-paille
47fa46c1c4
[perf] Replace copy-assign by move-assign in llvm/lib/Target/* (#178179) 2026-01-27 13:21:32 +00:00
Simon Pilgrim
c5e6257351
[X86] combineX86FPLogicOp - attempt to fold FAND/FOR/FXOR scalar nodes if they are constant or contain UNDEFs (#177947)
Fixes #177923
2026-01-26 13:30:12 +00:00
Simon Pilgrim
7cd5b2bffb
[X86] combineConcatVectorOps - concat(scalar_to_vector(extractelt(x,0)),scalar_to_vector(extractelt(y,0))) -> concat(x,y) (#177930)
Peek through free scalar_to_vector/extract_vector_elt pairs (of the same
vector width) that might still persist (ideally a better topological
sorting would have removed these already....)
2026-01-26 13:13:08 +00:00
Simon Pilgrim
4d683c0dd7
[X86] Rename lowerX86FPLogicOp -> combineX86FPLogicOp. NFC. (#177937)
This hasn't been part of lowering for a long time
2026-01-26 12:55:23 +00:00
Phoebe Wang
8fce1d75e7
[X86] Prefer andl to andb to save one byte encoding when using with bzhi or bextr (#86921) 2026-01-25 21:34:00 +08: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