20779 Commits

Author SHA1 Message Date
Vitaly Buka
d57892a2a1
Revert "[DAGCombiner] Add support for scalarising extracts of a vector setcc" (#118693)
Reverts llvm/llvm-project#117566

Breaks libc++ tests with HWASAN
https://lab.llvm.org/buildbot/#/builders/55/builds/3959
2024-12-04 12:36:46 -08:00
Simon Pilgrim
2567feaa13 [X86] Add fabs/fneg rmw style test coverage for #117557
Missed opportunity to avoid use of fpu for store(fabs(load()) style patterns
2024-12-04 18:16:30 +00:00
Simon Pilgrim
77908345d0 [X86] fsxor-alignment.ll - add nounwind to prevent cfi noise in an upcoming change 2024-12-04 18:16:30 +00:00
David Sherwood
4675db5f39
[DAGCombiner] Add support for scalarising extracts of a vector setcc (#117566)
For IR like this:

%icmp = icmp ult <4 x i32> %a, splat (i32 5)
%res = extractelement <4 x i1> %icmp, i32 1

where there is only one use of %icmp we can take a similar approach
to what we already do for binary ops such add, sub, etc. and convert
this into

%ext = extractelement <4 x i32> %a, i32 1
%res = icmp ult i32 %ext, 5

For AArch64 targets at least the scalar boolean result will almost
certainly need to be in a GPR anyway, since it will probably be
used by branches for control flow. I've tried to reuse existing code
in scalarizeExtractedBinop to also work for setcc.

NOTE: The optimisations don't apply for tests such as
extract_icmp_v4i32_splat_rhs in the file

CodeGen/AArch64/extract-vector-cmp.ll

because scalarizeExtractedBinOp only works if one of the input
operands is a constant.
2024-12-04 10:26:51 +00:00
Simon Pilgrim
b1a48af56a
[DAG] SimplifyDemandedVectorElts - add handling for INT<->FP conversions (#117884) 2024-12-04 07:37:01 +00:00
Nikita Popov
b2df007413
[FastISel] Support unreachable with NoTrapAfterNoReturn (#118296)
Currently FastISel triggers a fallback if there is an unreachable
terminator and the TrapUnreachable option is enabled (the ISD::TRAP
selection does not actually work).

Add handling for NoTrapAfterNoReturn, in which case we don't actually
need to emit a trap. The test is just there to make sure there is no
FastISel fallback (which is why I'm not testing the case without
noreturn). We have other tests that check the actual unreachable codegen
variations.
2024-12-03 12:54:26 +01:00
Simon Pilgrim
4930f69b78 [X86] canonicalizeShuffleWithOp - add initial shuffle(sint_to_fp(x)) -> sint_to_fp(shuffle(x)) handling
Another tentative step towards folding shuffles through conversion ops - initially limited to cases where the src/dst types are matching width.
2024-12-02 12:03:04 +00:00
antangelo
73f087b331
[NFC][SelectionDAG] Replace generic @llvm.expect.with.probability codegen test with X86 test (#117848)
Adds test case for X86 to check that the output of
@llvm.expect.with.probability's generic lowering is reasonable. This
replaces a generic test which only asserts that llc does not crash.
2024-12-01 17:46:08 -05:00
Simon Pilgrim
31b7d4333a
[DAG] Extend extract_element(bitcast(scalar_to_vector(X))) -> trunc(srl(X,C)) (#117900)
When extracting a smaller integer from a scalar_to_vector source, we were limited to only folding/truncating the lowest bits of the scalar source.

This patch extends the fold to handle extraction of any other element, by right shifting the source before truncation.

Fixes a regression from #117884
2024-11-29 17:24:38 +00:00
Simon Pilgrim
5c181a9191 [X86] update vector shift lowering tests to take poison arg instead of undef 2024-11-29 16:03:35 +00:00
Simon Pilgrim
2a18162daa [X86] update shuffle lowering tests to take poison arg instead of undef 2024-11-29 16:03:35 +00:00
Phoebe Wang
bbea1dee28
[X86][FP16] Fix masking problem of VF[,C]MADDCSH intrinsics (#118071)
Fixes: #98306
2024-11-29 20:58:48 +08:00
Simon Pilgrim
55dd475d1d [X86] Fold (v2i64 (scalar_to_vector (i64 (bitcast (double))))) -> (bitcast (v2f64 scalar_to_vector))
This can occur more frequently after the MMX retirement if anyone is still using MMX intrinsics that now wrap to SSE
2024-11-29 12:30:55 +00:00
Simon Pilgrim
568ae0afab [X86] widen_shuffle-1.ll - update shuffle tests to take poison arg instead of undef 2024-11-29 11:57:54 +00:00
Simon Pilgrim
1784275e43 [X86] vector-shuffle-masked.ll - update extract_subvector shuffle tests to take poison arg instead of undef 2024-11-29 11:57:54 +00:00
Simon Pilgrim
044362215d [X86] Add test for new _mm_movpi64_epi64 lowering
With the MMX retirement, _mm_movpi64_epi64 now lowers to shuffle((__m64)(double)x,(__m64)0) pattern - which demonstrates a unnecessary FPU->GPU->FPU transfer
2024-11-29 11:57:53 +00:00
Simon Pilgrim
7ed36b9ec6 [X86] Add missing REQUIRES to test case for #114360 2024-11-29 10:35:05 +00:00
Simon Pilgrim
cb4f22c0a7 [X86] Adjust triple on test case for #114360
An attempt to fix a buildbot failure on clang-x64-windows-msvc
2024-11-29 10:02:10 +00:00
Simon Pilgrim
961c66c571 [X86] shrinkAndImmediate - bail on failed constant fold
Workaround for issue #114360 where shrinkAndImmediate folds away the AND after the ZEXT has already been folded away to SUBREG_TO_REG losing the implicit zext guarantee.

There's the possibility that other instructions can result in a similar regression, but this is a stopgap until I can investigate whether shrinkAndImmediate needs to be replaced entirely.

Fixes #114360
2024-11-28 19:00:43 +00:00
Simon Pilgrim
611ccfcae9 [X86] Add reduced test case for #114360 2024-11-28 18:00:47 +00:00
Simon Pilgrim
ddaf1d6878 [X86] Add GFNI test coverage for vXi8 LZCNT/TZCNT 2024-11-28 13:43:14 +00:00
abhishek-kaushik22
9bdf683ba6
[X86] Enforce strict pre-legalization to combine in scalarizeExtEltFP (#117681)
Use a `DCI` object to actually check the DAG combine level instead of
using the type `i1` because this assumption fails on AVX512 where we
have types like `v8i1` after legalization.

Closes #117684
2024-11-28 08:19:10 +08:00
Simon Pilgrim
f30f7a084c [X86] canonicalizeShuffleWithOp - initial support for shuffle(cvt(x),cvt(y)) -> cvt(shuffle(x,y))
Initial support is just for UNPCKL(CVTPH2PS(X),CVTPH2PS(Y)) -> CVTPH2PS(UNPCKL(X,Y))

Making this more general for other shuffles/conversions will have to be done carefully as we have to handle changes in src/dst element width, so I just handled the CVTPH2PS regression case.

Fixes #83414
2024-11-27 12:38:52 +00:00
Thurston Dang
0d15d46362
[ubsan] Change ubsan-unique-traps to use nomerge instead of counter (#117651)
https://github.com/llvm/llvm-project/pull/65972 (continuation of
https://reviews.llvm.org/D148654) had considered adding nomerge to
ubsantrap, but did not proceed with that because of
https://github.com/llvm/llvm-project/issues/53011. Instead, it added a
counter (based on TrapBB->getParent()->size()) to each ubsantrap call.
However, this counter is not guaranteed to be unique after inlining, as
shown by https://github.com/llvm/llvm-project/pull/83470, which can
result in ubsantraps being merged by the backend.

https://github.com/llvm/llvm-project/pull/101549 has since fixed the
nomerge limitation ("It sets nomerge flag for the node if the
instruction has nomerge arrtibute."). This patch therefore takes
advantage of nomerge instead of using the counter, guaranteeing that the
ubsantraps are not merged.

This patch is equivalent to
https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge
and updates tests (https://github.com/llvm/llvm-project/pull/117649:
ubsan-trap-merge.c; https://github.com/llvm/llvm-project/pull/117657:
ubsan-trap-merge.ll, ubsan-trap-nomerge.ll; catch-undef-behavior.c).
2024-11-26 21:13:00 -08:00
Sergei Barannikov
61a23646c9
[SjLjEHPrepare] Configure call sites correctly (#117656)
After 9fe78db4, the pass inserts `store volatile i32 -1, ptr %call_site`
before all invoke instruction except the one in the entry block, which
has the effect of bypassing landing pads on exceptions.

When configuring the call site for a potentially throwing instruction
check that it is not `InvokeInst` -- they are handled by earlier code.
2024-11-27 08:03:47 +03:00
Thurston Dang
dde7f4d024
[NFC][clang] Add ubsan-trap-merge.ll test to show absence of nomerge considered harmful (#117657)
These testcases demonstrate that ubsan intrinsics are merged in the
backend iff nomerge is missing from ubsantrap intrinsics.

This is based on the observation and testcase by Vitaly Buka in
https://github.com/llvm/llvm-project/pull/83470.
2024-11-26 14:21:05 -08:00
Daniel Zabawa
c1a3960abe
[X86] Add APX imulzu support. (#116806)
Add patterns to select 16b imulzu with -mapx-feature=zu, including
folding of zero-extends of the result. IsDesirableToPromoteOp is changed
to leave 16b multiplies by constant un-promoted, as imulzu will not
cause partial-write stalls.
2024-11-26 08:26:23 +08:00
Phoebe Wang
2ab84a60ff
[X86][FP16][BF16] Improve vectorization of fcmp (#116153) 2024-11-26 08:17:48 +08:00
Simon Pilgrim
1b18ce57f3 [X86] vector-interleaved-load-i16-stride-2.ll - regenerate with AVX512 common prefix 2024-11-25 16:05:22 +00:00
Serge Pavlov
809c5ac3b0
[X86] Modify tests for constrained rounding functions (#116951)
The existing tests for constrained functions often use constant
arguments. If constant evaluation is enhanced, such tests will not check
code generation of the tested functions. To avoid it, the tests are
modified to use loaded value instead of constants. Now only the tests
for rounding functions are changed.
2024-11-25 21:39:35 +07:00
Simon Pilgrim
70bd80dc51 [X86] combineTargetShuffle - commute VPERMV3 shuffles so any load is on the RHS
This helps ensure we lower to VPERMI2/T2 instructions that we can commute the index arg to VPERMT2/I2.

Similar to 1e31a4529244ead9f12abed524f33a48515abee2 to handle cases where the one use load appears after further folding (keep the lowerShuffleWithPERMV version as this can handle the non-VLX widening case as well).
2024-11-23 15:27:10 +00:00
Simon Pilgrim
1e31a45292 [X86] lowerShuffleWithPERMV - commute VPERMV3 shuffles so any load is on the RHS
This helps ensure we lower to VPERMI2/T2 instructions that we can commute the index arg to VPERMT2/I2.

Prep work for #79799
2024-11-23 10:47:30 +00:00
Simon Pilgrim
dbb21df2a2 [X86] vector-shuffle-avx512.ll - regenerate TERNLOG comments 2024-11-23 10:47:30 +00:00
Félix-Antoine Constantin
7a56dc7245
[Clang] Attribute NoFPClass should not prevent tail call optimization. (#116741)
Fixes #111950
2024-11-22 17:28:45 -08:00
Lei Wang
cf83a7fdc2
[SHT_LLVM_BB_ADDR_MAP] Add an option to skip emitting bb entries (#114447)
Sometimes we want to use a `PgoAnalysisMap` feature that doesn't require
the BB entries info, e.g. only the `FuncEntryCount`, but the BB entries
is emitted by default, so I'm adding an option to skip the info for this
case to save the binary size(can save ~90% size of the section). For
implementation, it extends a new field(`OmitBBEntries`) in
`BBAddrMap::Features` for this and it's controlled by a switch
`--basic-block-address-map-skip-bb-entries`.

Note that this naturally supports backwards compatibility as the field
is zero for the old version, matches the decoding in the new version
llvm.
2024-11-22 11:51:34 -08:00
Simon Pilgrim
5ac81a1d15 [X86] Add test coverage for #79799 2024-11-22 18:49:48 +00:00
Simon Pilgrim
29f11f0a32
[X86] Add missing reg/imm attributes to VRNDSCALES instruction names (#117203)
More canonicalization of the instruction names to make the predictable - more closely matches VRNDSCALEP / VROUND equivalent instructions
2024-11-22 17:45:30 +00:00
Simon Pilgrim
600a83bf9b [X86] IsNOT - match or(not(X),not(Y)) -> and(X,Y)
Fixes #116977
2024-11-21 10:35:56 +00:00
Simon Pilgrim
97ac84846a [X86] Add test coverage for #116977 2024-11-21 10:35:55 +00:00
abhishek-kaushik22
a23260087d
[SDAG] [X86] Extend SplitVecOp_VSETCC for STRICT_FSETCCS (#116768)
Closes #116767
2024-11-21 17:43:01 +08:00
Phoebe Wang
7b5b01980c
Revert "[X86] Recognize POP/ADD/SUB modifying rsp in getSPAdjust. (#114265) (#117089)
This reverts commit 6fb7cdff3d90c565b87a253ff7dbd36319879111.
2024-11-21 09:16:22 +08:00
Simon Pilgrim
3a5cf6d99b
[X86] Rename AVX512 VEXTRACT/INSERT??x? to VEXTRACT/INSERT??X? (#116826)
Use uppercase in the subvector description ("32x2" -> "32X4" etc.) - matches what we already do in VBROADCAST??X?, and we try to use uppercase for all x86 instruction mnemonics anyway (and lowercase just for the arg description suffix).
2024-11-20 08:25:01 +00:00
Simon Pilgrim
95ab42661e
[X86] Attempt to canonicalize vXf64 SHUFPD shuffle masks with undef elts to improve further folding (#116419)
Currently when creating a SHUFPD immediate mask, any undef shuffle elements are set to 0, which can limit options for further shuffle combining.

This patch attempts to canonicalize the mask to improve folding: first by detecting a per-lane broadcast style mask (which can allow us to fold to UNPCK instead), and second ensure any undef elements are set to an 'inplace' value to improve chances of the SHUFPD later folding to a BLENDPD (or be bypassed in a SimplifyMultipleUseDemandedVectorElts call).

This is very similar to canonicalization we already attempt in getV4X86ShuffleImm for vXi32/vXf32 SHUFPS/SHUFD shuffles.
2024-11-19 10:45:07 +00:00
Sergei Barannikov
6f53ae6e61
[X86] Properly chain PROBED_ALLOCA / SEG_ALLOCA (#116508)
These nodes should appear between CALLSEQ_START / CALLSEQ_END.
Previously, they could be scheduled after CALLSEQ_END because the nodes
didn't update the chain.

The change in a test is due to X86 call frame optimizer pass bailing out
for a particular call when CALLSEQ_START / CALLSEQ_END are not in the
same basic block. This happens because SEG_ALLOCA is expanded into a
sequence of basic blocks early. It didn't bail out before because the
closing CALLSEQ_END was scheduled before SEG_ALLOCA, in the same basic
block as CALLSEQ_START.

While here, simplify creation of these nodes: allocating a virtual
register and copying `Size` into it were unnecessary.
2024-11-19 13:29:58 +03:00
Freddy Ye
97836bed63
Reland "[X86] Support -march=diamondrapids (#113881)" (#116564)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-11-18 10:40:32 +08:00
Freddy Ye
90e92239bd
Revert "[X86] Support -march=diamondrapids (#113881)" (#116563)
This reverts commit 826b845c9e97448395431be3e4e5da585bd98c5e.
2024-11-18 08:45:28 +08:00
Freddy Ye
826b845c9e
[X86] Support -march=diamondrapids (#113881)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-11-18 08:31:17 +08:00
Phoebe Wang
56720a47bb
[X86][StrictFP] Add missing patterns for AVX512 fmin/fmax (#116240)
Fix crash after #109512, see https://godbolt.org/z/M6aP5Ka4j
2024-11-15 19:09:57 +08:00
Akshat Oke
2de1e06736
[CodeGen][NewPM] Port RegUsageInfoCollector pass to NPM (#113874) 2024-11-15 12:00:09 +05:30
Daniel Zabawa
6fb7cdff3d
[X86] Recognize POP/ADD/SUB modifying rsp in getSPAdjust. (#114265)
This code assumed only PUSHes would appear in call sequences. However,
if calls require frame-pointer/base-pointer spills, only the PUSH
operations inserted by spillFPBP will be recognized, and the adjustments
to frame object offsets in prologepilog will be incorrect.

This change correctly reports the SP adjustment for POP and ADD/SUB to
rsp, and an assertion for unrecognized instructions that modify rsp.
2024-11-14 17:20:16 +01:00