7616 Commits

Author SHA1 Message Date
Changpeng Fang
4202634886
[AMDGPU] Remove -wavefrontsizeX from GlobalISel tests (NFC) (#100812)
This is to make https://github.com/llvm/llvm-project/pull/100711
complete
2024-07-28 11:26:29 +04:00
Matt Arsenault
761372ef15 AMDGPU/GlobalISel: Add some more select of pointer typed constant tests 2024-07-26 21:52:50 +04:00
Changpeng Fang
a82032918c
[AMDGPU] Remove -wavefrontsize32 and -wavefrontsize64 from GFX10+ tests (NFC) (#100711)
They are no longer needed after the patch: [AMDGPU] Remove wavefrontsize
feature from GFX10: https://github.com/llvm/llvm-project/pull/98400
The exception is when "target-features" are set to "+wavefrontsize32" or
"+wavefrontsize64", we still need to remove a wavefrontsize feature
before add a different one to make sure only one of them are present.
2024-07-26 00:42:24 -07:00
Fabian Ritter
92a06546ab
[LowerMemIntrinsics] Lower llvm.memmove to wide memory accesses (#100122)
So far, the IR-level lowering of llvm.memmove intrinsics generates loops
that copy each byte individually. This can be wasteful for targets that
provide wider memory access operations.

This patch makes the memmove lowering more similar to the lowering of
memcpy with unknown length.
TargetTransformInfo::getMemcpyLoopLoweringType() is queried for an
adequate type for the memory accesses, and if it is wider than a single
byte, the greatest multiple of the type's size that is less than or
equal to the length is copied with corresponding wide memory accesses. A
residual loop with byte-wise accesses (or a sequence of suitable memory
accesses in case the length is statically known) is introduced for the
remaining bytes.

For memmove, this construct is required in two variants: one for copying
forward and one for copying backwards, to handle overlapping memory
ranges. For the backwards case, the residual code still covers the bytes
at the end of the copied region and is therefore executed before the
wide main loop. This implementation choice is based on the assumption
that we are more likely to encounter memory ranges whose start aligns
with the access width than ones whose end does.

In microbenchmarks on gfx1030 (AMDGPU), this change yields speedups up
to 16x for memmoves with variable or large constant lengths.

Part of SWDEV-455845.
2024-07-26 08:43:30 +02:00
Thorsten Schütt
db8c84fc7a
[GlobalIsel] Push cast through select. (#100539) 2024-07-25 19:21:28 +02:00
Mirko Brkušanin
817cd72645
[AMDGPU] Fix folding clamp into pseudo scalar instructions (#100568)
Clamp is canonically a v_max* instruction with a VGPR dst. Folding clamp
into a pseudo scalar instruction can cause issues due to a change in
regbank. We fix this with a copy.
2024-07-25 18:19:26 +02:00
Ivan Kosarev
24a18aafa3
[AMDGPU] Simplify printing row/bank_mask modifiers. (#100575)
And fix a codegen test to use mask values that fit their encoding
fields.

Part of <https://github.com/llvm/llvm-project/issues/62629>.
2024-07-25 16:44:44 +01:00
Matt Arsenault
e24dc34aa0
AMDGPU: Fix asserting in DAG kernel argument lowering on v6i32 (#100528)
Remove this pointless assertion for the number of vector elements.
2024-07-25 14:03:28 +04:00
Jay Foad
74e964c7c1
[AMDGPU] Add GFX12 test coverage for export instructions (#100415) 2024-07-25 10:55:07 +01:00
Mariusz Sikora
fe8d1e61ac
[AMDGPU][NFC] Use GFX940 prefix in dpp64_combine test (#100459) 2024-07-25 07:52:38 +02:00
Sumanth Gundapaneni
0ee32c4573
[AMDGPU] Implement llvm.lrint intrinsic lowering (#98931)
This patch enabled the target-independent lowering of llvm.lrint via
GlobalISel.
For SelectionDAG, the instrinsic is custom lowered for AMDGPU.
2024-07-24 23:34:31 +04:00
Jay Foad
b9995a14f5
[MachineLoopInfo] Fix assertion failure on undef use operands (#100137)
Fixes #100115
2024-07-24 14:27:12 +01:00
Matt Davis
404071b059
[SelectionDAG] Preserve volatile undef stores. (#99918)
This patch preserves `undef` SDNodes that are `volatile` qualified.
Previously, these nodes would be discarded. The motivation behind this
change is to adhere to the
[LangRef](https://llvm.org/docs/LangRef.html#volatile-memory-accesses),
even though that doc is mostly in terms of LLVM-IR, it seems reasonable
to imply that the volatile constraints also imply to SDNodes.

> Certain memory accesses, such as
[load](https://llvm.org/docs/LangRef.html#i-load)’s,
[store](https://llvm.org/docs/LangRef.html#i-store)’s, and
[llvm.memcpy](https://llvm.org/docs/LangRef.html#int-memcpy)’s may be
marked volatile. The optimizers must not change the number of volatile
operations or change their order of execution relative to other volatile
operations. The optimizers may change the order of volatile operations
relative to non-volatile operations. This is not Java’s “volatile” and
has no cross-thread synchronization behavior.

Source: https://llvm.org/docs/LangRef.html#volatile-memory-accesses
2024-07-24 08:41:56 -04:00
Jessica Del
6a1b119035
[AMDGPU] Add intrinsics for atomic struct buffer loads (#100140)
Mark these intrinsics as atomic loads within LLVM to prevent hoisting
out of loops in cases where
the load is considered invariant.

Similar to https://github.com/llvm/llvm-project/pull/97707, but for
struct buffer loads.
2024-07-24 11:05:28 +02:00
Sumanth Gundapaneni
fc832d5349
[AMDGPU] Implement llvm.lround intrinsic lowering. (#98970)
This patch enables the target-independent lowering of llvm.lround via
GlobalISel. For SelectionDAG, the instrinsic is custom lowered for
AMDGPU. In order to support vector floating point input for llvm.lround,
this patch extends the target independent APIs and provide support for
scalarizing. pr98950 is needed to let verifier allow vector floating
point types
2024-07-23 20:34:34 +04:00
Christudasan Devadasan
229e118559
[AMDGPU] Codegen support for constrained multi-dword sloads (#96163)
For targets that support xnack replay feature (gfx8+), the
multi-dword scalar loads shouldn't clobber any register that
holds the src address. The constrained version of the scalar
loads have the early clobber flag attached to the dst operand
to restrict RA from re-allocating any of the src regs for its
dst operand.
2024-07-23 13:59:15 +05:30
Christudasan Devadasan
a1d7da05d0
[AMDGPU][SILoadStoreOptimizer] Merge constrained sloads (#96162)
Consider the constrained multi-dword loads while merging
individual loads to a single multi-dword load.
2024-07-23 13:50:42 +05:30
Carl Ritson
939a6624ac
[AMDGPU] Implement workaround for GFX11.5 export priority (#99273)
On GFX11.5 shaders having completed exports need to execute/wait at a
lower priority than shaders still executing exports.
Add code to maintain normal priority of 2 for shaders that export and
drop to priority 0 after exports.
2024-07-23 17:03:21 +09:00
Jessica Del
0eb719fef5
[AMDGPU] Fix build failure in raw.atomic.buffer.load tests (#99912)
This fixes the failing tests after rebasing
over the attributor move.
2024-07-22 14:28:20 -04:00
Jessica Del
ec7f8e1113
[AMDGPU] Add intrinsic for raw atomic buffer loads (#97707)
Upstream the intrinsics `llvm.amdgcn.raw.atomic.buffer.load`
and `llvm.amdgcn.raw.atomic.ptr.buffer.load`.

These additional intrinsics mark atomic buffer loads
as atomic to LLVM by removing the `IntrReadMem`
attribute. Otherwise, it could hoist these
intrinsics out of loops in cases where LLVM marks
them as invariant. That can cause issues such as
infinite loops.

Continuation of https://reviews.llvm.org/D138786
with the additional use in the fat buffer lowering,
more test cases and the additional ptr versions 
of these intrinsics.

---------

Co-authored-by: rtayl <>
Co-authored-by: Jay Foad <jay.foad@amd.com>
Co-authored-by: Mariusz Sikora <mariusz.sikora@amd.com>
2024-07-22 18:04:49 +02:00
Björn Pettersson
2b78303e3f
[DAGCombiner] Freeze maybe poison operands when folding select to logic (#84924)
Just like for regular IR we need to treat SELECT as conditionally
blocking poison in SelectionDAG. So (unless the condition itself is
poison) the result is only poison if the selected true/false value is
poison.
Thus, when doing DAG combines that turn SELECT into arithmetic/logical
operations (e.g. AND/OR) we need to make sure that the new operations
aren't more poisonous. One way to do that is to use FREEZE to make
sure the operands aren't posion.

This patch aims at fixing the kind of miscompiles reported in
  https://github.com/llvm/llvm-project/issues/84653
and
  https://github.com/llvm/llvm-project/issues/85190

Solution is to make sure that we insert FREEZE, if needed to make
the fold sound, when using the foldBoolSelectToLogic and
foldVSelectToSignBitSplatMask DAG combines.
2024-07-22 17:19:46 +02:00
Joseph Huber
f39bd0a24e
[AMDGPU] Do not print kernel-resource-usage information on non-kernels (#99720)
Summary:
This pass is used to get helpful information about the kernel resources
without needing to insepct the binary. However, it currently prints on
every function. These values will always be zero, so it's just spam on
the terminal, at best an indication that a function wasn't internalized
/ optimized out. This patch makes it only print for kernels to make it
more useful in practice.
2024-07-22 07:07:51 -05:00
Carl Ritson
62aa596ba1
[AMDGPU] Add no return image_sample intrinsics and instructions (#97542)
An appropriately configured image resource descriptor can trigger
image_sample instructions to store outputs directly to a linked memory
location instead of returning to VGPRs.

This is opaque to the backend as instruction encoding is unchanged;
however, a mechanism is require to allow frontends to communicate that
these instructions do not require destination VGPRs and store to memory.
Flagging these as stores means they will not be optimized away.
2024-07-20 17:26:58 +09:00
Jeffrey Byrnes
6e68b75e66 [AMDGPU] Reland: Do not use original PHIs in coercion chains
Change-Id: I579b5c69a85997f168ed35354b326524b6f84ef7
2024-07-19 09:02:28 -07:00
Changpeng Fang
25f4bd8872
AMDGPU: Clear kill flags after FoldZeroHighBits (#99582)
After folding, all uses of the result register are going to be replaced
by the operand register. The kill flags on the uses of the result and
operand registers are no longer valid after the replacement, and need to
be cleared.
The only exception is, however, if the kill flag is set for the operand
register, we are sure the last use of the result register is the new
last use of the operand register, and thus we are safe to keep the kill
flags.
2024-07-19 00:46:37 -07:00
Changpeng Fang
280d90d0fd
AMDGPU: Add back half and bfloat support for global_load_tr16 pats (#99540)
half and bfloat are common types for 16-bit elements. The support of
them was original there and dropped due to some reasons. This work adds
the support of the float types back.
2024-07-18 11:23:35 -07:00
Jay Foad
27ec379f63
[AMDGPU] Do not select llvm.amdgcn.inverse.ballot with wrong wave size (#99470)
This produces a "cannot select" error, instead of failing later with an
illegal vgpr to sgpr copy.
2024-07-18 13:53:22 +01:00
paperchalice
1b873e565e
[CodeGen][NewPM] Port phi-node-elimination to new pass manager (#98867)
- Add `PHIEliminationPass `.
- Support new pass manager in `MachineBasicBlock:: SplitCriticalEdge `
2024-07-17 11:26:56 +08:00
Carl Ritson
befd44bcdc
[AMDGPU] Update hasUnwantedEffectsWhenEXECEmpty (#97982)
Add barriers and s_wait_event to hasUnwantedEffectsWhenEXECEmpty.
Add a comment documenting the current expected use of the function.
2024-07-17 11:30:44 +09:00
Joseph Huber
6dc8c2dada
[AMDGPU] Fix resource analysis crash on alias-to-alias function (#99034)
Summary:
Previously this code only looked through a single level of aliases to
find the underlying function. This patch changes it to continue until it
finds the end. Aliases that form a cycle are illegal IR, so we shouldn't
need to worry about infinite loops.

Fixes https://github.com/llvm/llvm-project/issues/96812
2024-07-16 08:34:18 -05:00
Pierre van Houtryve
b3a446650c
[AMDGPU] Implement GFX12 Memory Model (#98591)
- Emit GLOBAL_WB instructions
- Reflect synscope on instructions's `scope:` operand

Fixes SWDEV-468508
Fixes SWDEV-470735
Fixes SWDEV-468392
Fixes SWDEV-469622
2024-07-16 10:53:06 +02:00
David Stuttard
5d12fa7d72
[AMDGPU] Fix indirect dst bug for non-sgpr index (#98907)
When emitting indirect dst, if the idx is not SGPR there was a bug that
didn't
take into account that the subregister might be different from
computeIndirectRegAndOffset.
2024-07-16 09:12:39 +01:00
Stanislav Mekhanoshin
b132dd41eb
[AMDGPU] Remove wavefrontsize feature from GFX10+ (#98400)
Processor definition shall not include a default feature which may be
switched off by a different wave size. This allows not to write
-mattr=-wavefrontsize32,+wavefrontsize64 in tests.
2024-07-16 01:02:25 -07:00
Jay Foad
4420c57fc3 [AMDGPU] Add a test case for #98063
Add a test case to demonstrate broken IR caused by #98063 "[AMDGPU] Do
not use original PHIs in coercion chains" before it was reverted.
2024-07-15 15:17:12 +01:00
Jay Foad
1612e4a351 Revert "[AMDGPU] Do not use original PHIs in coercion chains (#98063)"
This reverts commit dc8ea046a516c3bdd0ece306f406c9ea833d4dac.

It generated broken IR as described here:
https://github.com/llvm/llvm-project/pull/98063#issuecomment-2225259451
2024-07-15 15:15:29 +01:00
Vikram Hegde
cf230e7799
[AMDGPU] Enable atomic optimizer for divergent i64 and double values (#96934) 2024-07-15 17:49:09 +05:30
paperchalice
1663ac523c
[AMDGPU] Remove some invalid tests (#98796)
`-early-live-intervals` only affects default pipeline. If
`LiveIntervalsAnalysis` happens before `TwoAddressInstructionPass`,
`llc` will crash, by adding `-run-pass liveintervals`.
2024-07-15 19:49:18 +08:00
Matt Arsenault
b1bcb7ca46 Reapply "AMDGPU: Move attributor into optimization pipeline (#83131)" and follow up commit "clang/AMDGPU: Defeat attribute optimization in attribute test" (#98851)
This reverts commit adaff46d087799072438dd744b038e6fd50a2d78.

Drop the -O3 checks from default-attributes.hip. I don't know why they
are different on some bots but reverting this is far too disruptive.
2024-07-15 11:51:44 +04:00
paperchalice
01191874f9
[CodeGen] Port two-address-instructions to new pass manager (#98632)
Add `TwoAddressInstructionPass`.
2024-07-15 15:11:06 +08:00
paperchalice
c09ed6a29e
[CodeGen][NewPM] Port MachineVerifier to new pass manager (#98628)
- Add `MachineVerifierPass`.
- Use complete `MachineVerifierPass` in `VerifyInstrumentation` if
possible.

`LiveStacksAnalysis` will be added in future, all other analyses are
done.
2024-07-15 12:42:44 +08:00
Carl Ritson
e025e5ef44 [AMDGPU] Reland generated test fix-wwm-vgpr-copy.ll (NFC)
Fix issues left over after generation.
2024-07-15 13:28:41 +09:00
Carl Ritson
8da3852f44 Revert "[AMDGPU] Generate test fix-wwm-vgpr-copy.ll (NFC)"
This reverts commit 5c8eb83ce8e4ef40fbd61a05f1de6394eb908da4.
2024-07-15 13:07:32 +09:00
Carl Ritson
5c8eb83ce8 [AMDGPU] Generate test fix-wwm-vgpr-copy.ll (NFC) 2024-07-15 12:02:33 +09:00
dyung
adaff46d08
Revert "AMDGPU: Move attributor into optimization pipeline (#83131)" and follow up commit "clang/AMDGPU: Defeat attribute optimization in attribute test" (#98851)
This reverts commits 677cc15e0ff2e0e6aa30538eb187990a6a8f53c0 and
78bc1b64a6dc3fb6191355a5e1b502be8b3668e7.

The test CodeGenHIP/default-attributes.hip is failing on multiple bots
even after the attempted fix including the following:
- https://lab.llvm.org/buildbot/#/builders/3/builds/1473
- https://lab.llvm.org/buildbot/#/builders/65/builds/1380
- https://lab.llvm.org/buildbot/#/builders/161/builds/595
- https://lab.llvm.org/buildbot/#/builders/154/builds/1372
- https://lab.llvm.org/buildbot/#/builders/133/builds/1547
- https://lab.llvm.org/buildbot/#/builders/81/builds/755
- https://lab.llvm.org/buildbot/#/builders/40/builds/570
- https://lab.llvm.org/buildbot/#/builders/13/builds/748
- https://lab.llvm.org/buildbot/#/builders/12/builds/1845
- https://lab.llvm.org/buildbot/#/builders/11/builds/1695
- https://lab.llvm.org/buildbot/#/builders/190/builds/1829
- https://lab.llvm.org/buildbot/#/builders/193/builds/962
- https://lab.llvm.org/buildbot/#/builders/23/builds/991
- https://lab.llvm.org/buildbot/#/builders/144/builds/2256
- https://lab.llvm.org/buildbot/#/builders/46/builds/1614

These bots have been broken for a day, so reverting to get everything
back to green.
2024-07-14 18:48:54 -07:00
Matt Arsenault
78bc1b64a6
AMDGPU: Move attributor into optimization pipeline (#83131)
Removing it from the codegen pipeline induces a lot of test churn
because llc is no longer optimizing out implicit arguments to kernels.

Mostly mechanical, but there are some creative test updates. I preferred
to take the changes as-is in tests where the ABI isn't relevant. In
cases where it's more relevant, or the optimize out logic was too
ingrained in the test, I pre-run the optimization. Some cases manually
add attributes to disable inputs.
2024-07-14 08:36:33 +04:00
Jay Foad
ae63db7882
[AMDGPU] Re-enable atomic optimization of uniform fadd/fsub with result (#97604)
Fix various problems to do with the first active lane of the result of
optimized fp atomics, as explained in the comment.

Fixes #97554
2024-07-13 11:18:45 +01:00
Jay Foad
520e045405
[AMDGPU] Handle llvm.amdgcn.pops.exiting.wave.id with calls (#98614) 2024-07-12 21:00:26 +01:00
Fabian Ritter
cbc96b9ef9
Reapply "[LowerMemIntrinsics] Use correct alignment in residual loop for variable llvm.memcpy" (#98482)
Reverts llvm/llvm-project#98295, which reverted llvm/llvm-project#97998

The failure in the "InOneWeekend" test of the HIP test suite on
clang-hip-vega20
(https://lab.llvm.org/buildbot/#/builders/123/builds/1498) seems to be
unrelated; I observed it (and a similar failure for the "TheNextWeek"
test in the same suite) intermittently on my system, with and without
the patch applied. (It occurred in 2 out of 50 repeated runs without the
patch and in 1 out of 50 runs with the patch.)
2024-07-12 08:44:34 +02:00
Vikram Hegde
0d9d5f7ea2
[CodeGen] Guard copy propagation in machine CSE against undefs (#97413) 2024-07-12 10:23:35 +05:30
Jay Foad
d4e46f0e86
[AMDGPU] Fix machine verification failure from INIT_EXEC lowering (#98333)
Fix machine verification failure from INIT_EXEC lowering since it was
moved from SILowerControlFlow to SIWholeQuadMode in #94452.
2024-07-11 09:18:50 +01:00