61058 Commits

Author SHA1 Message Date
Simon Pilgrim
6e47bff24d
[AMDGPU] callee-special-input-vgprs.ll / callee-special-input-vgprs-packed.ll - regenerate test coverage (#159587) 2025-09-18 15:19:48 +00:00
Fabian Ritter
01b4b2a5b8
[AMDGPU][SDAG] Handle ISD::PTRADD in VOP3 patterns (#143881)
This patch mirrors similar patterns for ISD::ADD. The main difference is
that ISD::ADD is commutative, so that a pattern definition for, e.g.,
(add (mul x, y), z), automatically also handles (add z, (mul x, y)).
ISD::PTRADD is not commutative, so we would need to handle these cases
explicitly. This patch only implements (ptradd z, (op x, y)) patterns,
where the nested operation (shift or multiply) is the offset of the
ptradd (i.e., the right operand), since base pointers that are the
result of a shift or multiply seem less likely.

For SWDEV-516125.
2025-09-18 15:01:07 +02:00
Petar Avramovic
2ec7959b96
[AMDGPU][SIInsertWaitcnts] Track SCC. Insert KM_CNT waits for SCC writes. (#157843)
Add new event SCC_WRITE for s_barrier_signal_isfirst and s_barrier_leave,
instructions that write to SCC, counter is KM_CNT.
Also start tracking SCC for reads and writes.
s_barrier_wait on the same barrier guarantees that the SCC write from
s_barrier_signal_isfirst has landed, no need to insert s_wait_kmcnt.
2025-09-18 14:41:01 +02:00
Simon Pilgrim
85527609a0
[AMDGPU] kernel-argument-dag-lowering.ll - regenerate test coverage (#159526) 2025-09-18 09:34:38 +00:00
Simon Pilgrim
573b3775e4
[X86] Add test coverage for #158649 (#159524)
Demonstrates the failure to keep avx512 mask predicate bit manipulation
patterns (based off the BMI1/BMI2/TBM style patterns) on the predicate
registers - unless the pattern is particularly complex the cost of
transferring to/from gpr outweighs any gains from better scalar
instructions

I've been rather random with the mask types for the tests, I can adjust
later on if there are particular cases of interest
2025-09-18 09:33:10 +00:00
David Green
d76d0a5139 [AArch64] Regenerate and update a number of check lines. NFC 2025-09-18 09:54:47 +01:00
yingopq
ddf0f6fe91
Revert "[Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2" (#159495)
Reverts llvm/llvm-project#149983
2025-09-18 15:07:15 +08:00
Jim Lin
8548fa00f1
[RISCV] Match fmaxnum and fminnum to reduction ops. (#159244)
This patch tries to match fmaxnum and fminnum to vector reductions.
2025-09-18 11:11:52 +08:00
Boyao Wang
27f8f9e1f1
[RISCV][CodeGen] Add CodeGen support of Zibi experimental extension (#146858)
This adds the CodeGen support of Zibi v0.1 experimental extension, which
depends on #127463.
2025-09-18 11:03:48 +08:00
woruyu
1a172b9924
[RISCV][GISel] Lower G_SSUBE (#157855)
### Summary
Try to implemente Lower G_SSUBE in LegalizerHelper::lower
2025-09-18 10:08:56 +08:00
hev
7ca448e479
[LoongArch] Fix MergeBaseOffset for constant pool index operand (#159336)
Fixes #159200
2025-09-18 10:06:33 +08:00
Craig Topper
38f2a1cb9b
[RISCV][GISel] Test legalizing s64 G_UADDE on RV32. And s128 on RV64. NFC (#159412) 2025-09-17 17:23:28 -07:00
Stanislav Mekhanoshin
221f8eef9d
[AMDGPU] Add gfx1251 runlines to cooperative atomcis tests. NFC (#159437) 2025-09-17 14:08:05 -07:00
Björn Pettersson
1c4c7bd808
[SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (#143102)
As reported in https://github.com/llvm/llvm-project/issues/141034
SelectionDAG::getNode had some unexpected
behaviors when trying to create vectors with UNDEF elements. Since
we treat both UNDEF and POISON as undefined (when using isUndef())
we can't just fold away INSERT_VECTOR_ELT/INSERT_SUBVECTOR based on
isUndef(), as that could make the resulting vector more poisonous.

Same kind of bug existed in DAGCombiner::visitINSERT_SUBVECTOR.

Here are some examples:

This fold was done even if vec[idx] was POISON:
  INSERT_VECTOR_ELT vec, UNDEF, idx -> vec

This fold was done even if any of vec[idx..idx+size] was POISON:
  INSERT_SUBVECTOR vec, UNDEF, idx -> vec

This fold was done even if the elements not extracted from vec could
be POISON:
  sub = EXTRACT_SUBVECTOR vec, idx
  INSERT_SUBVECTOR UNDEF, sub, idx -> vec

With this patch we avoid such folds unless we can prove that the
result isn't more poisonous when eliminating the insert.

Fixes https://github.com/llvm/llvm-project/issues/141034
2025-09-17 21:04:00 +00:00
Stanislav Mekhanoshin
e556dc0b23
[AMDGPU] Add gfx1251 subtarget (#159430) 2025-09-17 13:02:02 -07:00
Ying Wang
4bac9d4911
[RISCV] Add isel for bitcasting between bfloat and half types (#158828)
There is no RISCV isel for bitcast between f16 and bf16 which will
trigger "cannot select" fatal error.

Co-authored-by: Ying Wang <wy446777@alibaba-inc.com>
2025-09-17 12:10:47 -07:00
Vladislav Dzhidzhoev
432b58915a
[DebugInfo][DwarfDebug] Separate creation and population of abstract subprogram DIEs (#159104)
With this change, construction of abstract subprogram DIEs is split in
two stages/functions:
creation of DIE (in DwarfCompileUnit::getOrCreateAbstractSubprogramDIE)
and its population with children (in
DwarfCompileUnit::constructAbstractSubprogramScopeDIE).
With that, abstract subprograms can be created/referenced from
DwarfDebug::beginModule, which should solve the issue with static local
variables DIE creation of inlined functons with optimized-out
definitions. It fixes https://github.com/llvm/llvm-project/issues/29985.

LexicalScopes class now stores mapping from DISubprograms to their
corresponding llvm::Function's. It is supposed to be built before
processing of each function (so, now LexicalScopes class has a method
for "module initialization" alongside the method for "function
initialization"). It is used by DwarfCompileUnit to determine whether a
DISubprogram needs an abstract DIE before DwarfDebug::beginFunction is
invoked.

DwarfCompileUnit::getOrCreateSubprogramDIE method is added, which can
create an abstract or a concrete DIE for a subprogram. It accepts
llvm::Function* argument to determine whether a concrete DIE must be
created.

This is a temporary fix for
https://github.com/llvm/llvm-project/issues/29985. Ideally, it will be
fixed by moving global variables and types emission to
DwarfDebug::endModule (https://reviews.llvm.org/D144007,
https://reviews.llvm.org/D144005).

Some code proposed by Ellis Hoag <ellis.sparky.hoag@gmail.com> in
https://github.com/llvm/llvm-project/pull/90523 was taken for this
commit.
2025-09-17 20:06:49 +02:00
Benedikt Lukas Huber
e56b479d9f
[Hexagon] Bugfix in VarArg lowering: Special case for musl (#157564)
While debugging #145206 I found that a possible cause for the problem is
the call to printf, which is variadic.

In a musl environment VarArgs are treated like *non* VarArgs.
The handling of this special case was bypassed by the commit 
a4f85515c20566a3c059aacd1ee3554b598f33f0.

The reason is that the arguement `TreatAsVarArg` is only set to `true`
in
an *non* musl env. `TreatAsVarArg` determines the result of
`isVarArg()`.
The `CCIfArgVarArg` class only checks each individual
variable, but not whether `isVarArg()` is true.

Without the special case, the unnamed arguments are always passed
on the stack, as is standard calling convention. But with musl
also unnamed arguments can be passed in registers.

Possibly, this fixes #145206.
2025-09-17 11:03:27 -07:00
Stanislav Mekhanoshin
f0090bacc1
[AMDGPU] Fold copies of constant physical registers into their uses (#154410)
Co-authored-by: Jay Foad <Jay.Foad@amd.com>

Co-authored-by: Jay Foad <Jay.Foad@amd.com>
2025-09-17 10:49:34 -07:00
David Green
a50c11a715
[AArch64] Enable GlobalMerge on externals (#158592)
GlobalMerge has been enabled for minsize for a while, this patch enables
it more generally. In my testing it did not affect performance very
much, especially with the linker relaxations we already perform, but
should help reduce code size a little.
2025-09-17 17:49:23 +01:00
Ryan Cowan
d90a313b5e
[AArch64][GlobalISel] Legalize more G_VECREDUCE_FMIN/FMAX operations. (#159082)
Enabling scalarisation for `G_VECREDUCE_FMIN` and `G_VECREDUCE_FMAX`
allows for more instructions to be handled such as `v2fp128`.
2025-09-17 17:19:10 +01:00
Piotr Fusik
7a098aecb6
[RISCV] Implement computeKnownBitsForTargetNode for SHL_ADD (#159105) 2025-09-17 18:03:32 +02:00
pkarveti
b2f38637cd
[Hexagon] Added v32i1/v64i1 to v32f32/v64f16 lowering (#159355)
This patch introduces uint_to_fp conversions from v32i1 and v64i1
predicate vectors to v32f32 and v64f16 floating-point vectors.

Patch-by: Santanu Das

Co-authored-by: quic-santdas <quic_santdas@quicinc.com>
2025-09-17 09:49:27 -05:00
Brox Chen
2b2b580c8d
[AMDGPU][CodeGen][True16] Track waitcnt as vgpr32 instead of vgpr16 for D16 Instructions in GFX11 (#157795)
It seems the VMEM access on hi/lo half could interfere the other half.
Track waitcnt of vgpr32 instead of vgpr16 for 16bit reg in GFX11.

---------

Co-authored-by: Joe Nash <joseph.nash@amd.com>
2025-09-17 10:09:06 -04:00
Matt Arsenault
aac8eb85b2
AMDGPU: Fixes for regbankselecting copies of i1 physregs to sgprs (#159283)
If the source register of a copy was a physical sgpr copied to an
s1 value, this would assert.
2025-09-17 19:48:39 +09:00
Sander de Smalen
17e008db17
[IR] NFC: Remove 'experimental' from partial.reduce.add intrinsic (#158637)
The partial reduction intrinsics are no longer experimental, because
they've been used in production for a while and are unlikely to change.
2025-09-17 11:44:47 +01:00
Paul Walker
4c16cfff6f [NFC][LLVM][AArch64] Add use-constant-int-for-* RUN lines to global-isel tests.
CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
  CodeGen/AArch64/GlobalISel/irtranslator-one-by-n-vector-ptr-add.ll
2025-09-17 10:20:59 +00:00
yingopq
b7f68cb08c
[Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#149983)
Fix #145411.
2025-09-17 17:36:39 +08:00
sstipano
56ebbebada
[AMDGPU][NFC] Add back -new-reg-bank-select flag. (#159181) 2025-09-17 11:29:16 +02:00
Hongyu Chen
b29c7ded31
[AArch64] Fold uaddv(a) to a if the all lanes except the 0th are zeros (#159086)
Fixes https://github.com/llvm/llvm-project/issues/158741
2025-09-17 17:20:41 +08:00
Mary Kassayova
559cfefee1
[AArch64][SME] Introduce CHECK_MATCHING_VL pseudo for streaming transitions (#157510)
This patch adds a new codegen-only pseudo-instruction,
`CHECK_MATCHING_VL`, used when transitioning between non-streaming /
streaming-compatible callers and streaming-enabled callees. The pseudo
verifies that the current SVE vector length (VL) matches the streaming
vector length (SVL); if they differ, we trap.
2025-09-17 09:39:30 +01:00
Piotr Fusik
ec2ce34773
[RISCV] Lower (select c, (1 << X) + 1, 0) -> (shXadd c, c) (#158969) 2025-09-17 07:19:46 +02:00
Craig Topper
ab0bb6db39
[RISCV][GISel] Update rv32 s64 G_SADDE legalizer test. (#159153)
We were testing 2 s32 G_SADDE instead of a single s64 G_SADDE.

Similar for s128 on RV64.
2025-09-16 21:16:31 -07:00
Shilei Tian
f7f7abcde4
[NFC][AMDGPU] Add a missing test case about cluster dims (#159179) 2025-09-16 22:56:24 -04:00
hev
799b80d47a
[LoongArch] Fix instruction selection failure for BUILD_VECTOR on LA32 (#158788)
Fixes #158625
2025-09-17 09:03:06 +08:00
Krzysztof Drewniak
96ce9f9d64
[AMDGPU] Prevent re-visits in LowerBufferFatPointers (#159168)
Fixes https://github.com/iree-org/iree/issues/22001

The visitor in SplitPtrStructs would re-visit instructions if an
instruction earlier in program order caused a recursive visit() call via
getPtrParts(). This would cause instructions to be processed multiple
times.

As a consequence of this, PHI nodes could be added to the Conditionals
array multiple times, which would to a conditinoal that was already
simplified being processed multiple times. After the code moved to
InstSimplifyFolder, this re-processing, combined with more agressive
simplifications, would lead to an attempt to replace an instruction with
itself, causing an assertion failure and crash.

This commit resolves the issue and adds the reduced form of the crashing
input as a test.
2025-09-16 18:02:18 -07:00
Stanislav Mekhanoshin
4ab8dabc25
[AMDGPU] Add s_cluster_barrier on gfx1250 (#159175) 2025-09-16 14:49:48 -07:00
Shilei Tian
8122ccdca9
[AMDGPU] Set TGID_EN_X/Y/Z when cluster ID intrinsics are used (#159120)
Hardware initializes a single value in ttmp9 which is either the
workgroup ID X or cluster ID X. Most of this patch is a refactoring to
use a single `PreloadedValue` enumerator for this value, instead of two
enumerators `WORKGROUP_ID_X` and `CLUSTER_ID_X` referring to the same
value.

This makes it simpler to have a single attribute
`amdgpu-no-workgroup-id-x` indicating that this value is not used, which
in turns sets the TGID_EN_X bit appropriately to tell the hardware
whether to initialize it.

All of the above applies to Y and Z similarly.

Fixes: LWPSCGFX13-568

Co-authored-by: Jay Foad <jay.foad@amd.com>
2025-09-16 15:37:01 -04:00
Shilei Tian
158eeb344b
[AMDGPU] Change scale_sel to be 4 bits (#157900)
The latest SP changes updated it to use `OP_SEL[0:3]` instead of
`OP_SEL[0:2]`.

Fixes SWDEV-554472.
2025-09-16 15:36:45 -04:00
Stanislav Mekhanoshin
fd59fd563f
[AMDGPU] Add aperture classes to VS_64 (#158823)
Should not do anything.
2025-09-16 11:15:50 -07:00
Matt Arsenault
0648c5183f
AMDGPU: Fix some broken regclass numbers in mir tests (#159102) 2025-09-16 17:45:29 +00:00
Craig Topper
f209d63b04
[SelectionDAGBuilder][PPC] Use getShiftAmountConstant. (#158400)
The PowerPC changes are caused by shifts created by different IR
operations being CSEd now. This allows consecutive loads to be turned
into vectors earlier. This has effects on the ordering of other combines
and legalizations. This leads to some improvements and some regressions.
2025-09-16 10:26:49 -07:00
Craig Topper
4be1099607
[RISCV] Improve fixed vector handling in isCtpopFast. (#158380)
Previously we considered fixed vectors fast if Zvbb or Zbb is
enabled. Zbb only helps if the vector type will end up being
scalarized.
2025-09-16 09:47:09 -07:00
Fangrui Song
0cf6688898
MC: Better handle backslash-escaped symbols (#158780)
The MCContext::getOrCreateSymbol change in #138817 was a workaround.
With #158106, we can replace `getOrCreateSymbol` with `parseSymbol`, in
llvm/lib/MC/MCParser to handle backslash-escaped symbols.
2025-09-16 16:42:09 +00:00
Lei Huang
b22448c9ba
[PowerPC] Add intrinsic definition for load and store with Right Length Left-justified (#148873) 2025-09-16 12:36:28 -04:00
Alexey Karyakin
1327288324
[Hexagon] Lowering saturating subtraction (#158726)
Saturating arithmetic can be expressed by llvm.uadd/usub.sat generic
intrinsics.
2025-09-16 11:35:56 -05:00
yonghong-song
c3fb2e1cee
[BPF] Support Jump Table (#149715)
Add jump table (switch statement and computed goto) support for BPF
backend.
A `gotox <reg>` insn is implemented and the `<reg>` holds the target
insn where the gotox will go.

For a switch statement like
```
...
            switch (ctx->x) {
            case 1: ret_user = 18; break;
            case 20: ret_user = 6; break;
            case 16: ret_user = 9; break;
            case 6: ret_user = 16; break;
            case 8: ret_user = 14; break;
            case 30: ret_user = 2; break;
            default: ret_user = 1; break;
            }
...
```
and the final binary
```
    The final binary:
       4:       67 01 00 00 03 00 00 00 r1 <<= 0x3                                                           
       5:       18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0x0 ll                                  
                0000000000000028:  R_BPF_64_64  BPF.JT.0.0                                                   
       7:       0f 12 00 00 00 00 00 00 r2 += r1
        ...
    Symbol table:
     4: 0000000000000000   240 OBJECT  GLOBAL DEFAULT     4 BPF.JT.0.0
     5: 0000000000000000     4 OBJECT  GLOBAL DEFAULT     6 ret_user
     6: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND bar
     7: 00000000000000f0   256 OBJECT  GLOBAL DEFAULT     4 BPF.JT.0.1
    and
  [ 4] .jumptables       PROGBITS        0000000000000000 0001c8 0001f0 00      0   0  1
```
Note that for the above example, `-mllvm -bpf-min-jump-table-entries=5`
should be in compilation flags as the current default
bpf-min-jump-table-entries is 13. For example.
```
clang --target=bpf -mcpu=v4 -O2 -mllvm -bpf-min-jump-table-entries=5 -S -g test.c
```

For computed goto like
```
      int foo(int a, int b) {
        __label__ l1, l2, l3, l4;
        void *jt1[] = {[0]=&&l1, [1]=&&l2};
        void *jt2[] = {[0]=&&l3, [1]=&&l4};
        int ret = 0;
    
        goto *jt1[a % 2];
        l1: ret += 1;
        l2: ret += 3;
        goto *jt2[b % 2];
        l3: ret += 5;
        l4: ret += 7;
        return ret;
      }
```
The final binary:
```
      12:       bf 23 20 00 00 00 00 00 r3 = (s32)r2
      13:       67 03 00 00 03 00 00 00 r3 <<= 0x3
      14:       18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0x0 ll
                0000000000000070:  R_BPF_64_64  BPF.JT.0.0
      16:       0f 32 00 00 00 00 00 00 r2 += r3
      17:       bf 11 20 00 00 00 00 00 r1 = (s32)r1
      18:       67 01 00 00 03 00 00 00 r1 <<= 0x3
      19:       18 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r3 = 0x0 ll
                0000000000000098:  R_BPF_64_64  BPF.JT.0.1
      21:       0f 13 00 00 00 00 00 00 r3 += r1
    
  [ 4] .jumptables       PROGBITS        0000000000000000 000160 000020 00      0   0  1

     4: 0000000000000000    16 OBJECT  GLOBAL DEFAULT     4 BPF.JT.0.0
     5: 0000000000000010    16 OBJECT  GLOBAL DEFAULT     4 BPF.JT.0.1
```

A more complicated test with both switch-statement triggered jump table
and compute gotos:

```
$ cat test3.c
struct simple_ctx {
        int x;
        int y;
        int z;
};

int ret_user, ret_user2;
void bar(void);
int foo(struct simple_ctx *ctx, struct simple_ctx *ctx2, int a, int b)
{
        __label__ l1, l2, l3, l4;
        void *jt1[] = {[0]=&&l1, [1]=&&l2};
        void *jt2[] = {[0]=&&l3, [1]=&&l4};
        int ret = 0;

        goto *jt1[a % 2];
        l1: ret += 1;
        l2: ret += 3;
        goto *jt2[b % 2];
        l3: ret += 5;
        l4: ret += 7;

        bar();

        switch (ctx->x) {
        case 1: ret_user = 18; break;
        case 20: ret_user = 6; break;
        case 16: ret_user = 9; break;
        case 6: ret_user = 16; break;
        case 8: ret_user = 14; break;
        case 30: ret_user = 2; break;
        default: ret_user = 1; break;
        }

        return ret;
}
```
Compile with
```
  clang --target=bpf -mcpu=v4 -O2 -S test3.c
  clang --target=bpf -mcpu=v4 -O2 -c test3.c
```
  The binary:
```
     /* For computed goto */
      13:       bf 42 20 00 00 00 00 00 r2 = (s32)r4                                                         
      14:       67 02 00 00 03 00 00 00 r2 <<= 0x3                                                           
      15:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0x0 ll                                  
                0000000000000078:  R_BPF_64_64  BPF.JT.0.1                                                   
      17:       0f 21 00 00 00 00 00 00 r1 += r2                                                             
      18:       bf 32 20 00 00 00 00 00 r2 = (s32)r3                                                         
      19:       67 02 00 00 03 00 00 00 r2 <<= 0x3                                                           
      20:       18 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r3 = 0x0 ll                                  
                00000000000000a0:  R_BPF_64_64  BPF.JT.0.2                                                   
      22:       0f 23 00 00 00 00 00 00 r3 += r2

      /* For switch statement */
      39:       67 01 00 00 03 00 00 00 r1 <<= 0x3
      40:       18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0x0 ll
                0000000000000140:  R_BPF_64_64  BPF.JT.0.0
      42:       0f 12 00 00 00 00 00 00 r2 += r1
```
You can see jump table symbols are all different.
2025-09-16 09:27:08 -07:00
Damian Heaton
3eea01e731
[AArch64] Add ISel support for partial reductions to use SVE2.1 udot/sdot (#158310)
This allows dot products with scalable 8xi16 vectors (and fixed-length
vectors which are converted into a scalable vector) accumulating into a
4xi32 vector to lower into a single instruction (`udot`/`sdot`), rather
than a sequence of `umlalb`s and `umlalt`s`.
2025-09-16 17:05:11 +01:00
Janek van Oirschot
341cdbc970
[AMDGPU] Elide bitcast fold i64 imm to build_vector (#154115)
Elide bitcast combine to build_vector in case of i64 immediate that can
be materialized through 64b mov
2025-09-16 16:44:51 +01:00
guan jian
6aab826e23
[DAGCombiner] add fold (xor (smin(x, C), C)) and fold (xor (smax(x, C), C)) (#155141)
Hi, I compared the following LLVM IR with GCC and Clang, and there is a small difference between the two. The LLVM IR is:
```
define i64 @test_smin_neg_one(i64 %a) {
  %1 = tail call i64 @llvm.smin.i64(i64 %a, i64 -1)
  %retval.0 = xor i64 %1, -1
  ret i64 %retval.0
}
```
GCC generates:
```
	cmp	x0, 0
	csinv	x0, xzr, x0, ge
	ret
```
Clang generates:
```
	cmn	x0, #1
	csinv	x8, x0, xzr, lt
	mvn	x0, x8
	ret
```
Clang keeps flipping x0 through x8 unnecessarily.
So I added the following folds to DAGCombiner:
fold (xor (smax(x, C), C)) -> select (x > C), xor(x, C), 0
fold (xor (smin(x, C), C)) -> select (x < C), xor(x, C), 0

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

---------

Co-authored-by: Yui5427 <785369607@qq.com>
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-09-16 15:30:57 +00:00