14368 Commits

Author SHA1 Message Date
Alex MacLean
f73e163278
[DAGCombiner] Fold [us]itofp of truncate (#149391) 2025-07-18 08:10:20 -07:00
Paul Walker
44cd5027f8
[LLVM][CodeGen][SVE] List MVTs that are desirable for extending loads. (#149153)
Extend AArch64TargetLowering::isVectorLoadExtDesirable to specify the
set of MVT for which load extension is desirable.

Fixes https://github.com/llvm/llvm-project/issues/148939
2025-07-18 15:34:48 +01:00
Fabian Ritter
daa6de37ba
[AMDGPU][SDAG] Add target-specific ISD::PTRADD combines (#143673)
This patch adds several (AMDGPU-)target-specific DAG combines for
ISD::PTRADD nodes that reproduce existing similar transforms for
ISD::ADD nodes. There is no functional change intended for the existing
target-specific PTRADD combine.

For SWDEV-516125.
2025-07-18 10:00:54 +02:00
Shoreshen
5fe9b52352
Add FABS to canCreateUndefOrPoison (#149440)
FABS will not create undef/poison, add it into canCreateUndefOrPoison
return false
2025-07-18 14:17:15 +08:00
Fraser Cormack
284dd5ba84
[SelectionDAG] Fix misplaced commas in operand bundle errors (#149331) 2025-07-17 21:18:05 +01:00
Piotr Fusik
9fa3971fac
[DAGCombiner] Fold vector subtraction if above threshold to umin (#148834)
This extends #134235 and #135194 to vectors.
2025-07-17 16:37:59 +02:00
Marco Elver
66da9f38f3
[SelectionDAG] Fix copyExtraInfo where new node has entry as operand (#149307)
Add special case handling where a new replacement node has the entry
node as an operand i.e. does not depend on any other nodes.

This can be observed with the existing X86/pcsections-atomics.ll test
case when targeting Haswell, where certain 128-bit atomics are
transformed into arch-specific instructions, with some operands having
no other dependencies.
2025-07-17 15:44:21 +02:00
Craig Topper
36e4174989
[DAGCombiner][AArch64] Prevent SimplifyVCastOp from creating illegal scalar types after type legalization. (#148970)
Fixes #148949
2025-07-15 18:22:25 -07:00
Florian Mayer
5458151817
[SelectionDAG] improve error messages for invalid operator bundle (#148945) 2025-07-15 17:30:48 -07:00
Paul Walker
bd4e7f5f5d
[LLVM][DAGCombiner] Fix size calculations in calculateByteProvider. (#148425)
calculateByteProvider only cares about scalars or a single element
within a vector. For the later there is the VectorIndex parameter to
identify the element. All other properties, and specificially Index, are
related to the underyling scalar type and thus when taking the size of a
type it's the scalar size that matters.

Fixes https://github.com/llvm/llvm-project/issues/148387
2025-07-15 11:05:38 +01:00
Simon Pilgrim
e74520fae6
[DAG] canCreateUndefOrPoison - add handling for ISD::ABS nodes (#148791)
Unlike the abs intrinsic, the ISD::ABS node defines ABS(INT_MIN) -> INT_MIN, so no undef/poison is created by the node itself
2025-07-15 09:31:26 +01:00
Kazu Hirata
a869f7e821
[CodeGen] Remove an unnecessary cast (NFC) (#148764)
getExpression() already returns DIExpression *.
2025-07-14 22:18:51 -07:00
Craig Topper
eea5c291bb
[DAGCombiner] Pass SDNodeFlags to getNode instead of modifying nodes. (#148744)
getNode has logic to intersect flags correctly if the new node happens
to CSE with an existing node. Setting node flags after getNode bypasses
this logic and may change the node for other uses where the flags don't
hold.
2025-07-14 20:53:14 -07:00
Florian Mayer
be200e2b80
[SelectionDAG] improve error message for invalid op bundles (#148722) 2025-07-14 20:41:10 -07:00
Florian Mayer
14dc3e3d5f
[SelectionDAG] [KCFI] Allow "kcfi" on invoke (#148742)
This is handled in CallBase, so it is valid for both call and invoke
2025-07-14 18:55:09 -07:00
Craig Topper
f07107337f
[DAGCombiner] Pass SDNodeFlags to getSelect instead of modifying the node returned. (#148733) 2025-07-14 16:50:10 -07:00
woruyu
b22b103c3d
[DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::FCOPYSIGN (#148617)
### Summary
This PR resolves https://github.com/llvm/llvm-project/issues/147694
2025-07-14 15:28:52 +01:00
Matt Arsenault
7299250c03
DAG: Use fast variants of fast math libcalls (#147481)
Hexagon currently has an untested global flag to control fast
math variants of libcalls. Add fast variants as explicit libcall
options so this can be a flag based lowering decision, and implement
it. I have no idea what fast math flags the hexagon case requires,
so I picked the maximally potentially relevant set of flags although
this probably is refinable per call. Looking in compiler-rt, I'm not
sure if the fast variants are anything more than aliases.
2025-07-13 10:41:45 +09:00
jjasmine
44481f5067
[DAGCombine] Change isBuildVectorAll* -> isConstantSplatVectorAll* for Vselect (#147305)
Change isBuildVectorAll* -> isConstantSplatVectorAll* in VSelect in case
the fold happens after BuildVector has been canonically transformed to
Splat or if the Splat is initially in vselect already

- Fixes #73454
- Update related test cases, add extra tests in wasm

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-07-11 10:13:05 +01:00
Fraser Cormack
a516c60ec3
[NFC] Correct typo: invertion -> inversion (#147995) 2025-07-11 07:37:25 +01:00
David Green
0736f330b0
[DAG] Handle truncated splat in isBoolConstant (#145473)
This allows truncated splat / buildvector in isBoolConstant, to allow
certain not instructions to be recognized post-legalization, and allow
vselect to optimize.

An override for x86 avx512 predicated vectors is required to avoid an
infinite recursion from the code that detects zero vectors. From:
```
  // Check if the first operand is all zeros and Cond type is vXi1.
  // If this an avx512 target we can improve the use of zero masking by
  // swapping the operands and inverting the condition.
```
2025-07-10 20:59:34 +01:00
Boyao Wang
697beb3f17
[TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to take LLVM Context (#147664)
Add LLVM Context to getOptimalMemOpType and findOptimalMemOpLowering. So
that we can use EVT::getVectorVT to generate EVT type in
getOptimalMemOpType.

Related to [#146673](https://github.com/llvm/llvm-project/pull/146673).
2025-07-10 11:11:09 +08:00
Craig Topper
2fc6c73b39
[LegalizeTypes] Preserve disjoint flag when expanding OR. (#147640) 2025-07-09 14:15:42 -07:00
Matt Arsenault
d3d4066409
DAG: Remove dead declaration of ExpandSinCosLibCall (#147673) 2025-07-09 18:47:49 +09:00
Matt Arsenault
dc69b00b0a
RuntimeLibcalls: Remove table of soft float compare cond codes (#146082)
Previously we had a table of entries for every Libcall for
the comparison to use against an integer 0 if it was a soft
float compare function. This was only relevant to a handful of
opcodes, so it was wasteful. Now that we can distinguish the
abstract libcall for the compare with the concrete implementation,
we can just directly hardcode the comparison against the libcall
impl without this configuration system.
2025-07-09 17:13:58 +09:00
Sam Elliott
bccd34f323
[SelectionDAG] Correctly Mark Required Analyses (#147649)
llvm/llvm-project#147560 changed when the legacy SelectionDAG pass needs
TargetTransformInfoWrapperPass to always require it (rather than only
when assertions are enabled). `SelectionDAGISelLegacy::getAnalysisUsage`
was not updated in that PR, which was causing crashes on
assertions-disabled builds, which are hard to track down.

This makes the required update, which should avoid crashes being seen on
some buildbots and by some users.
2025-07-08 21:40:29 -07:00
alex-t
9293b65a61
[AMDGPU] SelectionDAG divergence tracking should take into account Target divergency. (#147560)
This is the next attempt to upstream this:
https://github.com/llvm/llvm-project/pull/144947
The las one caused build errors in AArch64.
Issue was resolved.
2025-07-09 00:06:58 +02:00
Matt Arsenault
3697d6dd98
DAG: Fall back to separate sin and cos when softening sincos (#147468)
Fix asserting in the error case.
2025-07-09 01:52:46 +09:00
Philip Reames
f00a7a49bd
[DAG] Fold insert_subvector (splat X), (splat X), N2 - > splat X (#147380)
If we're inserting a splat into a splat of the same value, then
regardless of the index, the result is simply a splat of that value.
2025-07-08 08:50:01 -07:00
Dominik Steenken
acdf1c7526
[DAG] Add generic expansion for ISD::FCANONICALIZE nodes (#142105)
This PR takes the work previously done by @pawan-nirpal-031 on X86 in
#106370, and makes it available in common code. This should enable all
targets to use `__builtin_canonicalize` for all `f(16|32|64|128)` data
types.

Canonicalization is implemented here as multiplication by `1.0`, as
suggested in [the
docs](https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic).
2025-07-08 16:12:17 +01:00
woruyu
b0790e04a3
[DAG] combineVSelectWithAllOnesOrZeros - fold select Cond, 0, x -> and not(Cond), x (#147472)
### Summary
This patch extends the work from
[#145298](https://github.com/llvm/llvm-project/pull/145298) by removing
the now-unnecessary X86-specific combineVSelectWithLastZeros logic. That
combine is now correctly and more generally handled in the
target-independent combineVSelectWithAllOnesOrZeros.

This simplifies the X86 DAG combine logic and avoids duplication.

Fixes: [#144513](https://github.com/llvm/llvm-project/issues/144513)
Related for reference:
[#146831](https://github.com/llvm/llvm-project/pull/146831)
2025-07-08 14:45:40 +01:00
Matt Arsenault
a79acbd92f DAG: Remove leftover debugging assert
Accidentally added in b5401624e1f19fc1f65499179403d0c7ed3ac6eb
2025-07-08 10:26:51 +09:00
DeanSturtevant1
ace3d3002f
Add #ifndef NDEBUG/#endif around debug-only code. (#147356) 2025-07-07 10:45:29 -07:00
woruyu
c80fa2364b
[DAG] SDPatternMatch m_Zero/m_One/m_AllOnes have inconsistent undef h… (#147044)
### Summary
This PR resolves https://github.com/llvm/llvm-project/issues/146871 
This PR resolves https://github.com/llvm/llvm-project/issues/140745

Refactor m_Zero/m_One/m_AllOnes all use struct template function to
match and AllowUndefs=false as default.
2025-07-07 15:04:54 +01:00
Benjamin Maxwell
3277f62344
[SDAG] Remove invalid check (NFC) (#146899)
It does not make sense to do !LC. LC is an RTLIB::Libcall enum, and zero
is a valid value.
2025-07-07 14:42:30 +01:00
Matt Arsenault
b5401624e1
DAG: Add RTLIB::getPOW helper (#147274)
Co-authored-by: Paul Walker <paul.walker@arm.com>
2025-07-07 21:31:49 +09:00
Simon Pilgrim
52383956f8
[DAG] Replace DAGCombiner::ConstantFoldBITCASTofBUILD_VECTOR with SelectionDAG::FoldConstantBuildVector (#147037)
DAGCombiner can already constant fold build vectors of constants/undefs
to a new vector type, but it has to be incredibly careful after
legalization to not affect a target's canonicalized constants.

This patch proposes we move the implementation inside SelectionDAG to
make it easier for targets to manually use the constant folding whenever
it deems it safe to do so.

I've also altered the method to take the BuildVectorSDNode input
directly and consistently use the same SDLoc.
2025-07-07 10:44:03 +01:00
Matt Arsenault
465f2b0571
DAG: Fix asserting in error case for frexp softening (#147236) 2025-07-07 18:37:37 +09:00
Matt Arsenault
08defcb6d3
DAG: Fix asserting in error case for powi softening (#147237) 2025-07-07 18:13:11 +09:00
Matt Arsenault
d8ef156379
DAG: Remove verifyReturnAddressArgumentIsConstant (#147240)
The intrinsic argument is already marked with immarg so non-constant
values are rejected by the IR verifier.
2025-07-07 16:28:47 +09:00
AZero13
91cc33f321
[TargetLowering] hasAndNotCompare should be checking for X, not Y (#146935)
Y is the one being bitwise-not, so it should not be passed, as the other
one should be passed instead.
2025-07-07 14:54:29 +09:00
Simon Pilgrim
ba7d78ac45
[DAG] foldABSToABD - fallback to value tracking if the (ABS (SUB LHS, RHS)) operands aren't extended (#147053)
ISD::ABDS can be used if the signed subtraction will not overwrap (this
is an extension to handle cases where the NSW flag has been lost)

ISD::ABDU can be used if both operands have at least 1 zero sign bit.

Fixes #147049
2025-07-06 08:36:46 +01:00
Simon Pilgrim
740da004af [DAG] Fix static analyzer warning about mismatched argument comments in isConstOrConstSplat. NFC. 2025-07-04 15:00:08 +01:00
Austin
a550fef906
[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)
Use llvm::fill instead of std::fill
2025-07-04 14:10:28 +08:00
Florian Hahn
bfd457588a
Revert "[AMDGPU] SelectionDAG divergence tracking should take into account Target divergency. (#144947)"
This reverts commit 8ac7210b7f0ad49ae7809bf6a9faf2f7433384b0.

This breaks the building the AArch64 backend, e.g. see
https://github.com/llvm/llvm-project/pull/144947

Revert to unbreak the build.

Also reverts follow-up commits 1e76f012db3ccfaa05e238812e572b5b6d12c17e.
2025-07-03 19:25:01 +01:00
alex-t
8ac7210b7f
[AMDGPU] SelectionDAG divergence tracking should take into account Target divergency. (#144947)
If a kernel is known to be executing only a single lane, IR
UniformityAnalysis will take note of that (via
GCNTTIImpl::hasBranchDivergence) and report that all values are uniform.
SelectionDAG's built-in divergence tracking should do the same.
2025-07-03 18:37:37 +02:00
Simon Pilgrim
c79fcfee41 [DAG] combineVSelectWithAllOnesOrZeros - reusing existing VT. NFC. 2025-07-03 10:57:55 +01:00
Philip Reames
220a002396
[SDAG] Prefer scalar for prefix of vector GEP expansion (#146719)
When generating SDAG for a getelementptr with a vector result, we were
previously generating splats for each scalar operand. This essentially
has the effect of aggressively vectorizing the sequence, and leaving it
later combines to scalarize if profitable.

Instead, we can keep the accumulating address as a scalar for as long as
the prefix of operands allows before lazily converting to vector on the
first vector operand. This both better fits hardware which frequently
has a scalar base on the scatter/gather instructions, and reduces the
addressing cost even when not as otherwise we end up with a scalar to
vector domain crossing for each scalar operand.

Note that constant splat offsets are treated as scalar for the above,
and only variable offsets can force a conversion to vector.

---------

Co-authored-by: Craig Topper <craig.topper@sifive.com>
2025-07-02 18:16:27 -07:00
Craig Topper
b62826cc05
[InstrEmitter] Use AddOperand in EmitCopyToRegClassNode. (#146637)
This is alternative to #145965 that allows RegisterSDNode to be handled
without making a special case.
2025-07-02 09:44:54 -07:00
woruyu
bbcebec3af
[DAG] Refactor X86 combineVSelectWithAllOnesOrZeros fold into a generic DAG Combine (#145298)
This PR resolves https://github.com/llvm/llvm-project/issues/144513

The modification include five pattern :
1.vselect Cond, 0, 0 → 0
2.vselect Cond, -1, 0 → bitcast Cond
3.vselect Cond, -1, x → or Cond, x
4.vselect Cond, x, 0 → and Cond, x
5.vselect Cond, 000..., X -> andn Cond, X

1-4 have been migrated to DAGCombine. 5 still in x86 code.

The reason is that you cannot use the andn instruction directly in
DAGCombine, you can only use and+xor, which will introduce optimization
order issues. For example, in the x86 backend, select Cond, 0, x →
(~Cond) & x, the backend will first check whether the cond node of
(~Cond) is a setcc node. If so, it will modify the comparison operator
of the condition.So the x86 backend cannot complete the optimization of
andn.In short, I think it is a better choice to keep the pattern of
vselect Cond, 000..., X instead of and+xor in combineDAG.

For commit, the first is code changes and x86 test(note 1), the second
is tests in other backend(node 2).

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-07-02 15:07:48 +01:00