20821 Commits

Author SHA1 Message Date
xilinbai-intel
7226b39926
[X86] Support vectorized llvm.fmaximum/fminimum.vXf16 lowering (#120988)
Support the lowering of vectorized FMINIMUM and FMAXIMUM to vminph and
vmaxph on types v8f16, v16f16 when AVX512FP, AVX512VL features are
present, and on type v32f16 when AVX512FP is present.
2024-12-25 17:54:13 +08:00
Fangrui Song
7b23f413d1 MCAsmStreamer: Omit initial ".text"
llvm-mc --assemble prints an initial `.text` from `initSections`.
This is weird for quick assembly tasks that do not specify `.text`.

Omit the .text by moving section directive printing from `changeSection`
to `switchSection`. switchSectionNoPrint now correctly calls the
`changeSection` hook (needed by MachO).

The initial directives of clang -S are now reordered. On ELF targets, we
get `.file "a.c"; .text` instead of `.text; .file "a.c"`.
If there is no function, `.text` will be omitted.
2024-12-22 22:03:44 -08:00
Fangrui Song
5712e293fb [CodeGen] Clean up tests that depend on implicit .text in MCAsmStreamer 2024-12-22 21:11:32 -08:00
Simon Pilgrim
eaf67e062c [X86] IsNOT - don't fold not(pcmpgt(C1, C2)) -> pcmpgt(C2, C1 - 1)
Interferes with constant folding of the pcmpgt node.

Yes another example where topological node sorting would have helped us.

Fixes #120906
2024-12-22 17:21:44 +00:00
Feng Zou
eb812d28f5
[X86] Put R20/R21/R28/R29 later in GR64 list (#120510)
Because these registers require an extra byte to encode in certain
memory form. Putting them later in the list will reduce code size when
EGPR is enabled. And align the same order in GR8, GR16 and GR32 lists.
Example:

    movq (%r20), %r11  # encoding: [0xd5,0x1c,0x8b,0x1c,0x24]
    movq (%r22), %r11  # encoding: [0xd5,0x1c,0x8b,0x1e]
2024-12-19 20:16:34 +08:00
Simon Pilgrim
49fd2dde21
[X86] LowerShift - don't prematurely lower to x86 vector shift imm instructions (#120282)
When splitting 2 unique amount shifts to shuffle(shift(x,c1),shift(x,c2)), don't use getTargetVShiftByConstNode directly to lower, use generic shifts to ensure we make use of any further canonicalization: shl(X,1) to add(X,X) etc. - this can have notably better throughput on some x86 targets.

Noticed on #120270
2024-12-18 16:08:45 +00:00
Sergei Barannikov
d3750412aa
[TableGen][GISel] Improve dead register handling (#120426)
A dead implicit def wasn't marked as dead if it is also an implicit use.
The new approach should also be more straightforward and simplifies
future changes for supporting optional defs and physical register defs.

Pull Request: https://github.com/llvm/llvm-project/pull/120426
2024-12-18 18:58:37 +03:00
Simon Pilgrim
f270c9a7d0 [X86] urem-seteq-illegal-types.ll - regenerate VPTERNLOG comment 2024-12-18 11:58:49 +00:00
Simon Pilgrim
dd8e1adbf2
[X86] LowerShift - track the number and location of constant shift elements. (#120270)
We have several vector shift lowering strategies that have to analyse
the distribution of non-uniform constant vector shift amounts, at the
moment there is very little sharing of data between these analysis.

This patch creates a SmallDenseMap of the different LEGAL constant shift
amounts used, with a mask of which elements they are used in. So far
I've only updated the shuffle(immshift(x,c1),immshift(x,c2)) lowering
pattern to use it for clarity, there's several more that can be done in
followups. Its hoped that the proposed patch #117980 can be simplified
after this patch as well.

vec_shift6.ll - the existing shuffle(immshift(x,c1),immshift(x,c2))
lowering bails on out of range shift amounts, while this patch now skips
them and treats them as UNDEF - this means we manage to fold more cases
that before would have to lower to a SHL->MUL pattern, including some
legalized cases.
2024-12-18 11:36:54 +00:00
Simon Pilgrim
0b4ee8d4ee
[X86] combineKSHIFT - fold kshiftr(kshiftr/extract_subvector(X,C1),C2) --> kshiftr(X,C1+C2) (#115528)
Merge serial KSHIFTR nodes, possibly separated by EXTRACT_SUBVECTOR, to allow mask instructions to be computed in parallel.
2024-12-18 09:48:38 +00:00
Simon Pilgrim
2a922903bf [X86] vector-shift tests - regenerate VPTERNLOG comments 2024-12-17 18:19:15 +00:00
Benjamin Maxwell
a7dafea384
[SDAG] Allow folding stack slots into sincos/frexp in more cases (#118117)
This adds a new helper `canFoldStoreIntoLibCallOutputPointers()` to
check that it is safe to fold a store into a node that will expand to a
library call that takes output pointers. This requires checking for two
(independent) properties:

1. The store is not within a CALLSEQ_START..CALLSEQ_END pair
* If it is, the expansion would lead to nested call sequences (which is
invalid)
2. The node does not appear as a predecessor to the store
* If it does, attempting to merge the store into the call would result
in a cycle in the DAG

These two properties are checked as part of the same traversal in
`canFoldStoreIntoLibCallOutputPointers()`
2024-12-17 10:54:17 +00:00
Matt Arsenault
5e727e8bed
[Statepoint] Treat undef operands less specially (#119682)
This reverts commit f7443905af1e06eaacda1e437fff8d54dc89c487.

This is to avoid an assertion if an undef operand appears in a
stackmap. This is important to avoid hitting verifier errors
when register allocation starts adding undefs in error scenarios.

Rather than trying to treat undef operands as special, leave them
alone and avoid producing an invalid spill. It would a bit more
precise to produce a spill of an undef register here, but that's not
exposed through the storeRegToStackSlot API.

https://reviews.llvm.org/D122605

This was an alternative to https://reviews.llvm.org/D122582
2024-12-17 12:59:46 +07:00
Simon Pilgrim
d7f3775977 [X86] combineEXTRACT_SUBVECTOR - fold extract_subvector(pshufd(v,i)) -> pshufd(extract_subvector(v,i))
Attempt to avoid unnecessary wide PSHUFD or VPERMILIPS/D instructions by pre-extracting the subvector source if thats its only use.
2024-12-16 18:32:12 +00:00
Simon Pilgrim
0954c67d7a [DAG] visitFREEZE - only fold integer types to an all ones constant
ISD::isBuildVectorAllOnes can peek through bitcasts, so this can match against FP NAN (ish) data (e.g. double (bitcast i64 -1)) under certain circumstances - bail if the type isn't an integer and let bitcast folding handle it first.

Fixes #120093
2024-12-16 16:46:38 +00:00
Björn Pettersson
3ad2399148
[DAGCombiner] Refactor and improve ReduceLoadOpStoreWidth (#119564)
This patch make a couple of improvements to ReduceLoadOpStoreWidth.

When determining the minimum size of "NewBW" we now take byte boundaries
into account. If we for example touch bits 6-10 we shouldn't accept
NewBW=8, because we would fail later when detecting that we can't access
bits from two different bytes in memory using a single load. Instead we
make sure to align LSB/MSB according to byte size boundaries up front
before searching for a viable "NewBW".

In the past we only tried to find a "ShAmt" that was a multiple of
"NewBW", but now we use a sliding window technique to scan for a viable
"ShAmt" that is a multiple of the byte size. This can help out finding
more opportunities for optimization (specially if the original type
isn't byte sized, and for big-endian targets when the original
load/store is aligned on the most significant bit).
2024-12-16 12:15:11 +01:00
Matt Arsenault
bb18e49edb
RegAlloc: Use DiagnosticInfo to report register allocation failures (#119492)
Improve the non-fatal cases to use DiagnosticInfo, which will now
provide a location. The allocators attempt to report different errors
if it happens to see inline assembly is involved (this detection is
quite unreliable) using srcloc instead of dbgloc. For now, leave this
behavior unchanged. I think reporting the full location and context
function would be more useful.
2024-12-16 10:49:08 +09:00
Fangrui Song
cd12922235 [test] Change llc -march= to -mtriple=
Similar to 806761a7629df268c8aed49657aeccffa6bca449

-march= is error-prone when running on a host whose OS is different.
2024-12-15 13:08:02 -08:00
Fangrui Song
8d550aa0f0 [test] Replace -march=x86 -mcpu=i386 with -mtriple 2024-12-15 12:57:35 -08:00
Craig Topper
7ece560a50
[GISel] Support narrowing G_ICMP with more than 2 parts. (#119335)
This allows us to support i128 G_ICMP on RV32. I'm not sure how to test
the "left over" part of this as RISC-V always widens to a power of 2
before narrowing.
2024-12-12 09:50:26 -08:00
Pengcheng Wang
da71203e6f
[MISched] Unify the way to specify scheduling direction (#119518)
For pre-ra scheduling, we use two options `-misched-topdown` and
`-misched-bottomup` to force the direction.

While for post-ra scheduling, we use `-misched-postra-direction`
with enumerated values (`topdown`, `bottomup` and `bidirectional`).

This is not unified and adds some mental burdens. Here we replace
these two options `-misched-topdown` and `-misched-bottomup` with
`-misched-prera-direction` with the same enumerated values.

To avoid the condition of `getNumOccurrences() > 0`, we add a new
enum value `Unspecified` and make it the default initial value.

These options are hidden, so we needn't keep the compatibility.
2024-12-12 11:24:07 +08:00
Bjorn Pettersson
22780f808a [DAGCombiner] Fix to avoid writing outside original store in ReduceLoadOpStoreWidth (#119203)
DAGCombiner::ReduceLoadOpStoreWidth could replace memory accesses
with more narrow loads/store, although sometimes the new load/store
would touch memory outside the original object. That seemed wrong
and this patch is simply avoiding doing the DAG combine in such
situations.

Also simplifying the expression used to align ShAmt down to a multiple
of NewBW. Subtracting (ShAmt % NewBW) should do the same thing as the
old more complicated expression.

Intention is to follow up with a patch that make more attempts, trying
to align the memory accesses at other offsets, allowing to trigger
the transform in more situations. The current strategy for deciding
size (NewBW) and offset (ShAmt) for the narrowed operations are a bit
ad-hoc, and not really considering big endian memory order in same
way as little endian.
2024-12-11 15:07:16 +01:00
Phoebe Wang
c69f8296f3
[X86][StrictFP] Add widening support for STRICT_FMIN/STRICT_FMAX (#119391)
Fixes: #119422
2024-12-11 20:21:34 +08:00
Guillaume DI FATTA
a1ee1a9126
[CodeGen] @llvm.experimental.stackmap make operands immediate (#117932)
This pull request modifies the behavior of the
`@llvm.experimental.stackmap` intrinsic to require that its two first
operands (`id` and `numShadowBytes`) be **immediate values**. This
change ensures that variables cannot be passed as two first arguments to
this intrinsic.


Related Issue: https://github.com/llvm/llvm-project/issues/115733

### Testing
- Added new test cases to ensure errors are emitted for non-immediate
operands.
- Ran the full LLVM test suite to verify no regressions were introduced.
2024-12-11 17:41:19 +08:00
Craig Topper
839c8217b9
[LegalizeTypes][RISCV][X86] Legalize FP_ROUND to libcall in SoftPromoteHalfRes_FP_ROUND if the input type is softened. (#119481)
Previously we created an FP_TO_FP16 and legalized it in
SoftenFloatOp_FP_ROUND. This caused i16 to be sent to call lowering
instead of f16. This results in the ABI not being followed if f16 is
supposed to be passed in a different register than i16.

Looking at the libgcc binary for the library function it appears the value
is returned in xmm0 so the X86 test was being miscompiled before.

Fixes #107607.
2024-12-10 22:21:49 -08:00
Phoebe Wang
e088249b74
[X86][FP16] Fix crash issue when AVX512VL is not set (#119309)
Fixes problem reported on #116153.
2024-12-10 18:12:51 +08:00
Phoebe Wang
322eb1a92e
[X86][NFC] Update ternlog comments (#119343) 2024-12-10 16:29:09 +08:00
Simon Pilgrim
078b60dc39 [X86] Only fold to v16i32 VPDPWSSD on targets with useAVX512Regs enabled.
Fixes #119158
2024-12-09 11:56:29 +00:00
David Sherwood
8630a7ba7c
Reapply "[DAGCombiner] Add support for scalarising extracts of a vector setcc (#117566)" (#118823)
[Reverts d57892a2a153ab71a796f07e39d939eae6910c21]

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.

---------

Co-authored-by: Paul Walker <paul.walker@arm.com>
2024-12-09 10:56:44 +00:00
Simon Pilgrim
9aa70419b8 [X86] Canonicalize VPERMV3 to VPERMV if both sources are the same. 2024-12-09 10:27:44 +00:00
abhishek-kaushik22
d6501dc88d
[X86][AVX512] Check input-types to COMX (#118606)
Supported types for COMX are f16, f32 and f64. 
Without this check there's a crash on f80 types.
Fixes: https://github.com/llvm/llvm-project/issues/118605
2024-12-09 12:55:07 +08:00
Phoebe Wang
943cc71a6c
[X86][APX] Convert store(cmov(load(x), y), x) to cstore(y, x) (#118946) 2024-12-07 11:38:43 +08:00
Simon Pilgrim
9ad22cf0ee [X86] lowerV32I16Shuffle - attempt to fold unary shuffle to lane permute + repeated mask
Fixes #79799
2024-12-06 16:25:15 +00:00
Simon Pilgrim
6bc3c9ee6b [X86] combineX86ShuffleChain - always create VPERMV3 nodes if started from a VPERMV3 node
If the root shuffle node was a VPERMV3 node, then we can always replace it with a new VPERMV3 node - it doesn't matter if other variable shuffles in the chain had multiple uses.
2024-12-06 16:25:15 +00:00
Simon Pilgrim
140680c5c8 [X86] Add peephole for (add (concat_vectors vpmaddwd, vpmaddwd)) -> vpdpwssd on VNNI targets
Cleanup for #118433
2024-12-06 16:25:14 +00:00
Simon Pilgrim
1885886b3f [X86] matchIndexRecursively - fix incorrect signed/unsigned constant creation
Fixes #118934
2024-12-06 13:36:43 +00:00
Simon Pilgrim
9d2351ab9a [X86] matchPMADDWD - add matching for (add (X, (pmaddwd Y, Z)) reassociation patterns.
Allows us to match pmaddwd accumulation patterns, and folding to vpdpwssd instructions on VNNI targets

Fixes #118433
2024-12-06 11:34:01 +00:00
Simon Pilgrim
ce4801d373 [X86] vpdpwssd.ll - add test coverage for #118443 2024-12-06 11:34:01 +00:00
Simon Pilgrim
dd7a3d4d79 [X86] Extend #118680 - support f16/bf16 fabs/fneg load-store patterns 2024-12-05 10:31:56 +00:00
Simon Pilgrim
ed9915ffdf [X86] fp16-libcalls.ll - regenerate test checks with vpternlog comments 2024-12-05 10:31:56 +00:00
Simon Pilgrim
722a568432 [X86] Add test coverage for f16/bf16 fabs/fneg load-store tests
Future extension to #118680
2024-12-05 10:31:55 +00:00
Simon Pilgrim
6caf9f8236
[X86] combineStore - fold scalar float store(fabs/fneg(load())) -> store(and/xor(load(),c)) (#118680)
As noted on #117557 - its not worth performing scalar float fabs/fneg on the fpu if we're not doing any other fp ops.

This is currently limited to store + load pairs - I could try to extend this further if necessary, but we need to be careful that we don't end up in an infinite loop with the DAGCombiner foldBitcastedFPLogic combine.

Fixes #117557
2024-12-05 09:36:21 +00:00
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