57396 Commits

Author SHA1 Message Date
Philip Reames
25e43334a8
[RISCV] Lower shuffle which splats a single span (without exact VLEN) (#127108)
If we have a shuffle which repeats the same pattern of elements, all of
which come from the first register in the source register group, we can
lower this to a single vrgather at m1 to perform the element
rearrangement, and reuse that for each register in the result vector
register group.
2025-02-14 17:09:27 -08:00
joaosaffran
77ddffc946
[HLSL] Fix Root signature test error (#127261)
Fixing error detected in build bot in file
`RootSignature-MultipleEntryFunctions.ll`

closes: [127260](https://github.com/llvm/llvm-project/issues/127260)

---------

Co-authored-by: joaosaffran <joao.saffran@microsoft.com>
2025-02-14 15:39:52 -08:00
Finn Plummer
5742dc44e2
[DirectX][ShaderFlags] Add analysis for WaveOps flag (#118140)
- Check each call instruction for a `WaveOp` intrinsic and set the
`WaveOps` flag if this is true for any intrinsic, Done in
DXILShaderFlags.cpp

Resolves #114565
2025-02-14 10:40:47 -08:00
Alexander Peskov
708dc651ba
[NVPTX] Fix vaarg store alignment (#127067)
There is an issue with different alignment applied to store and load of
vaargs in NVPTX backend.
Current `CodeGen/NVPTX/vaargs.ll` demonstrates this discrepancy. Store
occurs with offsets `0,4,12,20`, but load with `0,8,16,24`.

This patch attempts to unify the alignment approach for callee and
caller.
2025-02-14 12:13:37 -05:00
Simon Pilgrim
0b49001853 [X86] Add test coverage for #9297
(using bugzilla id for PR)
2025-02-14 11:38:47 +00:00
deadalnix
2ad1089d63
[X86] Match SETCC_CARRY in addition of SUB when trying to reconstruct LEA (#126551)
As per title.

This is not a huge deal at the moment, but becomes one when matching
node in topological order in the DAGCombiner, and is generally more
stable than the existing.
2025-02-14 17:38:25 +08:00
Csanád Hajdú
a190f15d2b
[AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) (#125687)
Add support for the new SHF_AARCH64_PURECODE ELF section flag:
https://github.com/ARM-software/abi-aa/pull/304

The general implementation follows the existing one for ARM targets.
Generating object files with the `SHF_AARCH64_PURECODE` flag set is
enabled by the `+execute-only` target feature.

Related PRs:
* Clang: https://github.com/llvm/llvm-project/pull/125688
* LLD: https://github.com/llvm/llvm-project/pull/125689
2025-02-14 08:56:07 +00:00
Nikita Popov
d8b2e432d6
[IR] Remove mul constant expression (#127046)
Remove support for the mul constant expression, which has previously
already been marked as undesirable. This removes the APIs to create mul
expressions and updates tests to stop using mul expressions.

Part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
2025-02-14 09:28:57 +01:00
Brox Chen
cf1165cb9c
Revert "[AMDGPU][True16][CodeGen] true16 codegen pattern for fma (#12… (#127175)
Reverting this patch since it raise buildbot failure

This reverts commit 2a7487cc2e0fb8bd91784e2d9636a65baa6d90ed.
2025-02-14 02:28:45 -05:00
Brox Chen
2a7487cc2e
[AMDGPU][True16][CodeGen] true16 codegen pattern for fma (#122950)
true16 codegen pattern for f16 fma.

created a duplicated shrink-mad-fma-gfx10.mir from shrink-mad-fma to
seperate pre-GFX11 and GFX11 mir test.
2025-02-14 02:16:00 -05:00
Srinivasa Ravi
bd860f9864
[NVPTX] Add intrinsics for redux.sync f32 instructions (#126664)
Adds NVVM intrinsics, NVPTX codegen and Clang builtins for `redux.sync`
f32 instructions introduced in ptx8.6 for sm_100a.
Tests added in `CodeGen/NVPTX/redux-sync.ll` and
`CodeGenCUDA/redux-builtins.cu` and verified through ptxas 12.8.0.

PTX Spec Reference:

https://docs.nvidia.com/cuda/parallel-thread-execution/#parallel-synchronization-and-communication-instructions-redux-sync
2025-02-14 11:11:44 +05:30
Ulrich Weigand
adacbf68eb [SystemZ] Add codegen support for llvm.roundeven
This is straightforward as we already had all the necessary
instructions, they simply were not wired up.

Also allows implementing the vec_round intrinsic via the
standard llvm.roundeven IR instead of a platform intrinsic now.
2025-02-14 00:10:37 +01:00
joaosaffran
1ff5f328d9
[DXIL] Add support for root signature flag element in DXContainer (#123147)
Adding support for Root Signature Flags Element extraction and writing
to DXContainer.
- Adding an analysis to deal with RootSignature metadata definition
- Adding validation for Flag
- writing RootSignature blob into DXIL

Closes: [126632](https://github.com/llvm/llvm-project/issues/126632)

---------

Co-authored-by: joaosaffran <joao.saffran@microsoft.com>
2025-02-13 14:16:01 -08:00
Scott Linder
0aafb8aca3
[AMDGPU] Add test for failure with function !dbg info in amdgpu-lower-kernel-arguments (#126146) 2025-02-13 15:58:45 -05:00
LU-JOHN
5decab178f
AMDGPU: Reduce shl64 to shl32 if shift range is [63-32] (#125574)
Reduce:

   DST = shl i64 X, Y

where Y is in the range [63-32] to:

   DST = [0, shl i32 X, (Y & 32)]


Alive2 analysis:

https://alive2.llvm.org/ce/z/w_u5je

---------

Signed-off-by: John Lu <John.Lu@amd.com>
2025-02-13 13:40:25 -06:00
Philip Reames
059722da5e Revert "[RISCV] Default to MicroOpBufferSize = 1 for scheduling purposes (#126608)" and follow up commit.
This reverts commit 9cc8442a2b438962883bbbfd8ff62ad4b1a2b95d.
This reverts commit 859c871184bdfdebb47b5c7ec5e59348e0534e0b.

A performance regression was reported on the original review.  There appears
to have been an unexpected interaction here.  Reverting during investigation.
2025-02-13 09:57:33 -08:00
Abhilash Majumder
55f3df875d
[NVPTX] Fix and refine prefetch.* intrinsics (#126899)
This is follow-up PR from #125887  which fixes the intrinsic failures .

---------

Co-authored-by: abmajumder <abmajumder@nvidia.com>
2025-02-13 17:54:01 +01:00
Vyacheslav Levytskyy
2f8de7b466
[SPIR-V] Type inference must realize that a <1 x Type> vector type is not a legal vector type in LLT (#124560)
In this PR we account for possible <1 x LLVM Type> input to ensure that
we produce legal vector types during type inference.

We modify an LLVM type to conform with future transformations in
IRTranslator, if it's a <1 x Type> vector type, replacing it by the
element type, because <1 x Type> vector type is not a legal vector type
in LLT and IRTranslator will represent it as the scalar eventually.
2025-02-13 17:46:42 +01:00
Robert Imschweiler
41e49fadd4
[AMDGPU] Fix llvm.amdgcn.workitem.id-unsupported-calling-convention.ll (#127041)
Follow-up fix for #126058. (@arsenm)
2025-02-13 22:23:47 +07:00
Robert Imschweiler
0da8d0f9b7
[AMDGPU] Change handling of unsupported non-compute shaders with HSA (#126798)
Previous handling in `SITargetLowering::LowerFormalArguments` only
reported a diagnostic message and continued execution by returning a
non-usable `SDValue`. This results in llvm crashing later with an
unrelated error. This commit changes the detection of an unsupported
non-compute shader to be a fatal error right away.

As an example situation, take the usage of an `amdgpu_ps` function and
the `amdgcn-unknown-amdhsa` target triple.
```
define amdgpu_ps void @foo(ptr %p, i32 %i) {
        store i32 %i, ptr %p
        ret void
}
```
Compiling this code (with `llc -mtriple=amdgcn-unknown-amdhsa
-mcpu=gfx942`, for example) fails with:
```
error: <unknown>:0:0: in function foo void (ptr, i32): unsupported non-compute shaders with HSA

llc:
[...]/git/trunk21.0/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:11790:
void llvm::SelectionDAGISel::LowerArguments(const llvm::Function&):
Assertion `InVals.size() == Ins.size() && "LowerFormalArguments didn't emit the correct number of values!"' failed.
[...]
```
2025-02-13 22:23:08 +07:00
Fabian Ritter
a33a84ee63
[AMDGPU][NFC] Replace gfx940 and gfx941 with gfx942 in llvm/test (#125711)
[AMDGPU][NFC] Replace gfx940 and gfx941 with gfx942 in llvm/test

gfx940 and gfx941 are no longer supported. This is one of a series of PRs to remove them from the code base.

This PR uses gfx942 instead of gfx940 and gfx941 in the test RUN-lines (unless there is already a RUN-line for gfx942).

The only notable difference in the test output is that gfx942 does not force the use of sc0 and sc1 on stores while gfx940 and gfx941 do (cf. https://reviews.llvm.org/D149986).

For SWDEV-512631
2025-02-13 15:17:12 +01:00
zhijian lin
7763119c6e
[PowerPC] Deprecate uses of ISD::ADDC/ISD::ADDE/ISD::SUBC/ISD::SUBE (#116984)
ISD::ADDC, ISD::ADDE, ISD::SUBC and ISD::SUBE are being deprecated,
using ISD::UADDO_CARRY,ISD::USUBO_CARRY instead. Lowering the UADDO,
UADDO_CARRY, USUBO, USUBO_CARRY in the patch.
2025-02-13 09:09:17 -05:00
Qi Zhao
e8dba3a4ff [LoongArch] Add test for stackmaps. NFC 2025-02-13 20:58:26 +08:00
Simon Pilgrim
e657b96cd8 [X86] Fold EXTRACT_SUBVECTOR(VPERMV(V,M),C) -> EXTRACT_SUBVECTOR(VPERMV(V,M'),0)
Similar to what we already do for VPERMV3, we can fold the non-zero-idx EXTRACT_SUBVECTOR into the shuffle mask and use a free EXTRACT_SUBVECTOR(V,0) instead
2025-02-13 12:35:05 +00:00
Matt Arsenault
eef0205345
AMDGPU: Add baseline test for treating v_pk_mov_b32 like reg_sequence (#125656) 2025-02-13 18:12:09 +07:00
Jay Foad
0b0f3da6a8
[AMDGPU] Add a regression test for -mattr=dumpcode (#116982) 2025-02-13 11:04:08 +00:00
Matt Arsenault
6c5a0086d1 AMDGPU: Add more tests for peephole opt subregister composing 2025-02-13 17:01:34 +07:00
Oliver Stannard
308ce8d524
[ARM] Fix calling convention for __fp16 with big-endian (#126741)
AAPCS32 defines the fp16 and bf16 types as being passed as if they were
extended to 32 bits, with the high 16 bits being unspecified. The
extension is specified as happening as-if it was done in a register,
which means that for big endian targets, the actual value gets passed in
the higher addressed half of the stack slot, instead of the lower
addressed half as for little endian. Previously, for targets with the
fp16 extension, we were passing these types as a 16 bit stack slot,
which worked for little endian because every later stack slot would be
4-byte aligned leaving the 2 byte gap, but was incorrect for big endian.
2025-02-13 09:09:29 +00:00
Robert Imschweiler
bcba3117c0
[AMDGPU] SelDAG: fix lowering of undefined workitem intrinsics (#126058)
GlobalISel already handles undefined workitem.id.{x,y,z} intrinsics,
SelDAG failed in AMDGPUISelLowering.cpp due to a failed assertion in
`AMDGPUTargetLowering::loadInputValue`: `Arg && "Attempting to load
missing argument"`. This commit changes the behavior of SelDAG to
instead use a zero constant.

This LLVM defect was identified via the AMD Fuzzing project.
2025-02-12 18:41:41 -05:00
Jeffrey Byrnes
c5a4512d85
[AMDGPU] iglp.opt does not clobber memory operands (#126976)
I think it was an accident that this wasn't included.
2025-02-12 14:11:02 -08:00
S. Bharadwaj Yadavalli
f2650c54c9
[DirectX] Set Shader Flag DisableOptimizations (#126813)
- Set the shader flag `DisableOptimizations` based on `optnone`
attribute of shader entry functions.

- Add DXIL Metadata Analysis pass as pre-requisite for Shader Flags pass
to obtain entry function information collected therein.

- Named module metadata `dx.disable_optimizations` is intended to
indicate disabling optimizations (`-O0`) via commandline flag. However,
its intent is fulfilled by `optnone` attribute of shader entry functions as 
implemented in a recent change, and thus not needed. Delete
generation of named metadata and corresponding test file
`disable_opt.ll`.

- Add tests to verify correctness of setting shader flag.

Closes #112263
2025-02-12 16:45:01 -05:00
Philip Reames
859c871184
[RISCV] Default to MicroOpBufferSize = 1 for scheduling purposes (#126608)
This change introduces a default schedule model for the RISCV target
which leaves everything unchanged except the MicroOpBufferSize. The
default value of this flag in NoSched is 0. Both configurations
represent in order cores (i.e. no reorder window), the difference
between them comes down to whether heuristics other than latency are
allowed to apply. (Implementation details below)

I left the processor models which explicitly set MicroOpBufferSize=0
unchanged in this patch, but strongly suspect we should change those
too. Honestly, I think the LLVM wide default for this flag should be
changed, but don't have the energy to manage the updates for all
targets.

Implementation wise, the effect of this change is that schedule units
which are ready to run *except that* one of their predecessors may not
have completed yet are added to the Available list, not the Pending one.
The result of this is that it becomes possible to chose to schedule a
node before it's ready cycle if the heuristics prefer. This is
essentially chosing to insert a resource stall instead of e.g.
increasing register pressure.

Note that I was initially concerned there might be a correctness aspect
(as in some kind of exposed pipeline design), but the generic scheduler
doesn't seem to know how to insert noop instructions. Without that, a
program wouldn't be guaranteed to schedule on an exposed pipeline
depending on the program and schedule model in question.

The effect of this is that we sometimes prefer register pressure in
codegen results. This is mostly churn (or small wins) on scalar because
we have many more registers, but is of major importance on vector -
particularly high LMUL - because we effectively have many fewer
registers and the relative cost of spilling is much higher. This is a
significant improvement on high LMUL code quality for default rva23u
configurations - or any non -mcpu vector configuration for that matter.

Fixes #107532
2025-02-12 12:31:39 -08:00
Philip Reames
9478822f4f
[RISCV] Decompose single source shuffles (without exact VLEN) (#126951)
(This is a re-apply for what was 8374d42. The bug there was fairly 
major - despite the comments and review description, the code was 
using each register in the source register group, not only the first 
register. This was completely wrong.)

This is a continuation of the work started in
https://github.com/llvm/llvm-project/pull/125735 to lower selected VLA
shuffles in linear m1 components instead of generating O(LMUL^2) or
O(LMUL*Log2(LMUL) high LMUL shuffles.

This pattern focuses on shuffles where all the elements being used
across the entire destination register group come from a single register
in the source register group. Such cases come up fairly frequently via
e.g. spread(N), and repeat(N) idioms.

One subtlety to this patch is the handling of the index vector for
vrgatherei16.vv. Because the index and source registers can have
different EEW, the index vector for the Nth chunk of the destination is
not guaranteed to be register aligned. In fact, it is common for e.g. an
EEW=64 shuffle to have EEW=16 indices which are four chunks per source
register. Given this, we have to pay a cost for extracting these chunks
into the low position before performing each shuffle.

I'd initially expressed this as a naive extract sub-vector for each data
parallel piece. However, at high LMUL, this quickly caused register
pressure problems since we could at worst need 4x the temporary
registers for the index. Instead, this patch uses a repeating slidedown
chained from previous iterations. This increases critical path by at
worst 3 slides (SEW=64 is the worst case), but reduces register pressure
to at worst 2x - and only if the original index vector is reused
elsewhere. I view this as arguably a bit of a workaround (since our
scheduling should have done better with the plain extract variant), but
a probably necessary one.
2025-02-12 12:10:35 -08:00
Simon Pilgrim
f719d8ac1c [X86] vec-strict-cmp-128-fp16.ll - regenerate VMOVSH comments 2025-02-12 18:48:55 +00:00
Simon Pilgrim
689f79d0f8 [X86] vec-strict-cmp-512-skx.ll - regenerate checks
Appears to have been manually edited at some point
2025-02-12 18:48:55 +00:00
Simon Pilgrim
a6a4252a15 [X86] vec-strict-fptoint - regenerate VPTERNLOG comments 2025-02-12 18:48:54 +00:00
Simon Pilgrim
b04a980b55 [X86] 2011-10-27-tstore.ll - regenerate checks 2025-02-12 17:19:19 +00:00
Philip Reames
c77d202759 Revert "[RISCV] Decompose single source shuffles (without exact VLEN) (#126108)"
This reverts commit 8374d421861cd3d47e21ae7889ba0b4c498e8d85.  A miscompile
was reported against the review thread, reverting while we investigate.
2025-02-12 08:33:20 -08:00
Philip Reames
ff8f6abe20 Reapply "[RISCV] Allow undef prefix for local repeating VLA shuffle lowering (#126097)"
(With a fix to recently added code.)

Implement the first TODO from #125735, and minorly cleanup code using
same style as the recently landed strict prefix case.
2025-02-12 07:40:13 -08:00
Alex MacLean
a282b6c486
[NVPTX] Convert scalar function nvvm.annotations to attributes (#125908)
Replace some more nvvm.annotations with function attributes,
auto-upgrading the annotations as needed. These new attributes will be
more idiomatic and compile-time efficient than the annotations.

- !"maxclusterrank" / !"cluster_max_blocks" -> "nvvm.maxclusterrank"
- !"minctasm" -> "nvvm.minctasm"
- !"maxnreg" -> "nvvm.maxnreg"
2025-02-12 07:33:22 -08:00
Simon Pilgrim
fbf46dfe35 [X86] fp-fold.ll - regenerate checks 2025-02-12 15:32:08 +00:00
Akshat Oke
7b60e03d73
Reland "CodeGen][NewPM] Port MachineScheduler to NPM. (#125703)" (#126684)
`RegisterClassInfo` was supposed to be kept alive between pass runs,
which wasn't being done leading to recomputations increasing the compile
time.

Now the Impl class is a member of the legacy and new passes so that it
is not reconstructed on every pass run.

---------

Co-authored-by: Christudasan Devadasan <christudasan.devadasan@amd.com>
2025-02-12 18:54:39 +05:30
Simon Pilgrim
7647f478c3
[X86] isShuffleFoldableLoad - only check that the SDValue has one use (#126900)
We don't need the entire load node to have oneuse, just the loaded value - prevents load chains from interfering with shuffle commutation
2025-02-12 13:13:49 +00:00
Jonathan Thackray
036f543952
[AArch64] Pre-commit tests for #125686 (NFC) (#126643)
Update the `generate-tests.py` script to create new tests for `atomicrmw
{fadd,fmin,fmax}` and test these with `half`, `float`, `bfloat` and
`double`.

Generate fp auto-tests to check both with and without `+lsfe`, so that when
#125686 is merged, `+lsfe` will use a single atomic floating-point
instruction.
2025-02-12 11:48:11 +00:00
David Green
bf7af2d12e
[AArch64][DAG] Allow fptos/ui.sat to scalarized. (#126799)
We we previously running into problems with fp128 types and certain
integer sizes.

Fixes an issue reported on #124984
2025-02-12 11:04:08 +00:00
Simon Pilgrim
f73ed3d434
[X86] lowerShuffleAsBroadcast - use isShuffleEquivalent to search for a hidden broadcast pattern (#126517)
lowerShuffleAsBroadcast only matches a known-splat shuffle mask, but we
can use the isShuffleEquivalent/IsElementEquivalent helpers to attempt
to find a hidden broadcast-able shuffle pattern.

This requires an extension to IsElementEquivalent to peek through
bitcasts to match against wider shuffles - these typically appear during
shuffle lowering where we've widened a preceding shuffle, often to a
vector concatenation etc.

Amazingly I hit this while yak shaving #126033 .......
2025-02-12 10:12:20 +00:00
Yeaseen
c174cc4840
[llvm] Remove br i1 undef in some llvm/test/CodeGen tests (#126811)
This PR replaces some instances of `br i1 undef` with function argument
value in several tests under `llvm/test/CodeGen/` directory.
2025-02-12 09:19:00 +00:00
Simon Pilgrim
8359dbc8c0
[X86] combineEXTRACT_SUBVECTOR - fold extract_subvector(subv_broadcast_load(ptr),0) -> load(ptr) (#126523)
This is typically handled by SimplifyDemandedVectorElts, but this will
fail when there are multiple uses of the subv_broadcast_load node, but
if there's just one use of the load result (and the rest are uses of the
memory chain), we can still replace with a load and update the chain
accordingly.

Noticed on #126517
2025-02-12 09:07:06 +00:00
Vikram Hegde
9c725ef368
[AMDGPU][NewPM] Port "GCNRewritePartialRegUses" pass to NPM (#126024) 2025-02-12 11:21:40 +05:30
Jim Lin
31bfae35d2
[DAGCombiner] Add hasOneUse checks for folding (not (add X, -1)) to (neg X) (#126667)
To get more better codegen for AArch with bic, x86 with andn and riscv
with andn.
2025-02-12 12:24:29 +08:00