58918 Commits

Author SHA1 Message Date
Fangrui Song
bb03cdcb44
RISCV: Remove shouldForceRelocation and unneeded relocations
Follow-up to #140494

`shouldForceRelocation` is conservative and produces redundant
relocations.

For example, RISCVAsmBackend::ForceRelocs (introduced to support mixed
relax/norelax code) leads to redundant relocations in the following
example adapted from #77436

```
.option norelax
j label
// For assembly input, RISCVAsmParser::ParseInstruction sets ForceRelocs (https://reviews.llvm.org/D46423).
// For direct object emission, RISCVELFStreamer sets ForceRelocs (#77436)
.option relax
call foo  // linker-relaxable

.option norelax
j label   // redundant relocation due to ForceRelocs
.option relax

label:
```

Root problem: The `isSymbolRefDifferenceFullyResolvedImpl` condition in
MCAssembler::evaluateFixup does not check whether two locations are
separated by a fragment whose size can be indeterminate due to linker
instruction (e.g. MCDataFragment with relaxation, or MCAlignFragment
due to indeterminate start offst).

This patch

* Updates the fragment walk code in
  `attemptToFoldSymbolOffsetDifference` to treat MCRelaxableFragment
  (for --riscv-asm-relax-branches) as fixed size after finishLayout.
* Adds a condition in `addReloc` to complement
  `isSymbolRefDifferenceFullyResolvedImpl`.
* Removes the no longer needed `shouldForceRelocation`.

This fragment walk code path handles nicely handles
mixed relax/norelax case from
https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
and allows us to remove `MCSubtargetInfo` argument (#73721) as a follow-up.

This fragment walk code should be avoided in the absence of
linker-relaxable fragments within the current section.

Adjust two bolt/test/RISCV tests (#141310)

Pull Request: https://github.com/llvm/llvm-project/pull/140692
2025-05-23 18:44:15 -07:00
Philip Reames
77a3f81dc4
[RISCV] Custom lower fixed length partial.reduce to zvqdotq (#141180)
This is a follow on to 9b4de7 which handles the fixed vector cases. In
retrospect, this is simple enough if probably should have just been part
of the original commit, but oh well.
2025-05-23 13:56:49 -07:00
Craig Topper
75d62ee853
[RISCV] Correctly account for the copy cost of GPR pairs in RISCVMakeCompressible. (#141251)
GPR pairs require 2 ADDIs to copy, so we need to be updating more
instructions to get a benefit.
2025-05-23 11:37:42 -07:00
Craig Topper
a2d717d303
[RISCV] Prevent copying dummy_reg_pair_with_x0 in RISCVMakeCompressible. (#141261)
dummy_reg_pair_with_x0 is the odd subregister of X0_Pair, but it isn't a
real register. We need to copy X0 instead since X0_Pair reads as 0.
2025-05-23 11:35:49 -07:00
Koakuma
3f15b66dec
[SPARC] Use op-then-halve instructions when we have VIS3
Reviewers: brad0, s-barannikov, arsenm, rorth

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/135718
2025-05-23 22:44:05 +07:00
Sarah Spall
1bdec97799
[DirectX] change makedouble return type to overloadTy (#141156)
Change makedouble return type to overloadTy so makedouble will match
validator expectations
Closes #140998
2025-05-23 08:22:36 -07:00
RolandF77
bbca78fbcb
[PowerPC] vector shift word/double by element size - 1 use all ones (#139794)
Vector shift word or double requires a shift amount vector of 31 or 63
which is too big for splat immediate and requires a multi-instruction
sequence. However the PPC instructions only use 5 or 6 bits of the shift
amount vector elements so an all ones mask, which we can generate
efficiently, works.
2025-05-23 10:49:37 -04:00
Simon Pilgrim
23a341e5ae [X86] vector-shuffle-combining-avx512bwvl.ll - regenerate test check 2025-05-23 14:10:17 +01:00
Shilei Tian
0f1277d0b3
[NFC][AMDGPU] Move flat_atomic.ll to llvm/test/CodeGen/AMDGPU/ (#141126) 2025-05-23 08:15:26 -04:00
Simon Pilgrim
6e574a4fa3
[X86] lowerVECTOR_SHUFFLE - canonicalize zeros/ones/fp splat constants to ensure no undefs (#141214)
Make it easier for splat/element-equivalent detection by ensuring
constant splats contain no undefs.

Integer constants are limited to rematerializable zeros/ones values to
avoid unnecessary scalar_to_vector(int) -> load conversions - we can
relax this later if useful
2025-05-23 11:02:46 +01:00
Dmitry Sidorov
69d6c1ff66
Revert "[SPIR-V] Support SPV_INTEL_int4 extension" (#141219)
Reverts llvm/llvm-project#141031
2025-05-23 11:45:55 +02:00
zGoldthorpe
bb7e559740
[AMDGPU] Correct bitshift legality transformation for small vectors (#140940)
Fix for a bug found by the AMD fuzzing project.

The legaliser would originally try to widen a small vector such as `<4 x
i1>` to a single `i16` during the legalisation of bitshifts, as it was
not originally written with consideration for vector operands. This
patch simply adds a guard to prohibit this transformation and allow
other legalisation transformations to step in.
2025-05-23 10:56:21 +02:00
Simon Pilgrim
34deb764a7
[X86] IsElementEquivalent - add handling for ISD::BITCASTS from smaller vector elements (#139741)
Check if all smaller aliased source elements are equivalent
2025-05-23 09:12:29 +01:00
Benjamin Maxwell
62cae9c3de
[AArch64] Don't use LowerToPredicatedOp to shufflevector -> SVE lowerings (#140713)
The use of `LowerToPredicatedOp` here seems like a mistake as
`LowerToPredicatedOp` turns the SDValue passed to it into the desired
predicated node by copying over operands (and adding a predicate). This
results in two odd things here, the BITCASTs created and passed to
`LowerToPredicatedOp` are not used, only the operands of those bitcasts
are taken. Secondly, when a shuffle vector node is passed directly to
`LowerToPredicatedOp` to create a `REVD_MERGE_PASSTHRU` node an invalid
REV node is created as REV only takes one vector operand, but both
operands from the shuffle vector are copied to the new REV node. This is
not an issue in practice as the extra operand is ignored.

These issues were found by the verification added in #140472.

Part of #140472.

Note: Test changes only result in the vxf64 lowering matching the vxi64
lowering.
2025-05-23 08:43:10 +01:00
hev
689342de25
[Clang][LoongArch] Add inline asm support for the q constraint (#141037)
This patch adds support for the `q` constraint:
a general-purpose register except for $r0 and $r1 (for the csrxchg
instruction)

Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684339.html
2025-05-23 11:14:41 +08:00
Alex MacLean
3a84a4e55d
Reland "[NVPTX] Unify and extend barrier{.cta} intrinsic support" (#141143)
Note: This relands #140615 adding a ".count" suffix to the non-".all"
variants.

Our current intrinsic support for barrier intrinsics is confusing and
incomplete, with multiple intrinsics mapping to the same instruction and
intrinsic names not clearly conveying intrinsic semantics. Further, we
lack support for some variants. This change unifies the IR
representation to a single consistently named set of intrinsics.

- llvm.nvvm.barrier.cta.sync.aligned.all(i32)
- llvm.nvvm.barrier.cta.sync.aligned.count(i32, i32)
- llvm.nvvm.barrier.cta.arrive.aligned.count(i32, i32)
- llvm.nvvm.barrier.cta.sync.all(i32)
- llvm.nvvm.barrier.cta.sync.count(i32, i32)
- llvm.nvvm.barrier.cta.arrive.count(i32, i32)

The following Auto-Upgrade rules are used to maintain compatibility with
IR using the legacy intrinsics:

* llvm.nvvm.barrier0 --> llvm.nvvm.barrier.cta.sync.aligned.all(0)
* llvm.nvvm.barrier.n --> llvm.nvvm.barrier.cta.sync.aligned.all(x)
* llvm.nvvm.bar.sync --> llvm.nvvm.barrier.cta.sync.aligned.all(x)
* llvm.nvvm.barrier --> llvm.nvvm.barrier.cta.sync.aligned.count(x, y)
* llvm.nvvm.barrier.sync --> llvm.nvvm.barrier.cta.sync.all(x)
* llvm.nvvm.barrier.sync.cnt --> llvm.nvvm.barrier.cta.sync.count(x, y)
2025-05-22 19:38:10 -07:00
hev
0635ef8240
[LoongArch][NFC] Improve csrxchg instrinsic test case (#141060)
Took xry's idea [^1] to improve the csrxchg instrinsic test case.

[^1]:
https://github.com/llvm/llvm-project/pull/141037#issuecomment-2900955906
2025-05-23 09:30:29 +08:00
Alex MacLean
f3eea12511
[NVPTX] Add intrinsic support for specialized prmt variants (#140951) 2025-05-22 13:05:17 -07:00
Matt Arsenault
db0bac0ef2
AMDGPU: Form v_med_f32 from minimumnum/maximumnum immediate pattern (#141048)
This makes little difference in the final output, as we manage to form this
after these are lowered to the _ieee operations. This does result in fewer steps
in the DAG, and helps prepare for changing the handling of minnum/maxnum.
2025-05-22 21:04:47 +02:00
Matt Arsenault
57e9097ad2
AMDGPU: Add baseline v_med3_f32 tests from minimumnum/maximumnum (#141047) 2025-05-22 21:01:49 +02:00
Viktoria Maximova
ced6076dfc
[SPIR-V] Support SPV_INTEL_int4 extension (#141031)
Adds support for native 4-bit type.

Spec:

https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_int4.asciidoc
2025-05-22 11:56:54 -07:00
Alex Maclean
e72d8b2553 Revert "[NVPTX] Unify and extend barrier{.cta} intrinsic support (#140615)"
This reverts commit 735209c0688b10a66c24750422b35d8c2ad01bb5.
2025-05-22 17:28:43 +00:00
Sumit Agarwal
b936112648
[HLSL] Move FNeg legalization to the DXILLegalization pass (#140942)
Fixes #137685
2025-05-22 10:43:00 -06:00
Jerry Zhang Jian
3ef1b07a6c
[RISCV] add Double Trap extension requires Zicsr (#141016)
- The double trap extension requires `mtval2' register, so add Zicsr as
required extension

Signed-off-by: Jerry Zhang Jian <jerry.zhangjian@sifive.com>
2025-05-23 00:27:04 +08:00
Simon Pilgrim
9a77af37d8
[X86] lowerV4F64Shuffle - prefer BLEND before UNPCK shuffle matching (#141073)
Use the same matching order as other 128/256-bit shuffles

Fixes regression identified in #139741
2025-05-22 16:51:00 +01:00
Philip Reames
9b4de7d885
[RISCV] Lower PARTIAL_REDUCE_[S/U]MLA via zvqdotq (#140950)
The semantics of the PARTIAL_REDUCE_SMLA with i32 result element, and i8
sources corresponds to vqdot. Analogously PARTIAL_REDUCE_UMLA
corresponds to vqdotu. There is currently no vqdotsu equivalent.

This patch is a starting place. We can extend this quite a bit more, and
I plan to take a look at the fixed vector lowering, the TTI hook to
drive loop vectorizer, and to try to integrate the reduction based
lowering I'd added for zvqdotq into this flow.
2025-05-22 08:29:05 -07:00
Craig Topper
c432936b05
[SelectionDAG][RISCV] Use VP_STORE to widen MSTORE in type legalization when possible. (#140991)
Widening the mask and padding with zeros doesn't work for scalable
vectors. Using VL produces less code for fixed vectors.

Similar was recently done for MLOAD.
2025-05-22 08:28:42 -07:00
Jay Foad
1f0c178411 Fix typo "redudant" 2025-05-22 15:42:22 +01:00
Simon Pilgrim
03cc50fd7d
[X86] lowerShuffleAsSplitOrBlend - prefer splitting AVX1-only shuffles if the operands can be freely split (#141055)
On an AVX1-only target, if both operands of a 256-bit shuffle can be freely split (concatenations or splats), then prefer to lower as 128-bit shuffles using splitAndLowerShuffle
2025-05-22 15:13:35 +01:00
Luigi Sartor Piucco
83de1efae3
[LangRef] Comment on validity of volatile ops on null (#139803)
Some hardware (for example, certain AVR chips) have peripheral registers
mapped to the data space address 0. Although a volatile load/store on
`ptr null` already generates expected code, the wording in the LangRef
makes operations on null seem like undefined behavior in all cases. This
commit adds a comment that, for volatile operations, it may be defined
behavior to access the address null, if the architecture permits it. The
intended use case is MMIO registers with hard-coded addresses that
include bit-value 0. A simple CodeGen test is included for AVR, as an
architecture known to have this quirk, that does `load volatile` and
`store volatile` to `ptr null`, expecting to generate `lds <reg>, 0` and
`sts 0, <reg>`.

See [this
thread](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Adding.20the.20possibility.20of.20volatile.20access.20to.20address.200)
and [the
RFC](https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303)
for discussion and context.
2025-05-22 15:12:34 +02:00
Orlando Cazalet-Hyams
34a55c9376
[BranchFolding] Fix assertion failure in HoistCommonCodeInSuccs (#141028)
Assertion failure introduced in #140063, which didn't account for TBB
and FBB being the same block.
2025-05-22 13:21:26 +01:00
Simon Pilgrim
b9a709832c
[X86] lowerShuffleAsSplitOrBlend - use isElementEquivalent to help identify hidden splat/broadcasts (#141035)
Noticed while yak shaving #139741
2025-05-22 13:01:21 +01:00
hev
bd8578c357
[LoongArch] Prevent R0/R1 allocation for rj operand of [G]CSRXCHG (#140862)
The `[G]CSRXCHG` instruction must not use R0 or R1 as the `rj` operand,
as encoding `rj` as 0 or 1 will be interpreted as `[G]CSRRD` OR
`[G]CSRWR`, respectively, rather than `[G]CSRXCHG`.

This patch introduces a new register class `GPRNoR0R1` and updates the
`[G]CSRXCHG` instruction definition to use it for the `rj` operand,
ensuring the register allocator avoids assigning R0 or R1.

Fixes #140842
2025-05-22 18:49:27 +08:00
Simon Pilgrim
c42c91cde4 [X86] icmp-abs-C-vec.ll - regenerate test checks for TERNLOG comments 2025-05-22 11:30:18 +01:00
David Green
a2aa88192f
[GlobalISel] Add a update_givaluetracking_test_checks.py script (#140296)
As with the other update scripts this takes the output of
-passes=print<gisel-value-tracking> and inserts the results into an
existing mir file. This means that the input is a lot like
update_analysis_test_checks.py, and the output needs to insert into a
mir file similarly to update_mir_test_checks.py. The code used to do the
inserting has been moved to common, to allow it to be reused. Otherwise
it tries to reuse the existing infrastructure, and
update_givaluetracking_test_checks is kept relatively short.
2025-05-22 09:06:37 +01:00
David Green
11953c647b
[ARM] Remove kill flags in ReplaceConstByVPNOTs. (#140082)
This is similar to #86300. The vpr register on this branch might be
killed before we reuse it.
2025-05-22 08:24:01 +01:00
Fangrui Song
53edb1a160 [test] Improve linker-relaxable fixups tests
The behavior will change once the assembler improves (#140692)
2025-05-21 22:08:55 -07:00
Mohammad Bashir
bcdce987c0
Fix regression tests with bad FileCheck checks (#140373)
Fixes https://github.com/llvm/llvm-project/issues/140149
2025-05-22 07:59:57 +03:00
Luke Lau
09c3d1432b
[IA] Add support for [de]interleave{3,5,7} (#139373)
This adds support for lowering deinterleave and interleave intrinsics
for factors 3 5 and 7 into target specific memory intrinsics.

Notably this doesn't add support for handling higher factors constructed
from interleaving interleave intrinsics, e.g. factor 6 from interleave3
+ interleave2.

I initially tried this but it became very complex very quickly. For
example, because there's now multiple factors involved
interleaveLeafValues is no longer symmetric between interleaving and
deinterleaving. There's then also two ways of representing a factor 6
deinterleave: It can both be done as either 1 deinterleave3 and 3
deinterleave2s OR 1 deinterleave2 and 3 deinterleave3s.

I'm not sure the complexity of supporting arbitrary factors is warranted
given how we only need to support a small number of factors currently:
SVE only needs factors 2,3,4 whilst RVV only needs 2,3,4,5,6,7,8.

My preference would be to just add a interleave6 and deinterleave6
intrinsic to avoid all this ambiguity, but I'll defer this discussion to
a later patch.
2025-05-22 04:32:47 +01:00
Sudharsan Veeravalli
f72a8ee489
[RISCV] Add Xqcibi Select_GPR_Using_CC_<Imm> Pseudos to isSelectPseudo (#140698)
Not adding them was leading to a crash when trying to expand these
pseudo instructions.

I've also fixed the register class types for the Xqcibi instructions in
these pseudo instructions which was incorrect and was exposed by the
machine verifier while running the test case added in this patch.

Fixes #140697
2025-05-22 08:57:26 +05:30
Lucas Ramirez
1b34722302
[AMDGPU] Fix computation of waves/EU maximum (#140921)
This fixes an issue in the waves/EU range calculation wherein, if the
`amdgpu-waves-per-eu` attribute exists and is valid, the entire
attribute may be spuriously and completely ignored if workgroup sizes
and LDS usage restrict the maximum achievable occupancy below the
subtarget maximum. In such cases, we should still honor the requested
minimum number of waves/EU, even if the requested maximum is higher than
the actually achievable maximum (but still within subtarget
specification).

As such, the added unit test `empty_at_least_2_lds_limited`'s waves/EU
range should be [2,4] after this patch, when it is currently [1,4] (i.e,
as if `amdgpu-waves-per-eu` was not specified at all).

Before e377dc4 the default maximum waves/EU was always set to the
subtarget maximum, trivially avoiding the issue.
2025-05-22 02:45:59 +02:00
Craig Topper
60ad6e3fa4
[SelectionDAG][RISCV] Use VP_LOAD to widen MLOAD in type legalization when possible. (#140595)
Padding the mask using 0 elements doesn't work for scalable vectors. Use
VP_LOAD and change the VL instead.

This fixes crash for Zve32x. Test file was split since i64 isn't a valid
element type for Zve32x.

Fixes #140198.
2025-05-21 15:52:08 -07:00
Brox Chen
7f62800fb8
[AMDGPU][True16][CodeGen] select vgpr16 for asm inline 16bit vreg (#140946)
select vgpr16 for asm inline 16bit vreg in true16 mode
2025-05-21 17:47:28 -04:00
Craig Topper
6212c199b1
[RISCV] Add tests for widening fixed vector masked loads/stores. NFC (#140949) 2025-05-21 13:31:23 -07:00
David Green
77c8d21413
[GlobalISel] Fix ZExt known bits for scalable vectors. (#140213)
It was using the full size of the vector as the SrcBitWidth. This patch
changes the code to split G_ASSERT_ZEXT away from the others (G_INTTOPTR
/ G_PTRTOINT / G_ZEXT / G_TRUNC) which are simpler, and make the code
match the SDAG equivalent.
2025-05-21 19:52:19 +01:00
Alex MacLean
76c9bfefa4
[NVPTX] Remove Float register classes (#140487)
These classes are redundant, as the untyped "Int" classes can be used
for all float operations. This change is intended to be as minimal as
possible and leaves the many potential simplifications and refactors
this exposes as future work.
2025-05-21 11:33:57 -07:00
Philip Reames
cbe9af1a9c [RISCV] Remove nsw/nuw from zvqdotq tests [nfc]
As noted in review comment https://github.com/llvm/llvm-project/pull/140922#discussion_r2100838209, this aren't required
2025-05-21 11:31:26 -07:00
Philip Reames
04d10f1d13 [RISCV] Expand zvqdotq partial.reduce test variants
Make sure to cover all the scalable types which are legal, plus
splitting.  Make sure to cover all instructions.  Not duplicating
vx testing at this time.
2025-05-21 11:19:48 -07:00
Philip Reames
68995b18da
[RISCV] Support scalable vectors for the zvqdotq lowering paths (#140922)
This was an oversight in the original patch series. Without this change,
the newly added tests fail assertions.
2025-05-21 10:52:39 -07:00
Vigneshwar Jayakumar
e12cbd8339
[AMDGPU] Fix scale opsel flags for scaled MFMA operations (#140183)
Fix for src scale opsel flags encoding and ASM parsing for gfx950 scaled MFMA.
2025-05-21 12:30:22 -05:00