82601 Commits

Author SHA1 Message Date
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
Evgenii Kudriashov
99816a5af4
[Xtensa] Add XtensaDesc dependency to LLVMXtensaDisassembler (#126904)
There is an undefined reference to checkRegister in shared lib builds

Suspecting #124656
2025-02-12 23:48:01 +07:00
Kazu Hirata
c15806aa5a
[SPIRV] Avoid repeated hash lookups (NFC) (#126854) 2025-02-12 08:47:26 -08: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
Rahul Joshi
bee9664970
[TableGen] Emit OpName as an enum class instead of a namespace (#125313)
- Change InstrInfoEmitter to emit OpName as an enum class
  instead of an anonymous enum in the OpName namespace.
- This will help clearly distinguish between values that are 
  OpNames vs just operand indices and should help avoid
  bugs due to confusion between the two.
- Rename OpName::OPERAND_LAST to NUM_OPERAND_NAMES.
- Emit declaration of getOperandIdx() along with the OpName
  enum so it doesn't have to be repeated in various headers.
- Also updated AMDGPU, RISCV, and WebAssembly backends
  to conform to the new definition of OpName (mostly
  mechanical changes).
2025-02-12 08:19:30 -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
Kazu Hirata
73509781b5
[X86] Avoid repeated hash lookups (NFC) (#126857) 2025-02-12 23:38:01 +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
Jason Eckhardt
96ce8cadf9
[NFC][Lanai][Hexagon] Define DEBUG_TYPE after including Debug.h. (#125440)
This patch fixes some warnings/errors that occur with certain
compilers-- due to existing code not following the idiom mentioned in
`Debug.h`:

```
// LLVM_DEBUG() requires the DEBUG_TYPE macro to be defined. Set it to "foo"
// specify that your debug code belongs to class "foo". **Be careful that you only
// do this after including Debug.h and not around any #include of headers.**
```
2025-02-12 08:32:59 -06: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
Simon Pilgrim
085bdb1e4c
[X86] canonicalizeShuffleWithOp - don't bother trying to move shuffles across binops to fold the load. (#126894)
Its not currently used, but is likely to just introduce additional shuffles, resulting in higher Port5 pressure etc. in future patches.
2025-02-12 12:13:11 +00:00
Mikhail Goncharov
5fe37ff75a Revert "[NVPTX] Cleanup/Refactoring in NVPTX AsmPrinter and RegisterInfo (NFC) (#126800)"
This reverts commit 215fa9e175c6ef9e2fa92f77fbd4015cd4c99a67.

getNameOrAsOperand is only defined under DEBUG
2025-02-12 11:13:16 +01: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
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
Alex MacLean
215fa9e175
[NVPTX] Cleanup/Refactoring in NVPTX AsmPrinter and RegisterInfo (NFC) (#126800) 2025-02-12 00:23:36 -08:00
Matt Arsenault
de968c8e1c
AMDGPU: Use range to implement getSubRegs (#126861)
Fixes #126781
2025-02-12 14:05:42 +07:00
Haohai Wen
ec28e9b757
[MC] Replace MCContext::GenericSectionID with MCSection::NonUniqueID (#126202)
They have same semantics. NonUniqueID is more friendly for isUnique
implementation in MCSectionELF.

History: 97837b7 added support for unique IDs in sections and added
GenericSectionID. Later, 1dc16c7 added NonUniqueID.
2025-02-12 14:28:37 +08:00
Vikram Hegde
9c725ef368
[AMDGPU][NewPM] Port "GCNRewritePartialRegUses" pass to NPM (#126024) 2025-02-12 11:21:40 +05:30
Kazu Hirata
84e3c6ff95 [RISCV] Fix a warning
THis patch fixes:

  llvm/lib/Target/RISCV/RISCVVMV0Elimination.cpp:91:29: error: unused
  variable 'TRI' [-Werror,-Wunused-variable]
2025-02-11 20:37:48 -08:00
Luke Lau
cc7e83601d
[RISCV] Select mask operands as virtual registers and eliminate uses of vmv0 (#125026)
This is another attempt at #88496 to keep mask operands in SSA after
instruction selection.

Previously we selected the mask operands into vmv0, a singleton register
class with exactly one register, V0.

But the register allocator doesn't really support singleton register
classes and we ran into errors like "ran out of registers during
register allocation in function".

This avoids this by introducing a pass just before register allocation
that converts any use of vmv0 to a copy to $v0, i.e. what isel currently
does today.

That way the register allocator doesn't need to deal with the singleton
register class, but we get the benefits of having the mask registers in
SSA throughout the backend:

- This allows RISCVVLOptimizer to reduce the VLs of instructions that
define mask registers
- It enables CSE and code sinking in more places
- It removes the need to peek through mask copies in RISCVISelDAGToDAG
and keep track of V0 defs in RISCVVectorPeephole

This patch initially eliminates uses of vmv0s after RISCVVectorPeephole
to keep the diff to a minimum, and a follow up patch will move it past
the other MachineInstr SSA passes.

Note that it doesn't try to remove any defs of vmv0 as we shouldn't have
any instructions that have any vmv0 outputs.

As a further follow up, we can move the elimination pass to after phi
elimination and outside of SSA, which would unblock the pre-RA scheduler
around masked pseudos. This might also help the issue that
RISCVVectorMaskDAGMutation tries to solve.
2025-02-12 12:06:55 +08:00
Krzysztof Drewniak
934c97dd16
[LowerBufferFatPointers] Fix support for GEP T, p7, <N x T> idxs (#126126)
The lowering for GEP didn't properly support the case where the pointer
argument was being implicitly broadcast by a vector of indices. Fix
that.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-02-11 18:22:50 -06:00
Philip Reames
a6a5507e36 Revert "[RISCV] Allow undef prefix for local repeating VLA shuffle lowering (#126097)"
This reverts commit ab0006ddba3e977c44e1e761909e09603816b32c.  It appears to have rebased badly during web merge.
2025-02-11 15:46:12 -08:00
Justin Fargnoli
022c9c9d3a
[NVPTX] Lower invalid ISD::ADDRSPACECAST (#125607)
Avoid [crashing](https://godbolt.org/z/8T58vcM68) when lowering
`addrspacecast ptr addrspace(<non-zero>) %ptr to ptr
addrspace(<non-zero>)`.
2025-02-11 15:36:07 -08:00
Philip Reames
ab0006ddba
[RISCV] Allow undef prefix for local repeating VLA shuffle lowering (#126097)
Implement the first TODO from #125735, and minorly cleanup code using
same style as the recently landed strict prefix case.
2025-02-11 15:30:36 -08:00
Daniel Hoekwater
3a22cf9bd8
[CFIFixup] Fixup CFI for split functions with synchronous uwtables (#125299)
- **Precommit tests for synchronous uwtable CFI fixup**
- **[CFIFixup] Fixup CFI for split functions with synchronous uwtables**

Commit
6e54fccede
disables CFI fixup for
functions with synchronous tables, breaking CFI for split functions.
Instead, we can disable *block-level* CFI fixup for functions with
synchronous tables.

Unwind tables can be:
- N/A (not present)
- Asynchronous
- Synchronous

Functions without unwind tables don't need CFI fixup (since they don't
care about CFI).

Functions with asynchronous unwind tables must be accurate for each
basic block, so full CFI fixup is necessary.

Functions with synchronous unwind tables only need to be accurate for
each function (specifically, the portion of a function in a given
section). Disabling CFI fixup entirely for functions with synchronous
uwtables may break CFI for a function split between two sections. The
portion in the first section may have valid CFI, while the portion in
the second section is missing a call frame.

Ex:
```
(.text.hot)
Foo (BB1):
  <Call frame information>
  ...
BB2:
  ...

(.text.split)
BB3:
  ...
BB4:
  <epilogue>
```

Even if `Foo` has a synchronous unwind table, we still need to insert
call frame information into `BB3` so that unwinding the call stack from
`BB3` or `BB4` works properly.
2025-02-11 18:25:08 -05:00
Philip Reames
8374d42186
[RISCV] Decompose single source shuffles (without exact VLEN) (#126108)
This is a continuation of the work started in #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 neccessary one.
2025-02-11 14:40:36 -08:00
Brox Chen
ad6cd7e8b2
[AMDGPU][True16][CodeGen] true16 codegen for MadFmaMixPat (#124892)
true16 codegen for MadFmaMixPat. GISEL test not enabled and will be
added later when GISEL is supported
2025-02-11 17:36:44 -05:00
Philip Reames
e4016bf5c3 [DAG] Use ArrayRef to simplify ShuffleVectorSDNode::isSplatMask 2025-02-11 12:47:10 -08:00
quic-areg
1bf1f13be9
[Hexagon][Disassembler] Set CommentStream of Disassembler (#126766)
Sets CommentStream after assert added in #125962.
2025-02-11 13:20:38 -06:00
Vigneshwar Jayakumar
1188b1ff7b
AMDGPU: Handle gfx950 XDL Write-VGPR-VALU-WAW wait state change (#126132)
There are additional wait states for XDL write VALU WAW hazard in gfx950
compared to gfx940.
2025-02-12 01:32:23 +07:00
Vigneshwar Jayakumar
a2263eba4d
AMDGPU: Handle gfx950 XDL-write-VGPR-VALU-Mem-Exp wait state change (#126727) 2025-02-12 01:30:53 +07:00
Kazu Hirata
c9686d6904
[SystemZ] Avoid repeated hash lookups (NFC) (#126679) 2025-02-11 09:09:04 -08:00
Stanislav Mekhanoshin
7639242155
[AMDGPU] Create new directive .amdhsa_inst_pref_size (#126622)
The field INST_PREF_SIZE is available since gfx11.
2025-02-11 08:35:45 -08:00
Ivan Kosarev
b7188f6313
[AMDGPU][NFC] Remove an unneeded return value. (#126739)
And rename the function to disassociate it from the one where generating
loading of the input value may actually fail.
2025-02-11 16:10:49 +00:00
Vigneshwar Jayakumar
c837f57286
AMDGPU: Handle gfx950 XDL-write-VGPR-Overlap-Src-AB wait state (#126732)
gfx950 needs more additional waitstates from gfx940
2025-02-11 22:30:16 +07:00
David Sherwood
efc72347fd
[AArch64] Improve getPartialReductionCost for fixed-width VFs (#126538)
NEON does not have a version of udot/sdot that accumulates into
64-bit integer values, so we should return Invalid from
getPartialReductionCost for 64-bit types and fixed-width VFs.
In theory, if the 64-bit versions of SVE udot/sdot are available 
we could use those, but we don't currently have lowering support
for that.
2025-02-11 15:10:39 +00:00
Marcos Maronas
a09beae271
[SPIRV] Add support for cl_khr_extended_bit_ops (#120571)
This PR adds support for `cl_khr_extended_bit_ops` in SPIRV Backend.
Note that `cl_khr_extended_bit_ops` only supports types in
```
char, charn, uchar, ucharn, short, shortn, ushort, ushortn, int, intn, uint, uintn, long, longn, ulong, and ulongn
```
where `n is 2, 3, 4, 8, or 16`.

Subsequent PRs will introduce support for non-standard bit width
required by `SPV_KHR_bit_instructions`.
2025-02-11 12:46:38 +01:00
Benjamin Maxwell
701223ac20
[IR] Add llvm.sincospi intrinsic (#125873)
This adds the `llvm.sincospi` intrinsic, legalization, and lowering
(mostly reusing the lowering for sincos and frexp).

The `llvm.sincospi` intrinsic takes a floating-point value and returns
both the sine and cosine of the value multiplied by pi. It computes the
result more accurately than the naive approach of doing the
multiplication ahead of time, especially for large input values.

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

Currently, the default lowering of this intrinsic relies on the
`sincospi[f|l]` functions being available in the target's runtime (e.g.
libc).
2025-02-11 09:01:30 +00:00
Abhilash Majumder
6a961dc03d
[NVPTX] Add intrinsics for prefetch.* (#125887)
\[NVPTX\] Add Prefetch intrinsics

This PR adds prefetch intrinsics with the relevant eviction priorities.
* Lit tests are added as part of prefetch.ll
* The generated PTX is verified with a 12.3 ptxas executable.
* Added docs for these intrinsics in NVPTXUsage.rst.

For more information, refer PTX ISA
`<https://docs.nvidia.com/cuda/parallel-thread-execution/#data-movement-and-conversion-instructions-prefetch-prefetchu>`_.

---------

Co-authored-by: abmajumder <abmajumder@nvidia.com>
2025-02-11 14:24:46 +05:30
YunQiang Su
0d8d354b0c Revert "[Mips] Support llvm.readcyclecounter intrinsic (#114953)"
This reverts commit 9cc7ee16e3bb849fb3c0155a843bfe349a2d2175.
2025-02-11 14:37:17 +08:00
Sudharsan Veeravalli
27c034a9c6
[Hexagon] Fix typos discovered by codespell (NFC) (#126233)
Found using https://github.com/codespell-project/codespell

```
codespell Hexagon --write-changes \
     --ignore-words-list=CarryIn,CreateOr,ORE,COPYs,ArchVer,predicable,UE,MIs,isNT,Vor,CountR,DUM,GEs,AddD,ToI, \
     CopyIn,TheI,TotalIn,vor,MOne,contigious,Contigious 
```
2025-02-11 11:31:31 +05:30
Vikram Hegde
3293bff5d2
[AMDGPU][NewPM] Port "GCNPreRAOptimizations" pass to NPM (#126040) 2025-02-11 11:09:38 +05:30
Phoebe Wang
0c955167c2
[X86] Generate cvtpd2dq for (v2i32 lrint(v2f64)) (#126508)
Found when addressing comment on #126477
2025-02-11 13:14:41 +08:00
Sam Elliott
ea6827cacf
[RISCV] Improve Errors for GPRNoX0 Reg Class (#126397)
More adoption of better diagnostics for RISC-V register classes:
- GPRNoX0 (GPRs excluding `zero`)
2025-02-10 17:21:51 -08:00
yingopq
9cc7ee16e3
[Mips] Support llvm.readcyclecounter intrinsic (#114953)
The llvm.readcyclecounter intrinsic can be implemented via the `rdhwr
$3, $hwr_cc` instruction.
$hwr_cc: High-resolution cycle counter. This register provides read
access to the coprocessor 0 Count Register.

Fix #106318.
2025-02-11 08:47:50 +08:00