20990 Commits

Author SHA1 Message Date
Yeaseen
96c723374a
[llvm] Remove br i1 undef from some llvm/test/CodeGen tests (#128272) 2025-02-23 09:23:33 +00:00
Yingwei Zheng
dbd219aef4
[DAGCombiner][X86] Correctly clean up high bits in combinei64TruncSrlAdd (#128353)
A counterexample for original implementation:
https://alive2.llvm.org/ce/z/7ieYLg
This patch uses zext instead of anyext to fix the original issue.
BTW, we should keep low `64 - shamt` bits instead of `shamt - 32`:
https://alive2.llvm.org/ce/z/ruQP_Z
Some codes are simplified to avoid confusion.
Proof: https://alive2.llvm.org/ce/z/z_jdHD

Closes https://github.com/llvm/llvm-project/issues/128309.
2025-02-23 12:57:45 +08:00
Vitaly Buka
50b0669e84
Revert "[X86] combineBROADCAST_LOAD - merge across chains" (#128380)
Reverts llvm/llvm-project#128209

Introduces "AddressSanitizer: use-after-poison".
2025-02-22 16:15:41 -08:00
Craig Topper
9e8d11d2df
[X86] Check that the type is integer before calling isUnsignedIntSetCC in combineExtSetcc. (#128263)
SETULT can be an unsigned less than integer compare or a unordered less
than FP compare. We need to check the VT to distinguish them.

Fixes on of the issues from #128237.
2025-02-22 10:10:51 -08:00
Simon Pilgrim
e21a1737f3
[X86] combineBROADCAST_LOAD - merge across chains (#128209)
Remove the restriction when reusing wider BROADCAST_LOAD nodes that both nodes couldn't have uses of their load chains - use makeEquivalentMemoryOrdering to merge the chains instead.
2025-02-22 15:59:25 +00:00
Phoebe Wang
fa64a210b8
[X86][FP16] Adding lowerings for FP16 ISD::LRINT and ISD::LLRINT (#127382)
Address comment in #126477
2025-02-22 21:17:26 +08:00
Yingwei Zheng
646e4f2eed
[DAGCombiner] visitFREEZE: Early exit when N is deleted (#128161)
`N` may get merged with existing nodes inside the loop. Early exit when
it is deleted to avoid the crash.
Alternative solution: use `DAGNodeDeletedListener` to refresh the value
of N.

Closes https://github.com/llvm/llvm-project/issues/128143.
2025-02-22 12:06:34 +08:00
Yingwei Zheng
3ec83f5774
[X86][DAGCombiner] Fix assertion failure in combinei64TruncSrlAdd (#128194)
Closes https://github.com/llvm/llvm-project/issues/128158.
2025-02-22 12:05:59 +08:00
Matt Arsenault
0c50054820 Revert "RegAlloc: Fix verifier error after failed allocation (#119690)"
This reverts commit 34167f99668ce4d4d6a1fb88453a8d5b56d16ed5.

Different set of verifier errors appears after other regalloc failure
tests with EXPENSIVE_CHECKS.
2025-02-22 00:23:21 +07:00
Simon Pilgrim
bd034ab111
[X86] combineX86ShuffleChain - always combine to a new VPERMV node if the root shuffle was a VPERMV node (#128183)
Similar to what we already do for VPERMV3 nodes - if we're trying to create a new unary variable shuffle and we started with a VPERMV node then always create a new one if it reduces the shuffle chain depth
2025-02-21 16:10:46 +00:00
Matt Arsenault
34167f9966
RegAlloc: Fix verifier error after failed allocation (#119690)
In some cases after reporting an allocation failure, this would fail
the verifier. It picks the first allocatable register and assigns it,
but didn't update the liveness appropriately. When VirtRegRewriter
relied on the liveness to set kill flags, it would incorrectly add
kill flags if there was another overlapping kill of the virtual
register.

We can't properly assign the register to an overlapping range, so
break the liveness of the failing register (and any other interfering
registers) instead. Give the virtual register dummy liveness by
effectively deleting all the uses by setting them to undef.

The edge case not tested here which I'm worried about is if the read
of the register is a def of a subregister. I've been unable to come up
with a test where this occurs.

https://reviews.llvm.org/D122616
2025-02-21 22:11:51 +07:00
Simon Pilgrim
884b79a478
[X86] Relax vbroadcast(vector load X) -> vbroadcast_load(X) to all types (#128039)
There's no need for a AVX1-only 32/64-bit scalar size limit - if the X86ISD::VBROADCAST node type is supported, X86ISD::VBROADCAST_LOAD will be as well.
2025-02-21 12:49:34 +00:00
João Gouveia
0a913b5e3a
[X86] Fold some (truncate (srl (add X, C1), C2)) patterns to (add (truncate (srl X, C2)), C1') (#126448)
Addresses the poor codegen identified in #123239 and a few extra cases.
This transformation is correct for `eq`
(https://alive2.llvm.org/ce/z/qZhwtT), `ne`
(https://alive2.llvm.org/ce/z/6gsmNz), `ult`
(https://alive2.llvm.org/ce/z/xip_td) and `ugt`
(https://alive2.llvm.org/ce/z/39XQkX).

Fixes #123239
2025-02-21 17:17:09 +08:00
Phoebe Wang
3302bef5b4
[X86] Combine FRINT + FP_TO_SINT to LRINT (#126477)
Based on Craig's suggestion on #126217

Alive2: https://alive2.llvm.org/ce/z/9XNpWt
2025-02-21 14:44:08 +08:00
Simon Pilgrim
a03f064b60 [X86] combineX86ShufflesRecursively - peek through one use bitcasts to find additional (free) extract_subvector nodes 2025-02-20 13:49:49 +00:00
Simon Pilgrim
505d35aad3
[X86] getFauxShuffleMask - relax one use limit for insert_subvector concat splat pattern (#127981)
If we're splatting a subvector using a insert_subvector(insert_subvector(undef,sub,0),sub,c) pattern then permit multiuse of the sub as long as the insert_subvector nodes are the only users.
2025-02-20 12:04:41 +00:00
Simon Pilgrim
92a3192a96 [X86] vector-shuffle-v192.ll - regenerate VPTERNLOG comments 2025-02-20 11:58:45 +00:00
Simon Pilgrim
66cf2a88a4 [X86] sext-vsetcc.ll - regenerate VPTERNLOG comments 2025-02-20 11:58:45 +00:00
Simon Pilgrim
62d77fcb3c
[X86] combineX86ShuffleChain - don't combine to VPERM2W/VPERM2B from just any single variable mask (#127914)
Despite them being more expensive than other variable mask shuffles, we
were combining shuffle chains to VPERM2W/VPERM2B if any shuffle in the
chain was a variable shuffle - including very cheap shuffles like PSHUFB
or AND mask patterns.

This patch adjusts the BWI VPERMV3 threshold - it still always permits
the merge if the chain (of 2 or more shuffles) contains any
X86ISD::VPERMV/VPERMV3 shuffles (including DQ variants), but otherwise
only reduces the depth threshold based off the number of other variable
shuffles we'd fold away.
2025-02-20 09:11:29 +00:00
Simon Pilgrim
0607f94280
[X86] getFauxShuffleMask - add support for vXi64/vXf64 concat_vectors decoding (#127630)
Similar to insert_subvector - limit this to vXi64 vector cases to make the most of cross lane shuffles (for now).
2025-02-19 09:34:15 +00:00
Nikita Popov
cc539138ac
[CodeGen] Use __extendhfsf2 and __truncsfhf2 by default (#126880)
The standard libcalls for half to float and float to half conversion are
__extendhfsf2 and __truncsfhf2. However, LLVM currently uses
__gnu_h2f_ieee and __gnu_f2h_ieee instead. As far as I can tell, these
libcalls are an ARM-ism and only provided by libgcc on that platform.
compiler-rt always provides both libcalls.

Use the standard libcalls by default, and only use the __gnu libcalls on
ARM.
2025-02-19 10:16:57 +01:00
Simon Pilgrim
f3f4afe43f
[X86] matchUnaryShuffle - add support for matching 512-bit extension patterns. (#127643)
Handles both BWI and non-BWI cases (skips PMOV*XBW without BWI).

The vector-interleaved-store-i8-stride-8.ll VPTERNLOG diffs are due to
better value tracking now recognizing the zero-extension patterns where
before it was any-extension
2025-02-19 09:07:49 +00:00
Mikołaj Piróg
6662fe393c
[X86] Add missing vNbf16 handling in X86CallingConv.td file (#127102)
Lack of these entries caused clang to crash on the following code:

```c
__m256bh fun(__m256bh arg) {
	return arg;
	
}
__m256bh run() {
    __m256bh arg= {0};
    fun(arg);
}
```
It caused the FastISel to fail since it handled the call lowering basing
on the X86CallingConv table.

Curiously, if FastISel fails somewhere down the line and
selectionDAGISel fallbacks, the crash does not occur. Following code
_does not_ crash:

```c
__m256bh fun(__m256bh arg) {
	return arg;
}

__m256bh run() {
    __m256bh arg= {0};
    return fun(arg);

}
```

This is puzzling to me. Obviously, if FastISel fails then compiler
fallbacks to something else to lower these calls -- but since the
X86callingConv table _doesn't_ have entries for vNbf16 how does this
other thing manage not to crash? It has to use some other mechanism, one
which doesn't use the table. This rises following questions:
- how is this lowering accomplished without, presumably, using the
CallingConv entries?
- why is the table not used? I mean this points to some logic
duplication (fastISel way vs. the other bug-free way)
- How to properly test this? There is a test for vNbf16 values, but it
also must not be using the FastISel path? This duplication of logic
makes it hard to test this, since we don't have direct control whether
the FastISel path or the other one is used.

Nonetheless, this PR fixes the crash, though I didn't create a test for
it, since I am unsure yet how it should look like. I would like to learn
how the working non-FastISel mechanism works; I tried looking for it,
but didn't yet manage to find anything
2025-02-19 11:04:10 +08:00
Simon Pilgrim
bfcec1999c [X86] Add test coverage for bfloat <-> half conversion
Inspired by #90738 (although that is a clang codegen issue)
2025-02-18 16:49:51 +00:00
Simon Pilgrim
10fc06a321
[X86] canonicalizeShuffleWithOp - add handling for X86ISD::VPERMV nodes (#127625)
Handle different src/mask operand ordering of X86ISD::VPERMV nodes
2025-02-18 14:42:18 +00:00
Simon Pilgrim
1ae9dd31a2
[X86] combineConcatVectorOps - add EXTEND_VECTOR_INREG() 512-bit handling (#127530)
Support extension to 512-bit vectors on AVX512/BWI targets.
2025-02-18 08:08:58 +00:00
Craig Topper
ef9f0b3c41
[DAGCombiner] Don't peek through truncates of shift amounts in takeInexpensiveLog2. (#126957)
Shift amounts in SelectionDAG don't have to match the result type
of the shift. SelectionDAGBuilder will aggressively truncate shift
amounts to the target's preferred type. This may result in a zero extend
that existed in IR being removed.
    
If we look through a truncate here, we can't guarantee the upper bits
of the truncate input are zero. There may have been a zext that was
removed. Unfortunately, this regresses tests where no truncate was
involved. The only way I can think to fix this is to add an assertzext
when SelectionDAGBuilder truncates a shift amount or remove the
early truncation of shift amounts from SelectionDAGBuilder all together.
    
Fixes #126889.
2025-02-17 20:26:05 -08:00
Simon Pilgrim
d29045622a
[X86] combineConcatVectorOps - fold concat(EXTEND_VECTOR_INREG(x),EXTEND_VECTOR_INREG(y)) -> EXTEND_VECTOR_INREG(unpack(x,y)) (#127502)
Concat/unpack the src subvectors together in the bottom 128-bit vector and then extend with a single EXTEND/EXTEND_VECTOR_INREG instruction

Required the getEXTEND_VECTOR_INREG helper to be tweaked to accept EXTEND_VECTOR_INREG opcodes as well to avoid us having to remap the opcode between both types.
2025-02-17 15:50:25 +00:00
Simon Pilgrim
94585dc59d [X86] Add test coverage for #116931 2025-02-17 09:03:26 +00:00
Simon Pilgrim
b16ce8fc24
[X86] getFauxShuffleMask - match 256-bit CONCAT(SUB0, SUB1) 64-bit elt patterns as well as 512-bit (#127392)
The 512-bit filter was to prevent AVX1/2 regressions, but most of that is now handled by canonicalizeShuffleWithOp

Ideally we need to support smaller element widths as well.

Noticed while triaging #116931
2025-02-17 08:20:25 +00:00
Simon Pilgrim
42ff31aea5
[X86] combineTargetShuffle - fold VPERMV3(HI,MASK,LO) -> VPERMV(COMMUTE(MASK),CONCAT(LO,HI)) (#127199)
We already handle the simpler VPERMV3(LO,MASK,HI) fold which can reuse
the (widened) mask, this attempts to match the flipped concatenation,
and commutes the mask to handle the flip.

I've limited this to cases where we can extract the constant mask for
commutation, a more general solution would XOR the MSB of the shuffle
mask indices to commute, but this almost never constant folds away after
lowering so the benefit was minimal.
2025-02-15 11:59:52 +00:00
Simon Pilgrim
0b49001853 [X86] Add test coverage for #9297
(using bugzilla id for PR)
2025-02-14 11:38:47 +00:00
deadalnix
2ad1089d63
[X86] Match SETCC_CARRY in addition of SUB when trying to reconstruct LEA (#126551)
As per title.

This is not a huge deal at the moment, but becomes one when matching
node in topological order in the DAGCombiner, and is generally more
stable than the existing.
2025-02-14 17:38:25 +08:00
Nikita Popov
d8b2e432d6
[IR] Remove mul constant expression (#127046)
Remove support for the mul constant expression, which has previously
already been marked as undesirable. This removes the APIs to create mul
expressions and updates tests to stop using mul expressions.

Part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
2025-02-14 09:28:57 +01:00
Simon Pilgrim
e657b96cd8 [X86] Fold EXTRACT_SUBVECTOR(VPERMV(V,M),C) -> EXTRACT_SUBVECTOR(VPERMV(V,M'),0)
Similar to what we already do for VPERMV3, we can fold the non-zero-idx EXTRACT_SUBVECTOR into the shuffle mask and use a free EXTRACT_SUBVECTOR(V,0) instead
2025-02-13 12:35:05 +00:00
Simon Pilgrim
f719d8ac1c [X86] vec-strict-cmp-128-fp16.ll - regenerate VMOVSH comments 2025-02-12 18:48:55 +00:00
Simon Pilgrim
689f79d0f8 [X86] vec-strict-cmp-512-skx.ll - regenerate checks
Appears to have been manually edited at some point
2025-02-12 18:48:55 +00:00
Simon Pilgrim
a6a4252a15 [X86] vec-strict-fptoint - regenerate VPTERNLOG comments 2025-02-12 18:48:54 +00:00
Simon Pilgrim
b04a980b55 [X86] 2011-10-27-tstore.ll - regenerate checks 2025-02-12 17:19:19 +00:00
Simon Pilgrim
fbf46dfe35 [X86] fp-fold.ll - regenerate checks 2025-02-12 15:32:08 +00:00
Simon Pilgrim
7647f478c3
[X86] isShuffleFoldableLoad - only check that the SDValue has one use (#126900)
We don't need the entire load node to have oneuse, just the loaded value - prevents load chains from interfering with shuffle commutation
2025-02-12 13:13:49 +00:00
Simon Pilgrim
f73ed3d434
[X86] lowerShuffleAsBroadcast - use isShuffleEquivalent to search for a hidden broadcast pattern (#126517)
lowerShuffleAsBroadcast only matches a known-splat shuffle mask, but we
can use the isShuffleEquivalent/IsElementEquivalent helpers to attempt
to find a hidden broadcast-able shuffle pattern.

This requires an extension to IsElementEquivalent to peek through
bitcasts to match against wider shuffles - these typically appear during
shuffle lowering where we've widened a preceding shuffle, often to a
vector concatenation etc.

Amazingly I hit this while yak shaving #126033 .......
2025-02-12 10:12:20 +00:00
Yeaseen
c174cc4840
[llvm] Remove br i1 undef in some llvm/test/CodeGen tests (#126811)
This PR replaces some instances of `br i1 undef` with function argument
value in several tests under `llvm/test/CodeGen/` directory.
2025-02-12 09:19:00 +00:00
Simon Pilgrim
8359dbc8c0
[X86] combineEXTRACT_SUBVECTOR - fold extract_subvector(subv_broadcast_load(ptr),0) -> load(ptr) (#126523)
This is typically handled by SimplifyDemandedVectorElts, but this will
fail when there are multiple uses of the subv_broadcast_load node, but
if there's just one use of the load result (and the rest are uses of the
memory chain), we can still replace with a load and update the chain
accordingly.

Noticed on #126517
2025-02-12 09:07:06 +00:00
Jim Lin
31bfae35d2
[DAGCombiner] Add hasOneUse checks for folding (not (add X, -1)) to (neg X) (#126667)
To get more better codegen for AArch with bic, x86 with andn and riscv
with andn.
2025-02-12 12:24:29 +08:00
Phoebe Wang
0c955167c2
[X86] Generate cvtpd2dq for (v2i32 lrint(v2f64)) (#126508)
Found when addressing comment on #126477
2025-02-11 13:14:41 +08:00
Florian Hahn
f147d67524
[X86] Use StackArgTokenFactor for all stores when setting up tail calls. (#126244)
Before this patch, the stack argument token factor was used if any
outgoing stack slots needed to be written, but not when writing the
return address to a stack slot. Writing the return address stack slot
can also alias a stack slot for an input argument.

Always use StackArgumentTokenFactor, to ensure the store of the return
address will always use it, i.e. happen after all input arguments are
loaded.

PR: https://github.com/llvm/llvm-project/pull/126244
2025-02-10 20:01:14 +00:00
Simon Pilgrim
d9183fd96e
[X86] LowerSelect - use BLENDV for scalar selection on all SSE41+ targets (#125853)
When we first began (2015) to lower f32/f64 selects to
X86ISD::BLENDV(scalar_to_vector(),scalar_to_vector(),scalar_to_vector()),
we limited it to AVX targets to avoid issues with SSE41's xmm0
constraint for the condition mask.

Since then we've seen general improvements in TwoAddressInstruction and
better handling of condition commutation for X86ISD::BLENDV nodes, which
should address many of the original concerns of using SSE41 BLENDVPD/S.
In most cases we will replace 3 logic instruction with the BLENDV node
and (up to 3) additional moves. Although the BLENDV is often more
expensive on original SSE41 targets, this should still be an improvement
in a majority of cases.

We also have no equivalent restrictions for SSE41 for v2f64/v4f32 vector
selection.

Fixes #105807
2025-02-10 11:24:04 +00:00
Simon Pilgrim
4972722f90
[X86] lowerV4F64Shuffle - prefer lowerShuffleAsDecomposedShuffleMerge if we're blending inplace/splatable shuffle inputs on AVX2 targets (#126420)
More aggressively use broadcast instructions where possible

Fixes #50315
2025-02-09 17:11:18 +00:00
Arthur Eubanks
7aabbf22f0
[llvm][ELF] Separate out .dwo bytes written in stats (#126165)
So we can distinguish between debug info sections written to .dwo files
and those written to the object file.
2025-02-07 10:34:16 -08:00