20098 Commits

Author SHA1 Message Date
Simon Pilgrim
49f95052c8 [X86] pr59305.ll - replace "X86-64" check prefix with "X64" 2024-03-05 11:33:34 +00:00
Simon Pilgrim
191f7678f7 [X86] 2007-03-15-GEP-Idx-Sink.ll - regenerate test checks 2024-03-05 11:33:34 +00:00
MalaySanghiIntel
564b81db85
Add support for x87 registers on GISel register selection (#83528)
We handle 3 register classes for x87 - rfp32, rfp64 and rfp80.
1. X87 registers are assigned a pseudo register class. We need a new
register bank for these classes.
2. We add bank information and enums for these.
3. Legalizer is updated to allow 32b and 64b even in absence of SSE.
This is required because with SSE enabled, x86 doesn't use fp stack and
instead uses SSE registers.
4. Functions in X86RegisterBankInfo need to decide whether to use the
pseudo classes or SSE-enabled classes. I add MachineInstr as an argument
to static helper function getPartialMappingIdx to this end.

Add/Update tests.
2024-03-05 03:00:14 +01:00
AtariDreams
3e40c96d89
[X86] Resolve FIXME: Add FPCW as a rounding control register (#82452)
To prevent tests from breaking, another fix had to be made: Now, we
check if the instruction after a waiting instruction is a call, and if
so, we insert the wait.
2024-03-05 08:47:05 +08:00
Craig Topper
bdfebc310e [X86] Use update_mir_test_checks.py to generate CHECK lines in masked_compressstore_isel.ll. NFC 2024-03-04 16:17:26 -08:00
Noah Goldstein
a4951eca40 Recommit "[X86] Don't always separate conditions in (br (and/or cond0, cond1)) into separate branches" (2nd Try)
Changes in Recommit:
    1) Fix non-determanism by using `SmallMapVector` instead of
       `SmallPtrSet`.
    2) Fix bug in dependency pruning where we discounted the actual
       `and/or` combining the two conditions. This lead to over pruning.

Closes #81689
2024-03-04 13:23:56 -06:00
Shilei Tian
8300f30a92 [SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)
This patch adds the support for `STRICT_BF16_TO_FP` and
`STRICT_FP_TO_BF16`.
2024-03-04 01:08:49 -05:00
Shilei Tian
2c5d01c2cf Revert "[SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)"
This reverts commit b0c158bd947c360a4652eb0de3a4794f46deb88b.

The changes in `compiler-rt` broke tests.
2024-03-04 00:33:31 -05:00
Shilei Tian
b0c158bd94
[SelectionDAG] Add STRICT_BF16_TO_FP and STRICT_FP_TO_BF16 (#80056)
This patch adds the support for `STRICT_BF16_TO_FP` and
`STRICT_FP_TO_BF16`.
2024-03-04 00:01:50 -05:00
Phoebe Wang
ccc48d45b8 [X86][NFC] Replace X32 check prefixes with X86
We try to only use X32 for gnux32 triple tests.
2024-03-04 11:13:13 +08:00
Phoebe Wang
ff72c83b01
[X86] Add missing subvector_subreg_lowering for BF16 (#83720)
Fixes: #83358
2024-03-04 10:15:43 +08:00
NAKAMURA Takumi
5b4759f9fd Revert "[X86] Don't always separate conditions in (br (and/or cond0, cond1)) into separate branches"
This has been buggy for a while.

Reverts #81689
This reverts commit ae76dfb74701e05e5ab4be194e20e49f10768e46.
2024-03-03 22:31:28 +09:00
Shengchen Kan
37293e69e6
[X86][CodeGen] Support long instruction fixup for APX NDD instructions (#83578)
RFC:
https://discourse.llvm.org/t/rfc-support-long-instruction-fixup-for-x86/76539
2024-03-03 13:03:35 +08:00
Simon Pilgrim
ca827d53c5
[X86] Convert logicalshift(x, C) -> and(x, M) iff x is allsignbits (#83596)
If we're logical shifting an all-signbits value, then we can just mask out the shifted bits.

This helps removes some unnecessary bitcasted vXi16 shifts used for vXi8 shifts (which SimplifyDemandedBits will struggle to remove through the bitcast), and allows some AVX1 shifts of 256-bit values to stay as a YMM instruction.

Noticed in codegen from #82290
2024-03-02 12:44:33 +00:00
Noah Goldstein
ae76dfb747 [X86] Don't always separate conditions in (br (and/or cond0, cond1)) into separate branches
It makes sense to split if the cost of computing `cond1` is high
(proportionally to how likely `cond0` is), but it doesn't really make
sense to introduce a second branch if its only a few instructions.

Splitting can also get in the way of potentially folding patterns.

This patch introduces some logic to try to check if the cost of
computing `cond1` is relatively low, and if so don't split the
branches.

Modest improvement on clang bootstrap build:
https://llvm-compile-time-tracker.com/compare.php?from=79ce933114e46c891a5632f7ad4a004b93a5b808&to=978278eabc0bafe2f390ca8fcdad24154f954020&stat=cycles
Average stage2-O3:   0.59% Improvement (cycles)
Average stage2-O0-g: 1.20% Improvement (cycles)

Likewise on llvm-test-suite on SKX saw a net 0.84% improvement  (cycles)

There is also a modest compile time improvement with this patch:
https://llvm-compile-time-tracker.com/compare.php?from=79ce933114e46c891a5632f7ad4a004b93a5b808&to=978278eabc0bafe2f390ca8fcdad24154f954020&stat=instructions%3Au

Note that the stage2 instruction count increases is expected, this
patch trades instructions for decreasing branch-misses (which is
proportionately lower):
https://llvm-compile-time-tracker.com/compare.php?from=79ce933114e46c891a5632f7ad4a004b93a5b808&to=978278eabc0bafe2f390ca8fcdad24154f954020&stat=branch-misses

NB: This will also likely help for APX targets with the new `CCMP` and
`CTEST` instructions.

Closes #81689
2024-03-01 15:35:34 -06:00
Noah Goldstein
ec415aff63 [X86] Regenerate X86/lsr-addrecloops.ll test; NFC 2024-03-01 15:35:34 -06:00
Simon Pilgrim
1e8d3c357e [X86] cmp-shiftX-maskX.ll - add additional tests for #83596
Shows cases where logical shifts of allsignbits values can be profitably converted to masks
2024-03-01 19:20:14 +00:00
Simon Pilgrim
582718fe61 [X86] cmp-shiftX-maskX.ll - add AVX1 test coverage 2024-03-01 19:20:14 +00:00
Simon Pilgrim
765a5d62bc
[X86] Pre-SSE42 v2i64 sgt lowering - check if representable as v2i32 (#83560)
Without PCMPGTQ, if the i64 elements are sign-extended enough to be representable as i32 then we can compare the lower i32 bits with PCMPGTD and splat the results into the upper elements.

Value tracking has meant we already get pretty close with this, but this allows us to remove a lot of unnecessary bit flipping.
2024-03-01 14:29:12 +00:00
Shengchen Kan
924ad198f5 [X86][CodeGen] Add missing patterns for APX NDD instructions about encoding trick 2024-03-01 21:26:10 +08:00
Shengchen Kan
420928b2fa [X86][CodeGen] Fix compile crash in EVEX compression for corner case
The base register of OPmi_ND may be allocated to the same physic
register as the ND operand.

OPmi_ND is not compressible b/c it has different semnatic from OPmi.
In this case, `isRedundantNewDataDest` should return false, otherwise
we would get error

Assertion `!IsNDLike && "Missing entry for ND-like instruction"' failed.
2024-03-01 16:13:09 +08:00
Simon Pilgrim
80a328b011 [X86] SimplifyDemandedVectorEltsForTargetNode - add basic PCMPEQ/PCMPGT handling 2024-02-29 15:22:12 +00:00
RicoAfoat
1e6627ecef
[X86] matchAddressRecursively - ensure dead nodes are replaced before matching the index register (#82881)
Fixes #82431 - see #82431 for more information.
2024-02-29 14:55:51 +00:00
Simon Pilgrim
139bcda542 [X86] SimplifyDemandedVectorEltsForTargetNode - add basic CVTPH2PS/CVTPS2PH handling
Allows us to peek through the F16 conversion nodes, mainly to simplify shuffles

An easy part of #83414
2024-02-29 12:33:49 +00:00
Simon Pilgrim
b50b50bfbf [X86] cmov-fp.ll - regenerate with common 'NOSSE' prefix to reduce duplication 2024-02-29 12:16:52 +00:00
Simon Pilgrim
7ff3f9760d [X86] getFauxShuffleMask - handle insert_vector_elt(bitcast(extract_vector_elt(x))) shuffle patterns
If the bitcast is between types of equal scalar size (i.e. fp<->int bitcasts), then we can safely peek through them

Fixes #83289
2024-02-29 10:32:49 +00:00
Simon Pilgrim
30b63def50 [X86] Regenerate tests to add missing avx512 constant comments 2024-02-29 10:32:48 +00:00
Simon Pilgrim
b4bc19e2e6 [X86] Add tests showing failure to demand only the sign bit of a sitofp/uitofp node
sitofp - if we only demand the signbit, then we can try to use the source integer
uitofp - signbit is guaranteed to be zero

Noticed while reviewing #82290
2024-02-28 18:49:24 +00:00
AtariDreams
0a54b36d5e
[X86] Resolve FIXME: Create cld only when needed (#82415)
Only use cld when we also have rep instructions, are calling a function, or contain inline asm.
2024-02-28 12:32:58 +00:00
Simon Pilgrim
6287b7b9e9 [X86] combineEXTRACT_SUBVECTOR - extract 256-bit comparisons if only one subvector is required
If only one subvector extraction will be necessary (i.e. because the other is constant etc.) then extract the source operands and perform as a 128-bit comparison

Ideally DAGCombiner's narrowExtractedVectorBinOp would handle this but its tricky to confirm when a target opcode can be safely extracted and performed as a different vector type

Partially improves an outstanding regression in #82290
2024-02-28 12:24:34 +00:00
Simon Pilgrim
37daff028f [X86] setcc-lowering.ll - regenerate with AVX2 test coverage
Added while triaging a regression from #82290
2024-02-28 11:19:48 +00:00
Simon Pilgrim
13c359aa9b
[X86] ReplaceNodeResults - truncate sub-128-bit vectors as shuffles directly (#83120)
We were scalarizing these truncations, but in most cases we can widen the source vector to 128-bits and perform the truncation as a shuffle directly (which will usually lower as a PACK or PSHUFB).

For the cases where the widening and shuffle isn't legal we can leave it to generic legalization to scalarize for us.

Fixes #81883
2024-02-27 15:03:42 +00:00
Noah Goldstein
15a7de697a [SelectionDAG] Support sign tracking through {S|U}INT_TO_FP
Just a minimal amount of easily provable tracking.

Proofs: https://alive2.llvm.org/ce/z/RQYbdw

Closes #82808

Alive2 to has an issue with `(sitofp i1)`, but it can
be verified by hand: https://godbolt.org/z/qKr7hT7s9
2024-02-26 15:35:38 -06:00
Jack Styles
28233408a2
[CodeGen] [ARM] Make RISC-V Init Undef Pass Target Independent and add support for the ARM Architecture. (#77770)
When using Greedy Register Allocation, there are times where
early-clobber values are ignored, and assigned the same register. This
is illeagal behaviour for these intructions. To get around this, using
Pseudo instructions for early-clobber registers gives them a definition
and allows Greedy to assign them to a different register. This then
meets the ARM Architecture Reference Manual and matches the defined
behaviour.

This patch takes the existing RISC-V patch and makes it target
independent, then adds support for the ARM Architecture. Doing this will
ensure early-clobber restraints are followed when using the ARM
Architecture. Making the pass target independent will also open up
possibility that support other architectures can be added in the future.
2024-02-26 12:12:31 +00:00
Owen Anderson
2c5a68858b
Fix non-splat vector SREM expansion when one of the divisors is a power of two. (#82706)
The expansion previously used, derived from Hacker's Delight,
does not work correctly when the dividend is INT_MIN and the
divisor is a power of two. We now use an alternate derivation
of the A and Q constants specifically for the power-of-two divisor
case to avoid this problem. Credit to Fabian Giesen for the
new derivation.

Fixes https://github.com/llvm/llvm-project/issues/77169
2024-02-25 10:13:05 -05:00
Evgenii Kudriashov
790bcecce6
[GlobalISel] Fix a check that aligned tail call is lowered (#82016)
Despite of a valid tail call opportunity, backends still may not
generate a tail call or such lowering is not implemented yet.

Check that lowering has happened instead of its possibility when
generating G_ASSERT_ALIGN.
2024-02-23 12:11:50 +01:00
Antonio Frighetto
25e7e8d993 [CGP] Permit tail call optimization on undefined return value
We may freely allow tail call optzs on undef values as well.

Fixes: https://github.com/llvm/llvm-project/issues/82387.
2024-02-22 10:09:15 +01:00
Simon Pilgrim
b8c9b06134 [X86] LowerCTPOP - add i3 and i4 LUT 'shift+mask' expansions
Use the 3 or 4 active bits as a shift amount into a i32/i64 constant representing the number of set bits.

In future, it might be worthwhile to move this into a generic location in case other targets want to make use of them.

Another expansion pulled from #79823
2024-02-21 13:53:47 +00:00
Simon Pilgrim
98a07f72ee [X86] LowerCTPOP - "ctpop(i2 x) --> sub(x, (x >> 1))"
If we only have 2 active bits then we can avoid the i8 CTPOP multiply expansion entirely

Another expansion pulled from #79823
2024-02-21 13:53:47 +00:00
Simon Pilgrim
3cb4f62de0 [X86] Regenerate vector tests to add missing avx512 constant broadcast comments 2024-02-21 10:46:12 +00:00
Simon Pilgrim
bdeb3d47d1 [X86] Regenerate saddsat/ssubsat vector tests
Adds missing avx512 constant broadcast comments
2024-02-21 10:46:12 +00:00
Simon Pilgrim
066773c411 [X86] computeKnownBitsForTargetNode - add generic handling of PSHUFB
When PSHUFB is used as a LUT (for CTPOP, BITREVERSE etc.), its the source operand that is constant and the index operand the variable. As long as the indices don't set the MSB (which zeros the output element), then the common known bits from the source operand can be used directly, even though the shuffle mask isn't constant.

Further helps to improve CTPOP reduction codegen
2024-02-20 17:14:49 +00:00
Simon Pilgrim
2f1e33df32 [X86] Fold add(psadbw(X,0),psadbw(Y,0)) -> psadbw(add(X,Y),0)
If the vXi8 add(X,Y) is guaranteed not to overflow then we can push the addition though the psadbw nodes (being used for reduction) and only need a single psadbw node.

Noticed while working on CTPOP reduction codegen
2024-02-20 15:58:29 +00:00
Simon Pilgrim
5bd374df3e [X86] psadbw.ll - add AVX2 target test coverage 2024-02-19 17:04:07 +00:00
Simon Pilgrim
8d8bb35ac3 [X86] Add some basic test coverage for #81765
Test cases demonstrating poor value tracking of PSADBW results
2024-02-19 15:20:09 +00:00
XinWang10
bb91b43719
[X86] Handle repeated blend mask in combineConcatVectorOps (#82155)
https://github.com/llvm/llvm-project/commit/1d27669e8ad07f8f2 add
support for fold 512-bit concat(blendi(x,y,c0),blendi(z,w,c1)) to
AVX512BW mask select.
But when the type of subvector is v16i16, we need to generate repeated
mask to make the result correct.
The subnode looks like t87: v16i16 = X86ISD::BLENDI t132, t58,
TargetConstant:i8<-86>.
2024-02-19 09:24:21 +08:00
Arthur Eubanks
5b51d45f49
[X86] Use ".lrodata" prefix for large mergeable constants (#81900)
Otherwise with a small enough large-data-threshold, we can get .rodata.*
sections marked large, making .rodata large in the final binary.
2024-02-15 12:50:26 -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
Simon Pilgrim
f82e0809ba [X86] Add v8i64/v16i32/v16i64 ctpop reduction test coverage
Add test coverage for types wider than legal
2024-02-14 10:54:23 +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