21575 Commits

Author SHA1 Message Date
Mikhail Gudim
562146499c
[CodeGen][NewPM] Port ReachingDefAnalysis to new pass manager. (#159572)
In this commit:
  (1) Added new pass manager support for `ReachingDefAnalysis`.
  (2) Added printer pass.
  (3) Make old pass manager use `ReachingDefInfoWrapperPass`
2025-09-19 09:38:34 -04:00
Simon Pilgrim
188c7ed171
[X86] Add test coverage for #159670 (#159767) 2025-09-19 13:09:32 +00:00
Hongyu Chen
fba55c89c3
[X86] Fold X * 1 + Z --> X + Z for VPMADD52L (#158516)
This patch implements the fold `lo(X * 1) + Z --> lo(X) + Z --> X iff X
== lo(X)`.
2025-09-19 19:35:05 +08:00
AZero13
a05e8d506b
[X86] Allow all legal integers to optimize smin with 0 (#151893)
It makes no sense why smin has to be limited to 32 and 64 bits.

hasAndNot only exists for 32 and 64 bits, so this does not affect smax.
2025-09-19 11:08:06 +00:00
Simon Pilgrim
573b3775e4
[X86] Add test coverage for #158649 (#159524)
Demonstrates the failure to keep avx512 mask predicate bit manipulation
patterns (based off the BMI1/BMI2/TBM style patterns) on the predicate
registers - unless the pattern is particularly complex the cost of
transferring to/from gpr outweighs any gains from better scalar
instructions

I've been rather random with the mask types for the tests, I can adjust
later on if there are particular cases of interest
2025-09-18 09:33:10 +00:00
Björn Pettersson
1c4c7bd808
[SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (#143102)
As reported in https://github.com/llvm/llvm-project/issues/141034
SelectionDAG::getNode had some unexpected
behaviors when trying to create vectors with UNDEF elements. Since
we treat both UNDEF and POISON as undefined (when using isUndef())
we can't just fold away INSERT_VECTOR_ELT/INSERT_SUBVECTOR based on
isUndef(), as that could make the resulting vector more poisonous.

Same kind of bug existed in DAGCombiner::visitINSERT_SUBVECTOR.

Here are some examples:

This fold was done even if vec[idx] was POISON:
  INSERT_VECTOR_ELT vec, UNDEF, idx -> vec

This fold was done even if any of vec[idx..idx+size] was POISON:
  INSERT_SUBVECTOR vec, UNDEF, idx -> vec

This fold was done even if the elements not extracted from vec could
be POISON:
  sub = EXTRACT_SUBVECTOR vec, idx
  INSERT_SUBVECTOR UNDEF, sub, idx -> vec

With this patch we avoid such folds unless we can prove that the
result isn't more poisonous when eliminating the insert.

Fixes https://github.com/llvm/llvm-project/issues/141034
2025-09-17 21:04:00 +00:00
Vladislav Dzhidzhoev
432b58915a
[DebugInfo][DwarfDebug] Separate creation and population of abstract subprogram DIEs (#159104)
With this change, construction of abstract subprogram DIEs is split in
two stages/functions:
creation of DIE (in DwarfCompileUnit::getOrCreateAbstractSubprogramDIE)
and its population with children (in
DwarfCompileUnit::constructAbstractSubprogramScopeDIE).
With that, abstract subprograms can be created/referenced from
DwarfDebug::beginModule, which should solve the issue with static local
variables DIE creation of inlined functons with optimized-out
definitions. It fixes https://github.com/llvm/llvm-project/issues/29985.

LexicalScopes class now stores mapping from DISubprograms to their
corresponding llvm::Function's. It is supposed to be built before
processing of each function (so, now LexicalScopes class has a method
for "module initialization" alongside the method for "function
initialization"). It is used by DwarfCompileUnit to determine whether a
DISubprogram needs an abstract DIE before DwarfDebug::beginFunction is
invoked.

DwarfCompileUnit::getOrCreateSubprogramDIE method is added, which can
create an abstract or a concrete DIE for a subprogram. It accepts
llvm::Function* argument to determine whether a concrete DIE must be
created.

This is a temporary fix for
https://github.com/llvm/llvm-project/issues/29985. Ideally, it will be
fixed by moving global variables and types emission to
DwarfDebug::endModule (https://reviews.llvm.org/D144007,
https://reviews.llvm.org/D144005).

Some code proposed by Ellis Hoag <ellis.sparky.hoag@gmail.com> in
https://github.com/llvm/llvm-project/pull/90523 was taken for this
commit.
2025-09-17 20:06:49 +02:00
Fangrui Song
0cf6688898
MC: Better handle backslash-escaped symbols (#158780)
The MCContext::getOrCreateSymbol change in #138817 was a workaround.
With #158106, we can replace `getOrCreateSymbol` with `parseSymbol`, in
llvm/lib/MC/MCParser to handle backslash-escaped symbols.
2025-09-16 16:42:09 +00:00
Mikołaj Piróg
175bab32d7
[X86] Don't rely on global -fp-contract=fast on X86 CodeGen tests (#158026)
IR has the `contract` to indicate that contraction is allowed. Testing
shouldn't rely on global flag to perform contraction. This is a
prerequisite before making backends rely only on the IR to perform
contraction. See more here:
https://discourse.llvm.org/t/allowfpopfusion-vs-sdnodeflags-hasallowcontract/80909/5
2025-09-16 16:57:31 +02:00
Phoebe Wang
14f2531894
[X86][APX] Compress non-redundant NDD ADD to LEA (#158254) 2025-09-16 13:31:32 +08:00
Hongyu Chen
641ed9f66f
[X86] Handle undef/zero/ones cases after modifying Ops and Masks (#158428)
Fixes https://github.com/llvm/llvm-project/issues/158415.
After `resolveTargetShuffleInputsAndMask` and other modifications on
`Ops` and `Mask`, unused inputs in `Ops` are erased, and may leave `Ops`
empty. This patch handles such cases before calling the final
`combineX86ShuffleChain`。
2025-09-15 19:02:09 +08:00
Mahesh-Attarde
d8c8c67dc5
[X86][GlobalIsel] Add G_[U|S]MIN/G_[U|S]MAX scalar test coverage (#157621)
Adds isel test for supporting G_[U|S]MIN/G_[U|S]MAX.
2025-09-15 09:07:59 +00:00
Mahesh-Attarde
fd4ef8e601
[X86][GlobalIsel] Support G_INTRINSIC_TRUNC/G_FCEIL/G_FFLOOR (#156633)
This PR adds support for C/CPP Lib Intrinsic G_INTRINSIC_TRUNC/G_FCEIL/G_FFLOOR from LangRef in GlobalIsel.
2025-09-15 09:03:14 +00:00
Matt Arsenault
eb3b7ddc69
X86: Fix win64 tail call regression for tail call to loaded pointer (#158055)
Fix regression after 62f2641d603db9aef99dd5c434a1dfe7d3f56346. Previous
patch handled the register case, but the memory case snuck another use
of ptr_rc_tailcall hidden inside i64mem_TC
2025-09-11 23:12:01 +03:00
Arthur Eubanks
984251acad
Revert "[DAGCombiner] Relax condition for extract_vector_elt combine" (#157953)
Reverts llvm/llvm-project#157658

Causes hangs, see
https://github.com/llvm/llvm-project/pull/157658#issuecomment-3276441812
2025-09-10 21:33:44 +00:00
BaiXilin
94e2c19f86
[x86][AVX-VNNI] Fix VPDPBUSD Argument Types (#155194)
Fixed intrinsic VPDPBUSD[,S]_128/256/512's argument types to match with the ISA.

Fixes part of #97271
2025-09-10 12:24:16 +00:00
Trevor Gross
bc65352ab5
[X86][Test] Update tests for lround and llrint (NFC) (#157807)
Apply the following changes:

* Ensure all float types are covered (`f16` and `f128` were often
missing)
* Switch to more straightforward test names
* Remove some CHECK directives that are outdated (prefix changed but the
directive did not get removed)
* Add common check prefixes to merge similar blocks
* Test a more similar set of platforms
* Add missing `nounwind`
* Test `strictfp` for each libcall where possible

This is a pre-test for [1].

[1]: https://github.com/llvm/llvm-project/pull/152684
2025-09-10 08:30:43 +00:00
Justin Riddell
212ba92d30
[X86] Recognise VPMADD52L pattern with AVX512IFMA/AVXIFMA (#153787) (#156714)
Match `(X * Y) + Z` in `combineAdd`. If target supports and we don't
overflow (ie. we know the top 12 bits are unset), rewrite using
VPMADD52L

Have just done the `L` version for now at least, wanted to get feedback
before continuing
2025-09-10 08:28:58 +00:00
ZhaoQi
4621e17dee
[DAGCombiner] Relax condition for extract_vector_elt combine (#157658)
Checking `isOperationLegalOrCustom` instead of `isOperationLegal` allows
more optimization opportunities. In particular, if a target wants to
mark `extract_vector_elt` as `Custom` rather than `Legal` in order to
optimize some certain cases, this combiner would otherwise miss some
improvements.

Previously, using `isOperationLegalOrCustom` was avoided due to the risk
of getting stuck in infinite loops (as noted in
61ec738b60).
After testing, the issue no longer reproduces, but the coverage is
limited to the regression/unit tests and the test-suite.
2025-09-10 15:51:52 +08:00
Phoebe Wang
253d18d032
[X86][LiveRegUnits] Exclude reserved registers from TargetRegisterClass (#157798)
Fixes regression casued by #156817.
2025-09-10 06:42:43 +00:00
Matt Arsenault
6076b070b0
X86: Use LiveRegUnits in findDeadCallerSavedReg (#156817) 2025-09-09 03:51:59 +00:00
guan jian
83af24dd85
[DAG] Generalize fold (not (neg x)) -> (add X, -1) (#154348)
Generalize `fold (not (neg x)) -> (add X, -1)` to `fold (not (sub Y, X)) -> (add X, ~Y)`

---------

Co-authored-by: Yui5427 <785369607@qq.com>
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-09-08 15:12:59 +00:00
Simon Pilgrim
ed33690d2b
[X86] PromoteMaskArithmetic - oneuse vector_extend_inreg nodes can be safely promoted on AVX2+ targets (#157425)
Allows us to extend a result back to the largest type after we've handled mask logic using vXi1 result types from different source vector widths (e.g. v8i32 and v8i8)

Fixes #157382
2025-09-08 13:47:08 +00:00
Simon Pilgrim
75fe619b24
[X86] Add test coverage for #157382 (#157411) 2025-09-08 10:22:50 +00:00
Frederik Harwath
7f6098ed98
[X86] Fix expand-fp on optnone functions (#156900)
As observed by @mikaelholmen, PR #130988
"[AMDGPU] Implement IR expansion for frem instruction" introduced a
regression on x86. Its changes led to the pass being skipped on
functions with the optnone attribute. @bjope also noted that a check
concerning the optnone handling is wrong.

This patch fixes both issues which together fixes the regression. During
the review it was observed that, even before PR #130988, the pass would
not run on optnone functions with the new pass manager. This is also
fixed.
2025-09-05 16:22:22 +02:00
Phoebe Wang
94b164c218
[X86][AVX10] Remove EVEX512 and AVX10-256 implementations (#157034)
The 256-bit maximum vector register size control was removed from AVX10
whitepaper, ref: https://cdrdv2.intel.com/v1/dl/getContent/784343

We have warned these options in LLVM21 through #132542. This patch
removes underlying implementations in LLVM22.
2025-09-05 14:08:59 +00:00
Simon Pilgrim
98f1e4a57f
[DAG] SelectionDAG::canCreateUndefOrPoison - AVGFLOOR/AVGCEIL don't create undef/poison (#157056)
AVGFLOORS: https://alive2.llvm.org/ce/z/6TdoQ_
AVGFLOORU: https://alive2.llvm.org/ce/z/4pfi4i
AVGCEILS: https://alive2.llvm.org/ce/z/nWu8WM
AVGCEILU: https://alive2.llvm.org/ce/z/CGvWiA

Fixes #147696
2025-09-05 11:11:15 +00:00
Hongyu Chen
379e121122
[X86] Compute the known bits for VPMADD52L/VPMADD52H in SimplifyDemandedBitsForTargetNode (#156847)
Address TODO and compute the known bits with the intermediate result.
2025-09-04 20:21:50 +08:00
Simon Pilgrim
05da1603e7
[X86] Add assembly comment for VMOVSH instructions (#156848)
Matches existing MOVSD/S implementations
2025-09-04 11:02:05 +00:00
Nikita Popov
3f757a39f2
[CodeGen] Remove ExpandInlineAsm hook (#156617)
This hook replaces inline asm with LLVM intrinsics. It was intended to
match inline assembly implementations of bswap in libc headers and
replace them more optimizable implementations.

At this point, it has outlived its usefulness (see
https://github.com/llvm/llvm-project/issues/156571#issuecomment-3247638412),
as libc implementations no longer use inline assembly for this purpose.

Additionally, it breaks the "black box" property of inline assembly,
which some languages like Rust would like to guarantee.

Fixes https://github.com/llvm/llvm-project/issues/156571.
2025-09-04 09:28:11 +02:00
Karthik Senthil
3821885b43
[AMX] Fix LIT test with adjustsStack attribute for expensive checks build. (#156808)
The generated MIR fails machine verifier as stack pointer is being
modified without appropriate attributes in frameInfo. This PR fixes this
issue by adding adjustsStack=true attribute. Fixes the post commit
regression identified in #155673.
2025-09-04 14:46:07 +08:00
Yingwei Zheng
0d29279465
[DAGCombine] Propagate nuw when evaluating sub with narrower types (#156710)
Proof: https://alive2.llvm.org/ce/z/cdbzSL
Closes https://github.com/llvm/llvm-project/issues/156559.
2025-09-04 10:17:45 +08:00
Karthik Senthil
0c6f98333f
[AMX][PreTileConfig] Ensure that PLDTILECFGV instruction is sinked closer to tile use instruction. (#155673)
According AMX ABI, tile registers (including config) are volatile hence
requiring caller to save/restore config register. This is done in X86's
FastPreTileConfig pass. Currently the PLDTILECFGV instruction is emitted
immediately after the call which can be problematic if call returns a
value in say rax register and AMX tile is configured using the same
register. This PR addresses this issue by ensuring that PLDTILECFGV is
sinked closer to first instruction using a tile after the call.
2025-09-03 18:36:32 +00:00
Frederik Harwath
47793f9a73
[AMDGPU] Implement IR expansion for frem instruction (#130988)
This patch implements a correctly rounded expansion of the frem
instruction in LLVM IR. This is useful for target architectures for
which such an expansion is too involved to be implement in ISel
Lowering. The expansion is based on the code from the AMD device libs
and has been tested successfully against the OpenCL conformance tests on
amdgpu. The expansion is implemented in the preexisting "expand-fp"
pass. It replaces the expansion of "frem" in ISel for the amdgpu target;
it is enabled for targets which do not directly support "frem" and for
which no matching "fmod" LibCall is available.

---------

Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-09-03 16:27:15 +02:00
Simon Pilgrim
86879d46f6
[X86] Only fold AND/ANDNP back to VSELECT if we know the predicated mask select is legal (#156663)
By only checking type legality we didn't account for 128/256-bit ops
being run on non-AVX512VL targets, or vXi8/i16 ops being run on
non-AVX512BW targets

This check is cropping up in several places now and I intend to hoist it
out into a common helper, but this initial fix needs to be as clean as
possible to be back ported to 21.X

Fixes #156256
2025-09-03 15:01:12 +01:00
Nikita Popov
653c40365b [X86] Generate test checks (NFC) 2025-09-03 10:14:17 +02:00
JaydeepChauhan14
036b33d4d9
[X86][NFC] Moved/Updated llvm.set.rounding testcases (#155434)
- Moved llvm.set.rounding testcases from llvm/test/CodeGen/X86/fpenv.ll to
llvm/test/CodeGen/X86/isel-llvm.set.rounding.ll.
- Added GlobalIsel RUNs as precommit test and will add llvm.set.rounding
GISEL implementation PR after this merge.
2025-09-02 18:54:34 +02:00
Simon Pilgrim
ba707db840
[X86] getScalarMaskingNode - if the mask is zero just return the blended passthrough and preserved source value (#153575)
We already handle the case if the mask is one, so I added the other case where the op is replaced with a MOVSH/S/D blend.

This assumes the scalar passthrough is op0.

I had to adjust the test case for #98306 as AFAICT it'd been over
reduced

Fixes #153570
2025-09-02 08:44:15 +00:00
JaydeepChauhan14
f8a53b0b01
[X86][NFC] Renamed Trigonometric functions testcases (#156162)
Reference PR -
https://github.com/llvm/llvm-project/pull/155434#discussion_r2310501931
2025-09-02 08:38:37 +00:00
Mahesh-Attarde
1cdb8810ce
[X86][GlobalIsel] Add ceil/trunc/floor cpp intrinsic test (#156281)
I am working towards supporting G_INTRINSIC_TRUNC, G_FCEIL and G_FFLOOR.
This patch adds isel test for usecase.
Ref
https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-fceil-g-fsqrt-g-ffloor-g-frint-g-fnearbyint

---------

Co-authored-by: mattarde <mattarde@intel.com>
2025-09-02 13:45:06 +05:30
Prabhu Rajasekaran
6980d3b307
[NFC][llvm] Simplify test IR file (#155926) 2025-09-01 11:34:47 -07:00
XChy
c241eb30c5
[X86] Fold X * Y + Z --> C + Z for vpmadd52l/vpmadd52h (#156293)
Address TODO and implement constant fold for intermediate multiplication
result of vpmadd52l/vpmadd52h.
2025-09-01 17:18:50 +00:00
Craig Topper
4a6435397b
[SelectionDAG] Add computeKnownBits for ISD::ROTL/ROTR. (#156142) 2025-08-30 21:25:56 -07:00
XChy
5a33bc5422
[X86] Fold vpmadd52h/l for pattern X * 0 + Y --> Y (#156086)
Resolves comment in
https://github.com/llvm/llvm-project/pull/155494#issuecomment-3227735091
2025-08-30 16:15:05 +00:00
Daniel Paoliello
95657630bd
[win][x64] Various fixes for unwind v2 (#154834)
* `SetFrame` does not count as a stack allocation.
* `mov` in the epilog undoes `SetFrame` (but is not required), it does
not deallocate a stack allocation.
* `mov` in the epilog MUST be before any stack deallocation or register
popping.
* Remove assert for having a prolog without any epilogs (this is
possible for `noreturn` functions, for instance).
* Improve the errors in `MC` to include the problematic function name.
2025-08-29 09:00:01 -07:00
Phoebe Wang
59082485e6
Reland "[X86][APX] Remove redundant TEST*ri instructions" (#156002)
The goal is to remove redundant TEST*ri instructions, especially with NF
feature. Other tests are side effects due to longer live range of
EFLAGS. https://godbolt.org/z/PbaTj1oa3

Reland with fix to buildbot failures.
2025-08-29 14:51:40 +00:00
Vitaly Buka
3789e593e8
Revert "[X86][APX] Remove redundant TEST*ri instructions" (#155968)
Reverts llvm/llvm-project#155586

Breaks bots, see details in #155586.
2025-08-29 04:05:31 +00:00
Abhishek Kaushik
33b2c26560
[X86] Fix assertion in AVX512 setcc combine due to invalid APInt mask width (#155775)
The AVX512 setcc combine in X86ISelLowering was calling
`APInt::getLowBitsSet` with a mask width (`Len`) that could exceed the
bit width of the broadcasted scalar operand
(`BroadcastOpVT.getSizeInBits()`), leading to assertion failures.

This patch replaces `Len` with the number of defined (non-undef)
elements in the constant pool vector.

This ensures the generated mask is valid and avoids crashes when the
constant pool contains more elements than the scalar bit width can
represent.

Fixes #155762
2025-08-28 19:50:47 +05:30
Phoebe Wang
9c9e56b81c
[X86][APX] Remove redundant TEST*ri instructions (#155586)
The goal is to remove redundant TEST*ri instructions, especially with NF
feature. Other tests are side effects due to longer live range of
EFLAGS. https://godbolt.org/z/PbaTj1oa3
2025-08-28 08:46:58 +08:00
XChy
8687ef7ca2
[X86] SimplifyDemandedBitsForTargetNode - add handling for VPMADD52L/VPMADD52H (#155494)
Resolves #155387.
The X86ISD::VPMADD52L/VPMADD52H nodes only demand the lower 52 bits of
operands 0 / 1.
2025-08-27 11:56:03 +01:00