57368 Commits

Author SHA1 Message Date
Luke Lau
771f6b9f43
[RISCV][VLOPT] Add support for Widening Floating-Point Fused Multiply-Add Instructions (#126485)
We already had getOperandInfo support, so this marks the instructions as
supported in isCandidate. It also adds support for vfwmaccbf16.v{v,f}
from zvfbfwma
2025-02-10 19:55:22 +08:00
Luke Lau
71ee257a1d [RISCV][VLOPT] Precommit tests for opt info on passthrus. NFC
Currently we are returning the wrong operand info for passthru
operands.
2025-02-10 19:47:04 +08:00
ZhaoQi
0b5c318127
[LoongArch] Merge base and offset for tls-le code sequence (#122999)
Adapt the merge base offset pass to optimize the tls-le code sequence.
2025-02-10 19:44:24 +08: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
Cullen Rhodes
317a644ae6
[SDAG] Precommit tests for #126207 (NFC) (#126208)
Add missing test coverage for codepaths touched by #126207.
2025-02-10 09:13:02 +00:00
David Green
b3e74e307f
[AArch64] Add SUBHN patterns for xor variant (#126100)
`xor x, -1` can be treated as `sub -1, x`, add patterns for generating
subhn as opposed to a not.

Fixes #123999
2025-02-10 09:09:14 +00:00
ZhaoQi
91682da438
[LoongArch] Pre-commit tests for tls-le merge base offset. NFC (#122998)
Similar to tests in `merge-base-offset.ll`, except for tests of
blockaddress.

A later commit will optimize this.
2025-02-10 16:40:07 +08:00
Shilei Tian
70fdd9f0a2
[GlobalISel] Check whether G_CTLZ is legal in matchUMulHToLShr (#126457)
We need to check `G_CTLZ` because the combine uses `G_CTLZ` to get log
base 2,
and it is not always legal for on a target.

Fixes SWDEV-512440.
2025-02-10 00:11:09 -05:00
Shilei Tian
967973512b
[AMDGPU] Don't unify divergent exit nodes with musttail calls (#126395)
Fixes SWDEV-512254.
2025-02-09 21:48:24 -05:00
Jonathan Thackray
560cea61ab
[NFC][AArch64] move AArch64 non auto-generated tests to static file (#126312)
Move AArch64 non auto-generated test code into a static file, since the
script `./llvm/test/CodeGen/AArch64/Atomics/generate-tests.py` will overwrite
these tests when re-run. (Test code was originally added in change
465bc5e729fd755880b9a288de42a37ad1206301)
2025-02-10 00:03:05 +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
Min-Yih Hsu
c40877d095
[RISCV] Attach an implicit source operand on vector copies (#126155)
Somtimes when we're breaking up a large vector copy into several smaller
ones, not every single smaller source registers are initialized at the
time when the original COPY happens, and the verifier will not be
pleased when seeing the smaller copies reading from an undef register.
This patch is a workaround for the said issue by attaching an implicit
read of the source operand on the newly generated copies.

This is tested by llvm/test/CodeGen/RISCV/rvv/vector-interleave.ll which
would have crashed the compiler without this fix when
LLVM_EXPENSIVE_CHECK is enabled. Original context:
https://github.com/llvm/llvm-project/pull/124825#issuecomment-2639097531

---------

Co-authored-by: Craig Topper <craig.topper@sifive.com>
2025-02-08 16:25:27 -08:00
Akshat Oke
564b9b7f4d
Revert "CodeGen][NewPM] Port MachineScheduler to NPM. (#125703)" (#126268)
This reverts commit 5aa4979c47255770cac7b557f3e4a980d0131d69 while I
investigate what's causing the compile-time regression.
2025-02-08 15:36:48 +05:30
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
Durgadoss R
f3040498f0
[NVPTX] Add tcgen05 wait/fence/commit intrinsics (#126091)
This patch adds intrinsics for tcgen05 wait,
fence and commit PTX instructions.

lit tests are added and verified with a
ptxas-12.8 executable.

Docs are updated in the NVPTXUsage.rst file.

Signed-off-by: Durgadoss R <durgadossr@nvidia.com>
2025-02-07 22:10:25 +05:30
David Green
2c43479683
[AArch64] Fix op mask detection in performZExtDeinterleaveShuffleCombine (#126054)
Given a zext from an extract vector, with a shuffle mask like <4, 0, 0, 4> we
would previously recognize the top half as a deinterleave. In order to convert
into a uzp we should have been checking that the bottom half is also poison.

Fixes #125989
2025-02-07 16:37:05 +00:00
Brox Chen
2b43543afb
[AMDGPU][True16][MC][CodeGen] true16 for v_alignbyte_b32 (#125706)
Support true16 format for v_alignbyte_b32 in MC and CodeGen
2025-02-07 09:54:11 -05:00
Yashas Andaluri
a361de6d13
[RDF] Create phi nodes for clobbering defs (#123694)
When a def in a block A reaches another block B that is in A's iterated
dominance frontier, a phi node is added to B for the def register.

A clobbering def can be created at a call instruction, for a register
clobbered by a call.
However, phi nodes are not created for a register, when one of the
reaching defs of the register is a clobbering def.

This patch adds phi nodes for registers that have a clobbering reaching
def. These additional phis help in checking reaching defs for an
instruction in RDF based copy propagation and addressing mode
optimizations.
2025-02-07 08:28:29 -06:00
Steven Perron
cfd8980fe7
[SPIRV] Handle vector load/store for RWBuffer (#125581)
The type inference for `spv_resource_getpointer` must look at the uses
of the intrinsic. The type of the handle will be a scalar type, but it
can still be read or written as a vector of that type.

Fixes https://github.com/llvm/llvm-project/issues/124551.
2025-02-07 09:12:35 -05:00
Florian Hahn
991123f2fb
[X86] Add test where storing return addr clobbers argument stack slot.
Currently for the test the return address is written to the stack before
loading the argument from an aliasing stack slot.
2025-02-07 13:38:17 +00:00
David Green
6424abcd6c
[AArch64] Enable AvoidLDAPUR for cpu=generic between armv8.4 and armv9.3. (#125261)
As added in #124274, CPUs in this range can suffer from performance
issues with ldapur. As the gain from ldar->ldapr is expected to be
greater than the minor gain from ldapr->ldapur, this opts to avoid the
instruction under the default -mcpu=generic when the -march is less that
armv8.8 / armv9.3.

I renamed AArch64Subtarget::Others to AArch64Subtarget::Generic to be
clearer what it means.
2025-02-07 10:16:57 +00:00
Benjamin Maxwell
4bf97aa818
[IR] Add llvm.modf intrinsic (#121948)
This adds the `llvm.modf` intrinsic, legalization, and lowering (mostly
reusing the lowering for sincos and frexp).

The `llvm.modf` intrinsic takes a floating-point value and returns both
the integral and fractional parts (as a struct).

```
declare { float, float }             @llvm.modf.f32(float  %Val)
declare { double, double }           @llvm.modf.f64(double %Val)
declare { x86_fp80, x86_fp80 }       @llvm.modf.f80(x86_fp80  %Val)
declare { fp128, fp128 }             @llvm.modf.f128(fp128 %Val)
declare { ppc_fp128, ppc_fp128 }     @llvm.modf.ppcf128(ppc_fp128  %Val)
declare { <4 x float>, <4 x float> } @llvm.modf.v4f32(<4 x float>  %Val)
```

This corresponds to the libm `modf` function but returns multiple values
in a struct (rather than take output pointers), which makes it easier to
vectorize.
2025-02-07 09:25:13 +00:00
Mahesh-Attarde
35afd022ee
[X86][GlobalISel] Support G_FCMP for scalar cases (#123598)
With this patch, we are enabling comparisons for Long double (80) types
on X87 stack. It lowers G_FCMP.

---------

Co-authored-by: mattarde <mattarde@intel.com>
2025-02-07 13:01:21 +05:30
Matt Arsenault
d21fc58aee
AMDGPU: Use default shouldRewriteCopySrc (#125535)
This was ultimately working around bugs in subregister handling
in peephole-opt. In the common case, it would give up on folding
anything into a subregister extract copy.
2025-02-07 12:31:14 +07:00
Sam Elliott
50cdf6cbc5
[RISCV] Allow spilling to unused Zcmp Stack (#125959)
This is a tiny change that can save up to 16 bytes of stack allocation,
which is more beneficial on RV32 than RV64.

cm.push allocates multiples of 16 bytes, but only uses a subset of those
bytes for pushing callee-saved registers. Up to 12 (rv32) or 8 (rv64)
bytes are left unused, depending on how many registers are pushed.
Before this change, we told LLVM that the entire allocation was used, by
creating a fixed stack object which covered the whole allocation.

This change instead gives an accurate extent to the fixed stack object,
to only cover the registers that have been pushed. This allows the
PrologEpilogInserter to use any unused bytes for spills. Potentially
this saves an extra move of the stack pointer after the push, because
the push can allocate up to 48 more bytes than it needs for registers.

We cannot do the same change for save/restore, because the restore
routines restore in batches of `stackalign/(xlen/8)` registers, and we
don't want to clobber the saved values of registers that we didn't tell
the compiler we were saving/restoring - for instance `__riscv_restore_0`
is used by the compiler when it only wants to save `ra`, but will end up
restoring `ra` and `s0`.
2025-02-06 19:45:47 -08:00
Mingming Liu
5399782508
[IR] Generalize Function's {set,get}SectionPrefix to GlobalObjects, the base class of {Function, GlobalVariable, IFunc} (#125757)
This is a split of https://github.com/llvm/llvm-project/pull/125756
2025-02-06 14:51:13 -08:00
Sam Elliott
624dc00e76
[RISCV][NFC] Remove nounwind from push/pop tests (#125939)
These tests are for frame handling code with push/pop. To increase
coverage of CFI/Unwind info, this removes the `nounwind` annotations and
regenerates the checks for this test.
2025-02-06 12:44:24 -08:00
Justin Fargnoli
b2bd3a45ec
[NVPTX] Require asserts in unrecognized-sm1x.ll (#126105)
Fix clang-with-thin-lto-ubuntu - failed build
2025-02-06 11:17:55 -08:00
Simon Pilgrim
5c3d1463ed [X86] avx512-arith.ll - regenerate VPTERNLOG comments 2025-02-06 18:30:54 +00:00
Craig Topper
932d0ce325 Recommit "[RISCV] Prefer (select (x < 0), y, z) -> x >> (XLEN - 1) & (y - z) + z even with Zicond. (#125772)"
With the test changes.

Original message:

The Zicond version of this requires an li instruction and an
additional register.

Without Zicond we match this in a DAGCombine on RISCVISD::SELECT_CC.

This PR has 2 commits. I'll pre-commit the test change if this looks
good.
2025-02-06 10:29:45 -08:00
Jeffrey Byrnes
16f7e961c6
[AMDGPU] Allow rematerialization of instructions with virtual register uses (#124327)
Remove the restriction that scheduling rematerialization candidates
cannot have virtual reg uses.

Currently, this only allows for virtual reg uses which are already live
at the rematerialization point, so bring in allUsesAvailableAt to check
for this condition. Because of this condition, the uses of the remats
will already be live in to the region, so the remat won't increase
live-in pressure.

Add an expensive check to check this condition.
2025-02-06 10:16:28 -08:00
David Green
11c3f52bbb [AArch64] Add test for subhn xor pattern. NFC 2025-02-06 17:26:10 +00:00
Virginia Cangelosi
875e014471
[AArch64] Codegen for new SCVTF/UCVTF variants (FEAT_FPRCVT) (#123767)
Adds patterns of new SCVTF/UCVTF instructions to tablegen, with
associated test .ll file.
2025-02-06 17:12:22 +00:00
Luke Quinn
d5666294e9
[RISCV] Porting hasAllNBitUsers to RISCV GISel for instruction select (#125795)
Ported hasAllNBitUsers to RISCV GISel side. Add GISelPredicate code to
each of the 16,32, and 64 bit words. It allows for generation of
optimized packw sequences along with other transparent narrowing
operations. Included a few new .ll files to expand testing and limited
the OptW pass Optimization to fewer options until GISel is ready for
more code generation paths

---------

Signed-off-by: Luke Quinn <quic_lquinn@quicinc.com>
2025-02-06 11:57:52 -05:00
Matt Arsenault
c268a3f093 DAG: Fix extract of load combine with mismatched vector element type
Fix the case where the vector element type of the loaded extractelement
input does not match the result type of the extract.

This fixes a regression reported after
c55a7659b38946350315ac4a18d9805deb1f0a54
2025-02-06 22:56:56 +07:00
Nikita Popov
88b1d16c4a [Mips] Use getSignedConstant() in or combine
Fixes https://github.com/llvm/llvm-project/issues/125954.
2025-02-06 16:27:42 +01:00
Valery Chernov
e225677b1f
[NVPTX] Update setmaxnreg intrinsic lowering (#125846)
The setmaxnreg PTX instruction is supported on all arch-conditionals,
known up-to cuda-12.8, from sm90 onwards. This patch
updates the predicate checks to handle this. The feature is additionally
tested in setmaxnreg-sm100a.ll
2025-02-06 15:23:55 +00:00
Philip Reames
f2ac265c22
[RISCV] Reduce the LMUL for a vrgather operation if legal (#125768)
If we're lowering a shuffle to a vrgather (or vcompress), and we know
that a prefix of the operation can be done while producing the same
(defined) lanes, do the operation with a narrower LMUL.
2025-02-06 07:15:36 -08:00
Benjamin Maxwell
e470dcae8d
[AArch64][SME] Reduce ptrue count when filling p-regs from z-regs (#125523)
Currently, each expansion of `FILL_PPR_FROM_ZPR_SLOT_PSEUDO` creates a
new ptrue instruction. This patch adds a simple method to reuse a
previous ptrue instruction when expanding back-to-back fill pseudos.
2025-02-06 14:30:19 +00:00
Graham Hunter
b74176a3a2
[AArch64][SelectionDAG] Generate clastb for extract.last.active (#112738)
This patch improves SVE codegen for the vector extract last active
intrinsic, using either the lastb instruction (if the passthru value was
poison or undef), or the clastb instruction.
2025-02-06 13:38:53 +00:00
Simon Pilgrim
f82902fef4
[X86] Fold (f16 bitcast extract_vectorelt(v,0)) to (extract_vectorelt (v8f16 bitcast(v,0))) (#125877)
Also handles possible truncations from i32 to i16.

Cleans up some of the poor codegen identified in #98630
2025-02-06 08:29:39 +00:00
Justin Fargnoli
de5f6432ef
[NVPTX] Remove sm_1x / non-ABI compilation support (#125977)
@Artem-B, I believe you said we don't intend to support `sm_1x`.
Assuming that's correct, this PR will remove all remaining support I
could find for `sm_1x`.
2025-02-05 19:41:59 -08:00
Phoebe Wang
8c222c122f
[X86] Do not combine LRINT and TRUNC (#125848)
Per to discussions in #125324, most participants are opposed to this
optimization. So remove the combination to address the concerns.

Fixes #125324
2025-02-06 10:58:37 +08:00
Scott Constable
e223485c9b
[X86] Extend kCFI with a 3-bit arity indicator (#121070)
Kernel Control Flow Integrity (kCFI) is a feature that hardens indirect
calls by comparing a 32-bit hash of the function pointer's type against
a hash of the target function's type. If the hashes do not match, the
kernel may panic (or log the hash check failure, depending on the
kernel's configuration). These hashes are computed at compile time by
applying the xxHash64 algorithm to each mangled canonical function (or
function pointer) type, then truncating the result to 32 bits. This hash
is written into each indirect-callable function header by encoding it as
the 32-bit immediate operand to a `MOVri` instruction, e.g.:
```
__cfi_foo:
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	movl	$199571451, %eax                # hash of foo's type = 0xBE537FB
foo:
        ...
```

This PR extends x86-based kCFI with a 3-bit arity indicator encoded in
the `MOVri` instruction's register (reg) field as follows:

| Arity Indicator | Description | Encoding in reg field |
| --------------- | --------------- | --------------- |
| 0 | 0 parameters | EAX |
| 1 | 1 parameter in RDI | ECX |
| 2 | 2 parameters in RDI and RSI | EDX |
| 3 | 3 parameters in RDI, RSI, and RDX | EBX |
| 4 | 4 parameters in RDI, RSI, RDX, and RCX | ESP |
| 5 | 5 parameters in RDI, RSI, RDX, RCX, and R8 | EBP |
| 6 | 6 parameters in RDI, RSI, RDX, RCX, R8, and R9 | ESI |
| 7 | At least one parameter may be passed on the stack | EDI |

For example, if `foo` takes 3 register arguments and no stack arguments
then the `MOVri` instruction in its kCFI header would instead be written
as:
```
	movl	$199571451, %ebx                # hash of foo's type = 0xBE537FB
```

This PR will benefit other CFI approaches that build on kCFI, such as
FineIBT. For example, this proposed enhancement to FineIBT must be able
to infer (at kernel init time) which registers are live at an indirect
call target: https://lkml.org/lkml/2024/9/27/982. If the arity bits are
available in the kCFI function header, then this information is trivial
to infer.

Note that there is another existing PR proposal that includes the 3-bit
arity within the existing 32-bit immediate field, which introduces
different security properties:
https://github.com/llvm/llvm-project/pull/117121.
2025-02-06 10:54:22 +08:00
Philip Reames
ed8a6d6155 [RISCV] Add VLA shuffle coverage
Add coverage for a few cases which have come up in discussion of
recent VLA shuffle lowering changes.
2025-02-05 18:47:45 -08:00
Philip Reames
fc10ad1a66
[RISCV] Make single source reverse legal in isShuffleMaskLegal (#125949)
This enables DAG combines to form this mask. Reverse is generally linear
in LMUL so this is reasonable, and results in better codegen for the 2
source variants.

For <= m1, the change is only slightly profitable if at all. We trade
some mask creation and an extract vrsub for a vslideup.vi. This is
likely roughly neutral. At >= m2, this is distinctly profitable as
generic DAG pushes the reverse into the two operands. We effectively
already did this for one operand, but the other was hitting a full
O(LMUL^2) shuffle. Moving that to be O(LMUL/2) operation is a big win.
2025-02-05 18:12:59 -08:00
Min-Yih Hsu
e335ca7b84 [RISCV] Update tests after #124825 2025-02-05 16:13:39 -08:00
Artem Belevich
cd9795c10b
[NVPTX] Fixed few other failing ptxas tests (#125963) 2025-02-05 16:02:00 -08:00
David Green
c552c6c914 [AArch64][GlobalISel] Protect against non-reg operands in matchExtAddvToUdotAddv.
In some situations the first operand to an instruction might not be a register
(for example with intrinsics). We are only interested in extend operations, so
make sure the instruction is one we expect before we attempt to access the
first reg.
2025-02-05 23:57:39 +00:00
Artem Belevich
1c4ee06135
[NVPTX] fix ptxas tests introduced by #124865 (#125927) 2025-02-05 15:47:05 -08:00