3774 Commits

Author SHA1 Message Date
David Green
9fd2e2c2fd
[DAG][AArch64] Support masked loads/stores with nontemporal flags (#87608)
SVE has some non-temporal masked loads and stores. The metadata coming
from the nodes is not copied to the MMO at the moment though, meaning it
will generate a normal instruction. This patch ensures that the right
flags are set if the instruction has non-temporal metadata.
2024-04-08 08:53:27 +01:00
Piotr Sobczak
5b59ae423a
[DAG] Preserve NUW when reassociating (#87621)
Similarly to the generic case below, preserve the NUW flag when
reassociating adds with constants.
2024-04-04 16:47:25 +02:00
Simon Pilgrim
2d0087424f
[DAG] Remove extract_vector_elt(freeze(x)), idx -> freeze(extract_vector_elt(x), idx) fold (#87480)
Reverse the fold with handling inside canCreateUndefOrPoison for cases where we know that the extract index is in bounds.

This exposed a number or regressions, and required some initial freeze handling of SCALAR_TO_VECTOR, which will require us to properly improve demandedelts support to handle its undef upper elements.

There is still one outstanding regression to be addressed in the future - how do we want to handle folds involving frozen loads?

Fixes #86968
2024-04-04 11:10:55 +01:00
Simon Pilgrim
39eedfded4 [DAG] visitADDLikeCommutative - convert (add x, shl(0 - y, n)) fold to SDPatternMatch. NFC. 2024-04-03 15:37:38 +01:00
AinsleySnow
52b18430ae
[VP][DAGCombine] Use simplifySelect when combining vp.select. (#87342)
Hi all,

This patch is a follow-up of #79101. It migrates logic from
`visitVSELECT` to `visitVP_SELECT` to simplify `vp.select`. With this
patch we can do the following combinations:

```
vp.select undef, T, F --> T (if T is a constant), F otherwise
vp.select <condition>, undef, F --> F
vp.select <condition>, T, undef --> T
vp.select false, T, F --> F
vp.select <condition>, T, T --> T
```

I'm a total newbie to llvm and I'm sure there's room for improvements in
this patch. Please let me know if you have any advice. Thank you in
advance!
2024-04-03 07:45:50 -04:00
Jonas Paulsson
94b5c118b3
[ISel] Move handling of atomic loads from SystemZ to DAGCombiner (NFC). (#86484)
The folding of sign/zero extensions into an atomic load by specifying an
extension type is not target specific, and therefore belongs in the
DAGCombiner rather than in the SystemZ backend.

- Handle atomic loads similarly to regular loads by adding
AtomicLoadExtActions with set/get methods.
- Move SystemZ extendAtomicLoad() to DagCombiner.cpp.
2024-03-28 16:14:35 +01:00
Luke Lau
856e815ca1
[DAGCombiner] Set disjoint flag in add->or and xor->or combines (#86925)
We check DAG.haveNoCommonBitsSet so the operands will be known to be
disjoint.

I couldn't think of a codegen test case since most targets aren't
checking hasDisjoint yet, apart from RISCV in the or_is_add pattern, but
it also falls back to computeKnownBits.
2024-03-28 18:08:59 +08:00
Simon Pilgrim
9247f3185c [DAG] foldAddSubOfSignBit - reuse existing SDLoc instead of regenerating it. NFC. 2024-03-27 12:22:31 +00:00
Simon Pilgrim
51388fbab1 [DAG] visitSub - reuse existing SDLoc instead of regenerating it. NFC. 2024-03-27 12:22:30 +00:00
Simon Pilgrim
1c9d5c25ae [DAG] foldAddSubBoolOfMaskedVal - reuse existing SDLoc instead of regenerating it. NFC. 2024-03-26 18:33:30 +00:00
Simon Pilgrim
5fc619b5ee [DAG] Update ISD::AVG folds to use hasOperation to allow Custom matching prior to legalization
Fixes issue where AVX1 targets weren't matching 256-bit AVGCEILU cases.
2024-03-26 10:41:07 +00:00
Simon Pilgrim
c7198e0af3
[DAG] Fold insert_subvector(N0, extract_subvector(N0, N2), N2) --> N0 (#86487)
Handle the case where we've ended up inserting back into the source vector we extracted the subvector from.
2024-03-26 10:03:42 +00:00
houndlord
9632e1515c
Match fixed width ISD::AVGFLOORS + ISD::AVGCEILS patterns (#86222) 2024-03-24 15:33:16 +00:00
Harvin Iriawan
57146daeaa
[CodeGen] Update for scalable MemoryType in MMO (#70452)
Remove getSizeOrUnknown call when MachineMemOperand is created.  For Scalable
TypeSize, the MemoryType created becomes a scalable_vector.

2 MMOs that have scalable memory access can then use the updated BasicAA that
understands scalable LocationSize.

Original Patch by Harvin Iriawan
Co-authored-by: David Green <david.green@arm.com>
2024-03-23 12:56:25 +00:00
Simon Pilgrim
ceabaa7e7a [DAG] Fix some missing formatting when I rewrote the SUB(MAX,MIN) -> ABD patterns. NFC. 2024-03-22 11:48:03 +00:00
XChy
cb4453dc69
[SelectionDAG] Prevent combination on inconsistent type in combineCarryDiamond (#84888)
Fixes #84831
When matching carry pattern with `getAsCarry`, it may produce different
type of carryout. This patch checks such case and does early exit.

I'm new to DAG, any suggestion is appreciated.
2024-03-22 16:05:20 +05:30
Simon Pilgrim
6942927609 [DAG] combineConcatVectorOfScalars - stop always creating UNDEF nodes. NFC.
Noticed in debug logs - most calls to visitVECTOR_SHUFFLE resulted into wasteful UNDEF node creations, despite almost never being used.
2024-03-21 16:37:48 +00:00
AtariDreams
7e72cafd68
[SelectionDAG] Add MaskedValueIsZero check to allow folding of zero extended variables we know are safe to extend (#85573)
Add ones for every high bit that will cleared.

This will allow us to evaluate variables that have their bits known to
see if they have no risk of overflow despite the shift amount being
greater than the difference between the two types.
2024-03-21 16:45:17 +05:30
Simon Pilgrim
23de3862dc [DAG] visitSUB - use sd_match to match SUB(MAX,MIN) -> ABD pattern. NFC.
Seriously simplifies the commutation matching logic.
2024-03-21 09:55:50 +00:00
Simon Pilgrim
11aa95f83b [DAG] visitSUB - pull out repeated getScalarSizeInBits() calls. NFC. 2024-03-21 09:55:50 +00:00
Simon Pilgrim
7b5a5be2a7 [DAG] visitSUB/visitSUBO - move getAsNonOpaqueConstant into the if() where its used. NFC.
Noticed while beginning some cleanup for moving to pattern matchers
2024-03-21 09:19:12 +00:00
Shourya Goel
92764c99e9
[DAG] Matched Fixedwidth Pattern for ISD::AVGCEILU (#85031)
Fixes: #84753
2024-03-19 13:02:37 +00:00
Simon Pilgrim
97fc16e14b [DAG] visitEXTRACT_VECTOR_ELT - share the same SDLoc instead of recreating it. NFC. 2024-03-19 12:39:47 +00:00
Shourya Goel
703920d413
[DAG] Matched FixedWidth pattern for ISD::AVGFLOORU (#84903)
Fixes: #84749
2024-03-19 08:29:55 +00:00
zicwangupa
bc70f60418
[SelectionDAG] Add m_Neg and m_Not pattern matcher and update DAGCombiner (#85365)
Resolves #85065

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2024-03-18 18:34:31 +05:30
David Green
601e102bdb
[CodeGen] Use LocationSize for MMO getSize (#84751)
This is part of #70452 that changes the type used for the external
interface of MMO to LocationSize as opposed to uint64_t. This means the
constructors take LocationSize, and convert ~UINT64_C(0) to
LocationSize::beforeOrAfter(). The getSize methods return a
LocationSize.

This allows us to be more precise with unknown sizes, not accidentally
treating them as unsigned values, and in the future should allow us to
add proper scalable vector support but none of that is included in this
patch. It should mostly be an NFC.

Global ISel is still expected to use the underlying LLT as it needs, and
are not expected to see unknown sizes for generic operations. Most of
the changes are hopefully fairly mechanical, adding a lot of getValue()
calls and protecting them with hasValue() where needed.
2024-03-17 18:15:56 +00:00
Simon Pilgrim
f1d0a48b27 [DAG] foldABSToABD - share the same SDLoc argument instead of recreating it over and over again. 2024-03-15 11:25:33 +00:00
Simon Pilgrim
cdb36d47b7 [DAG] foldAndToUsubsat/foldSubToUSubSat - share the same SDLoc argument instead of recreating it over and over again. 2024-03-15 11:25:33 +00:00
Simon Pilgrim
fe753f77c3 [DAG] visitTRUNCATE - pull out repeated SDLoc(N). NFC. 2024-03-15 10:24:19 +00:00
Simon Pilgrim
d59256992e [DAG] visitAND - pull out repeated SDLoc(N). NFC. 2024-03-15 10:24:19 +00:00
Simon Pilgrim
c7cf1350b4 [DAG] foldAndToUsubsat - convert to use sd_match pattern. NFC. 2024-03-14 12:20:49 +00:00
Simon Pilgrim
63180ba444 [DAG] Use SelectionDAG::getNOT helper where possible. NFC. 2024-03-13 14:47:35 +00:00
Simon Pilgrim
a7af53e99b [DAG] visitSUB - convert some folds to use SDPatternMatch
General cleanup and allows us to handle several commutable matches with a single pattern
2024-03-13 12:00:24 +00:00
XChy
c8cc7903b3
[SelectionDAG] Replace some basic patterns in visitADDLike with SDPatternMatch (#84759)
Resolves #84745.

Based on SDPatternMatch introduced by #78654, this patch replaces some
of basic patterns in `visitADDLike` with corresponding patterns in
SDPatternMatch.

This patch only replaces original folds, instead of introducing new ones.
2024-03-13 00:33:50 +08:00
SahilPatidar
9e0f5909d0
[DAG] Fix Failure to reassociate SMAX/SMIN/UMAX/UMIN (#82175)
Resolve #58110
2024-03-07 15:15:17 +00:00
Jay Foad
571d5af5aa [DAGCombiner] Improve comment on reassociateOps and its helper 2024-03-06 16:40:12 +00:00
elhewaty
26058e68ea
[DAG] select (sext m), (add X, C), X --> (add X, (and C, (sext m)))) (#83640)
- [DAG][X86] Add tests for Folding select m, add(X, C), X --> add (X, and(C, m))(NFC)
- [DAG][X86] Fold select (sext m), (add X, C), X --> (add X, (and C, (sext m))))
- Fixes: https://github.com/llvm/llvm-project/issues/66101
2024-03-05 16:41:41 +00:00
Luke Lau
a668846202
[DAGCombiner] Handle extending EXTRACT_VECTOR_ELTs in calculateByteProvider (#83963)
An EXTRACT_VECTOR_ELT can extend the element to the width of its result
type, leaving the high bits undefined. Previously if we attempted to
query the bytes in these high bits we would recurse and hit an
assertion. This fixes it by bailing if the index is outside of the
vector element size.

I think the assertion Index < ByteWidth may still be incorrect, since
ByteWidth is calculated from Op.getValueSizeInBits(). I believe this
should be Op.getScalarValueSizeInBits() whenever VectorIndex is set
since we're querying the element now, not the vector. But I couldn't
think of a test case to trigger it. It can be addressed in a follow-up
patch.

Fixes #83920
2024-03-05 18:31:33 +08:00
David Green
6e41d60a71
[SelectionDAG] Change computeAliasing signature from optional<uint64> to LocationSize. (#83017)
This is another smaller step of #70452, changing the signature of
computeAliasing() from optional<uint64_t> to LocationSize, and follow-up
changes in DAGCombiner::mayAlias(). There are some test change due to
the previous AA->isNoAlias call incorrectly using an unknown size
(~UINT64_T(0)). This should then be improved again in #70452 when the
types are known to be scalable.
2024-02-28 09:43:05 +00:00
David Green
257cbea20d [DAG] Format DAGCombiner::mayAlias. NFC 2024-02-26 18:22:35 +00:00
Yeting Kuo
850dde063b
[RISCV][VP] Introduce vp saturating addition/subtraction and RISC-V support. (#82370)
This patch also pick the MatchContext framework from DAGCombiner to an
indiviual header file to make the framework be used from other files in
llvm/lib/CodeGen/SelectionDAG/.
2024-02-23 14:17:15 +08:00
Craig Topper
c1716e3fcf
[DAGCombiner][RISCV] CSE zext nneg and sext. (#82597)
If we have a sext and a zext nneg with the same types and operand
we should combine them into the sext. We can't go the other way
because the nneg flag may only be valid in the context of the uses
of the zext nneg.
2024-02-22 09:06:49 -08:00
Craig Topper
f8cbb67b10
[DAGCombiner] Preserve nneg flag from inner zext when we combine (z/s/aext (zext X)) (#82199) 2024-02-19 12:21:17 -08:00
Craig Topper
f668a08e00
[DAGCombiner][RISCV] Optimize (zext nneg (truncate X)) if X has known sign bits. (#82227)
This treats the zext nneg as sext if X is known to have sufficient sign
bits to allow the zext or truncate or both to removed. This code is
taken from the same optimization for sext.
2024-02-19 10:45:11 -08:00
Craig Topper
d5167c84f9
[DAGCombiner] Allow tryToFoldExtOfLoad to use a sextload for zext nneg. (#81714)
If the load is used by any signed setccs, we can use a sextload
instead of zextload. Then we don't have to give up on extending
the load.
2024-02-17 11:37:13 -08:00
Simon Pilgrim
b279ca2783 [DAG] visitCTPOP - CTPOP(SHIFT(X)) -> CTPOP(X) iff the shift doesn't affect any non-zero bits
If the source is being (logically) shifted, but doesn't affect any active bits, then we can call CTPOP on the shift source directly.
2024-02-15 10:41:08 +00:00
Craig Topper
86ce491f30
[DAGCombiner] Remove unneeded commonAlignment from reduceLoadWidth. (#81707)
We already have the PtrOff factored into MachinePointerInfo. Any calls
to getAlign on the new load with do commonAlignment with the
MachinePointerInfo offset and the base alignment.
2024-02-13 23:26:25 -08:00
Craig Topper
e6253102a7
[DAGCombiner] Remove unnecessary commonAlignment from CombineExtLoad. (#81705)
The getAlign function for a load returns the commonAlignment of the
"base align" and the offset stored in the MachinePointerInfo.

We're splitting a load here, so we should take the base alignment from
the original load without any offset that may already exist in the
original load. The new load can then maintain its own alignment using
just the base alignment and its own offset.

Noticed by inspection.
2024-02-13 23:26:08 -08:00
Nikita Popov
25b9ed6e49
[DAGCombine] Fix multi-use miscompile in load combine (#81586)
The load combine replaces a number of original loads with one new loads
and also replaces the output chains of the original loads with the
output chain of the new load. This is incorrect if the original load is
retained (due to multi-use), as it may get incorrectly reordered.

Fix this by using makeEquivalentMemoryOrdering() instead, which will
create a TokenFactor with both chains.

Fixes https://github.com/llvm/llvm-project/issues/80911.
2024-02-13 16:41:00 +01:00
Simon Pilgrim
b35c519762 [DAG] tryToFoldExtendOfConstant - share the same SDLoc argument instead of recreating it over and over again. 2024-02-08 11:43:29 +00:00