59584 Commits

Author SHA1 Message Date
Andrei Safronov
3dc09fbf29
[Xtensa] Implement THREADPTR and DFPAccel Xtensa Options. (#145543)
Implment base support of the TLS functionality using Xtensa THREADPTR
Option. Implement basic functionality of the DFPAccel Option(registers
support).
2025-07-02 17:47:07 +03:00
Kai Nacke
ebcf7f91ff
[SystemZ][HLASM] Emit END instruction (#146110)
A HLASM source file must end with the END instruction. It is implemented
by adding a new function to the target streamer. This change also turns
SystemZHLASMSAsmString.h into a proper header file, and only uses the
SystemZTargetHLASMStreamer when HLASM output is generated.
2025-07-02 10:08:25 -04:00
woruyu
bbcebec3af
[DAG] Refactor X86 combineVSelectWithAllOnesOrZeros fold into a generic DAG Combine (#145298)
This PR resolves https://github.com/llvm/llvm-project/issues/144513

The modification include five pattern :
1.vselect Cond, 0, 0 → 0
2.vselect Cond, -1, 0 → bitcast Cond
3.vselect Cond, -1, x → or Cond, x
4.vselect Cond, x, 0 → and Cond, x
5.vselect Cond, 000..., X -> andn Cond, X

1-4 have been migrated to DAGCombine. 5 still in x86 code.

The reason is that you cannot use the andn instruction directly in
DAGCombine, you can only use and+xor, which will introduce optimization
order issues. For example, in the x86 backend, select Cond, 0, x →
(~Cond) & x, the backend will first check whether the cond node of
(~Cond) is a setcc node. If so, it will modify the comparison operator
of the condition.So the x86 backend cannot complete the optimization of
andn.In short, I think it is a better choice to keep the pattern of
vselect Cond, 000..., X instead of and+xor in combineDAG.

For commit, the first is code changes and x86 test(note 1), the second
is tests in other backend(node 2).

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-07-02 15:07:48 +01:00
Steven Perron
4e213159af
[SPIRV] Add FloatControl2 capability (#144371)
Add handling for FPFastMathMode in SPIR-V shaders. This is a first pass
that
simply does a direct translation when the proper extension is available.
This will unblock work for HLSL. However, it is not a full solution.

The default math mode for spir-v is determined by the API. When
targeting Vulkan many of the fast math options are assumed. We should do
something particular when targeting Vulkan.

We will also need to handle the hlsl "precise" keyword correctly when
FPFastMathMode is not available.

Unblockes https://github.com/llvm/llvm-project/issues/140739, but we are
keeing it open to track the remaining issues mentioned above.
2025-07-02 08:48:57 -04:00
jyli0116
9c0743fbc5
[GlobalISel] Allow expansion of urem by constant in prelegalizer (#145914)
This patch allows urem by a constant to be expanded more efficiently to
avoid the need for expensive udiv instructions. This is part of the
resolution to issue #118090
2025-07-02 13:46:36 +01:00
Shilei Tian
c0e9084b1c
[AMDGPU] Add a debug option -amdgpu-snop-padding for GCNHazardRecognizer (#146587)
This can help to identify if there is potential hazards.

Co-authored-by: Byrnes, Jeffrey <Jeffrey.Byrnes@amd.com>
2025-07-02 08:16:38 -04:00
David Sherwood
f575b18fdc
[LV] Add support for partial reductions without a binary op (#133922)
Consider IR such as this:

for.body:
  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
  %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]
  %gep.a = getelementptr i8, ptr %a, i64 %iv
  %load.a = load i8, ptr %gep.a, align 1
  %ext.a = zext i8 %load.a to i32
  %add = add i32 %ext.a, %accum
  %iv.next = add i64 %iv, 1
  %exitcond.not = icmp eq i64 %iv.next, 1025
  br i1 %exitcond.not, label %for.exit, label %for.body

Conceptually we can vectorise this using partial reductions too,
although the current loop vectoriser implementation requires the
accumulation of a multiply. For AArch64 this is easily done with
a udot or sdot with an identity operand, i.e. a vector of (i16 1).

In order to do this I had to teach getScaledReductions that the
accumulated value may come from a unary op, hence there is only
one extension to consider. Similarly, I updated the vplan and
AArch64 TTI cost model to understand the possible unary op.

---------

Co-authored-by: Matt Devereau <matthew.devereau@arm.com>
2025-07-02 13:05:51 +01:00
Andrei Safronov
a2c9f7dbcc
[Xtensa] Implement lowering SELECT_CC/BRCC for Xtensa FP Option. (#145544)
Also minor format changes in disassembler test for Xtensa FP Option.
2025-07-02 13:48:49 +03:00
Paul Walker
7cc8fe2a2c
[LLVM][AArch64] Relax SVE/SME codegen predicates. (#145322)
Code generation predicates like HasSVE2_or_SME implemented a strict
divide between streaming and non-streaming which meant some SME
instructions were not available unless a matching SVE feature was
enabled.
2025-07-02 11:39:33 +01:00
Simon Pilgrim
38200e94f1
[DAG] visitFREEZE - always allow freezing multiple operands (#145939)
Always try to fold freeze(op(....)) -> op(freeze(),freeze(),freeze(),...).

This patch proposes we drop the opt-in limit for opcodes that are allowed to push a freeze through the op to freeze all its operands, through the tree towards the roots.

I'm struggling to find a strong reason for this limit apart from the DAG freeze handling being immature for so long - as we've improved coverage in canCreateUndefOrPoison/isGuaranteedNotToBeUndefOrPoison it looks like the regressions are not as severe.

Hopefully this will help some of the regression issues in #143102 etc.
2025-07-02 11:28:37 +01:00
Qi Zhao
82c0a53763 [LoongArch] Pre-commit for optimizing insert extracted pair elements 2025-07-02 17:38:08 +08:00
Alex Crichton
a8a9a7f95a
[WebAssembly] Fix inline assembly with vector types (#146574)
This commit fixes using inline assembly with v128 results. Previously
this failed with an internal assertion about a failure to legalize a
`CopyFromReg` where the source register was typed `v8f16`. It looks like
the type used for the destination register was whatever was listed first
in the `def V128 : WebAssemblyRegClass` listing, so the types were
shuffled around to have a default-supported type.

A small test was added as well which failed to generate previously and
should now pass in generation. This test passed on LLVM 18 additionally
and regressed by accident in #93228 which was first included in LLVM 19.
2025-07-01 20:26:30 -07:00
jjasmine
e9c9f8f374
[WebAssembly] Fold any/alltrue (setcc x, 0, eq/ne) to [not] any/alltrue x (#144741)
Fixes https://github.com/llvm/llvm-project/issues/50142, a miss of
further vectorization, where we can only achieve zext (xor (any_true),
-1).

Now in test case simd-setcc-reductions, it's converted to all_true.

Also fixes https://github.com/llvm/llvm-project/issues/145177, which is

all_true (setcc x, 0, eq) -> not any_true
any_true (setcc x, 0, ne) -> any_true
all_true (setcc x, 0, ne) -> all_true

---------

Co-authored-by: badumbatish <--show-origin>
2025-07-01 15:27:37 -07:00
jjasmine
4a8c1f7d12
[WebAssembly] [Backend] Wasm optimize illegal bitmask (#145627)
[WebAssembly] [Backend] Wasm optimize illegal bitmask for #131980.

Currently, the case for illegal bitmask (v32i8 or v64i8) is that at the
SelectionDag level, two (four) vectors of v128 will be concatenated
together, then they'll all be SETCC by the same pseudo illegal
instruction, which requires expansion later on.

I opt for SETCC-ing them seperately, bitcast and zext them and then add
them up together in the end.

---------

Co-authored-by: badumbatish <--show-origin>
2025-07-01 15:13:08 -07:00
James Y Knight
ae2104897c
[SelectionDAG] Fix NaN regression in fma dag-combine. (#146592)
After 901e1390c9778a191256335d37802bc631c2d183 (#127770), the DAG
combine would transform `fma(x, 0.0, 1.0)` into `1.0` if
`-fp-contract=fast` was enabled, in addition to when 'x' is marked
nnan/ninf.

It's only valid in the latter case, not the former, so delete the extra
condition.
2025-07-01 18:10:30 -04:00
Alex MacLean
475cd8dfaf
[NVPTX] Further cleanup call isel (#146411)
This change continues rewriting and cleanup around DAG ISel for
formal-arguments, return values, and function calls. This causes some
incidental changes, mostly to instruction ordering and register naming
but also a couple improvements caused by using scalar types earlier in
the lowering.
2025-07-01 14:55:04 -07:00
Changpeng Fang
5035d20dcb
AMDGPU: Implement ds_atomic_async_barrier_arrive_b64/ds_atomic_barrier_arrive_rtn_b64 (#146409)
These two instructions are supported by gfx1250. We define the
instructions and implement the corresponding intrinsic and builtin.

Co-authored-by: Stanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
2025-07-01 11:08:49 -07:00
Simon Pilgrim
b697b801b1 [X86] freeze-vector.ll - fix cut+pasta typo in frozen build vector tests
Ensure we load BOTH scalars, inserted into different positions into separate vectors with the freeze(poison) base

Noticed while triaging regressions in #145939
2025-07-01 17:36:43 +01:00
Sameer Sahasrabuddhe
a34a024812
[AMDGPU][SIInsertWaitCnts] skip meta instructions early (#145720)
When iterating over a block, meta instructions have no effect on wait counts,
but their presence drops the reference to earlier waitcnt instructions before
they are processed. This results in spurious wait counts, which do not affect
correctness, but are also not required in the resulting program. Skipping meta
instructions as soon as they are seen cleans this up.
2025-07-01 22:02:48 +05:30
Guy David
01a6c08533
[PHIElimination] Verify reappropriated COPY is of similar register class, update livevars. (#146337)
Follow up to the second bug that
https://github.com/llvm/llvm-project/pull/131837 introduced, described
in
https://github.com/llvm/llvm-project/pull/131837#issuecomment-3018777795.
2025-07-01 19:18:31 +03:00
Shilei Tian
4dab0b2300
[AMDGPU] Fix wrong reverse operations for v_cmpx_le_u32 (#146398)
Fixes: SWDEV-538616
2025-07-01 11:48:08 -04:00
Simon Pilgrim
6b1c92cbcb [X86] legalize-sub-zero.ll - regenerate test checks 2025-07-01 16:07:32 +01:00
David Green
6e3465cd0f
[AArch64] Fix ldp rename through a bundle (#146415)
std::prev(Paired) will get the previous instruction, that might skip
over the instructions in a bundle to the BUNDLE itself. Change it to
Paired->getPrevNode() to make sure we update the registers in each
instruction in the bundle.
2025-07-01 15:44:59 +01:00
David Green
5332534b9c [ARM] Add neon vector support for ceil
As per #142559, this marks fceil as legal for Neon and upgrades the existing
arm.neon.vrintp intrinsics.
2025-07-01 15:41:10 +01:00
Shilei Tian
bab9d4c2d7
[NFC][AMDGPU] Pre-commit a test case that shows wrong reverse operation is used for V_CMPX_LE_U32 (#146527) 2025-07-01 09:57:04 -04:00
Shilei Tian
3355cca938
[NFC][AMDGPU] Auto generate check lines for some test cases (#146400) 2025-07-01 09:25:08 -04:00
Sudharsan Veeravalli
15ab4bb5c8
[Hexagon] Implement shouldConvertConstantLoadToIntImm (#146452)
This will convert loads of constant strings to immediate values. Put
this behind a flag that is enabled by default so that we can toggle it
if need be.
2025-07-01 17:52:09 +05:30
Simon Pilgrim
56841565db
[DAG] canCreateUndefOrPoison - add handling for CTTZ/CTLZ_ZERO_UNDEF nodes (#146501)
CTTZ/CTLZ_ZERO_UNDEF nodes can only create poison if the source value is zero - so check with isKnownNeverZero

Pulled out of #146361 and reapplied now that #146490 has landed.
2025-07-01 12:44:45 +01:00
Jim Lin
a6bb895efe [RISCV] Fix typo in header of llvm/test/CodeGen/RISCV/rvv/select-fp.ll. NFC.
I believe that the second and third llc tests in the header tend to use
zvfhmin extension rather than zvfh; otherwise, they would be duplicates.
2025-07-01 17:09:37 +08:00
Simon Pilgrim
372e332a57 [X86] freeze-unary.ll - remove unnecessary freeze from CTLZ/CTTZ_ZERO_UNDEF tests 2025-07-01 08:32:28 +01:00
Phoebe Wang
67b740bd73
[X86] Add diagnostic for fp128 inline assemble for 32-bit (#146458)
Suggested by Craig from #146259
2025-07-01 12:39:43 +08:00
Qi Zhao
66cc167dfa [LoongArch] Add tests for inserting extracted integer elements. NFC 2025-07-01 10:21:33 +08:00
Jim Lin
70db191efa
[RISCV] Add LLVM IR intrinsicis vrgatherei16/vslideup/vslidedown support for Zvfbfmin (#146312)
This patch add LLVM IR intrinsicis vrgatherei16/vslideup/vslidedown
support for Zvfbfmin.
2025-07-01 08:48:13 +08:00
Deric C.
12409a18f6
[DirectX] Implement memcpy in DXIL CBuffer Access pass (#144436)
Fixes #141840

This PR implements support for the `memcpy` intrinsic in the DXIL
CBuffer Access pass with the following restrictions:

- The CBuffer Access must be the `src` operand of `memcpy` and must be
direct (i.e., not a GEP)
- The type of the CBuffer Access must be of an Array Type

These restrictions greatly simplify the implementation of `memcpy` yet
still covers the known uses in DML shaders.

Furthermore, to prevent errors like #141840 from occurring silently
again, this PR adds error reporting for unsupported users of globals in
the DXIL CBuffer Access pass.
2025-06-30 16:32:43 -07:00
realqhc
6896d8a05d
[RISCV][MC] Support Base P non-GPR pair instructions (#137927) 2025-07-01 08:01:06 +10:00
Jeffrey Byrnes
d599bdeaa4
[AMDGPU] Autogen checks for test (#146421)
Needed for upcoming PR for RA priorities
2025-06-30 14:36:23 -07:00
Ellis Hoag
0d1392e979
[MachineOutliner] Remove LOHs from outlined candidates (#143617)
Remove Linker Optimization Hints (LOHs) from outlining candidates
instead of simply preventing outlining if LOH labels are found in the
candidate. This will improve the effectiveness of the machine outliner
when LOHs are enabled (which is the default).

In
https://discourse.llvm.org/t/loh-conflicting-with-machineoutliner/83279/1
it was observed that the machine outliner is much more effective when
LOHs are disabled. Rather than completely disabling LOH, this PR aims to
keep LOH in most places and removing them from outlined functions where
it could be illegal. Note that we are conservatively removing all LOHs
from outlined functions for simplicity, but I believe we could retain
LOHs that are in the intersection of all candidates.

It should be ok to remove these LOHs since these blocks are being
outlined anyway, which will harm performance much more than the gain
from keeping the LOHs.
2025-06-30 14:29:06 -07:00
Mahesh-Attarde
56ef00a59d
[X86][GlobalISel] Fix RegBank issue for G_FABS (#145674)
Fixes hidden issue in https://github.com/llvm/llvm-project/pull/136718. 
It removes custom selection code since problem was in RegBank
assignment
2025-06-30 22:52:12 +02:00
Simon Pilgrim
529508c187
[DAG] canCreateUndefOrPoison - add handling for CTTZ/CTLZ nodes (#146361)
ISD::CTTZ/CTLZ nodes handle all input values and do not create undef/poison.

The *_ZERO_UNDEF variants will be handled in a future patch.
2025-06-30 17:48:05 +01:00
David Green
6bd9ff04af [ARM] Add neon vector support for round
As per #142559, this marks fround as legal for Neon and upgrades the existing
arm.neon.vrinta intrinsics.
2025-06-30 17:15:26 +01:00
Simon Wallis
a1d83311c8
[AArch64] Change IssueWidth to 5 in AArch64SchedNeoverseN2.td (#145717)
It has been observed that the issue width for neoverse-n2 CPUs is set
too high, and does not properly reflect the dispatch constraints.

I tested various values of IssueWidth (10, 8, 6, 5, 4) with runs of
various workloads on a neoverse-n2 machine and I got the highest overall
geomean score with an issue width of 5.

If this patch were to cause any major regression post-commit, it could
be easily reverted, but it is likely to show an overall improvement.

Related Neoverse-V2 PR: https://github.com/llvm/llvm-project/pull/142565
2025-06-30 17:12:02 +01:00
Philip Reames
199c6ecb5c [RISCV] Add coverage for missed scalarization of gather/scatter base pointers 2025-06-30 08:42:52 -07:00
Simon Pilgrim
c00c5a3898 [X86] Add test coverage to show failure to push freeze through CTLZ/CTTZ nodes (+ZERO_UNDEF variants)
Helps with nvtpx regression #145939
2025-06-30 15:48:40 +01:00
Ramkumar Ramachandra
652630b3c9
[ISel/RISCV] Fix fixed-vector [l]lrint lowering (#145898)
Make the fixed-vector lowering of ISD::[L]LRINT use the custom-lowering
routine, lowerVectorXRINT, and fix issues in lowerVectorXRINT related to
this new functionality.
2025-06-30 13:44:34 +01:00
Simon Pilgrim
b9e4679976
[DAG] canCreateUndefOrPoison - add handling for ADD/SUB/MUL overflow nodes (#146322)
Neither the arithmetic value or overflow result can create undef/poison from regular operands values.

We have complete test coverage for all ADDO/SUBO nodes, 32-bit codegen handles the _CARRY variants but until #145939 lands AND DAGCombiner::visitFREEZE handles multiple results we can't see any codegen change.

Pulled out of #145939
2025-06-30 13:26:57 +01:00
Shilei Tian
a99c964d7f
[AMDGPU] Add support for v_cvt_f16_fp8 on gfx1250 (#146302)
Co-authored-by: Mekhanoshin, Stanislav <Stanislav.Mekhanoshin@amd.com>
2025-06-30 07:51:00 -04:00
Guy David
f4128428af
[PHIElimination] Fix bug around $noreg assignment (#146320)
PR which introduced the bug:
https://github.com/llvm/llvm-project/pull/131837.
Fixes a crash around dead registers which started in f5c62ee0fa04 by
verifying that the reused incoming register is also virtual.
2025-06-30 12:59:12 +03:00
Simon Pilgrim
f226852265 [X86] Add test coverage to show failure to push freeze through ssubo/usubo nodes (+carry variants)
Test coverage to pull out the overflow handling from #145939
2025-06-30 10:35:15 +01:00
Simon Pilgrim
1dfc3e8461 [X86] Add test coverage to show failure to push freeze through saddo/uaddo nodes (+carry variants)
Test coverage to pull out the overflow handling from #145939
2025-06-30 10:17:47 +01:00
Ricardo Jesus
b563e76306
[AArch64] Improve scalar and Neon popcount with SVE CNT. (#143870)
When available, we can use SVE's CNT instruction to improve the lowering
of scalar and fixed-length popcount (CTPOP) since the SVE instruction
supports types that the Neon variant doesn't.

For the scalar types, I see the following speedups on NVIDIA Grace CPU:
| size (bits) | before (Gibit/s) | after (Gibit/s) | speedup |
|------------:|-----------------:|----------------:|--------:|
|         32  |           75.20  |          86.79  |   1.15  |
|         64  |          149.87  |         173.70  |   1.16  |
|        128  |          158.56  |         164.88  |   1.04  |
2025-06-30 09:04:45 +01:00