57643 Commits

Author SHA1 Message Date
Akshat Oke
6c87ec4f4d
[AMDGPU][NPM] Port SIModeRegister to NPM (#129014) 2025-03-04 10:51:03 +05:30
Matt Arsenault
8476a5d480
SplitKit: Fix rematerialization undoing subclass based split (#122110)
This fixes an allocation failure in the new test.

In cases where getLargestLegalSuperClass can inflate the register class,
rematerialization could effectively undo a split which was done to
inflate
the register class, if the defining instruction can only write a
subclass
and the use can read the superclass.

Some of the x86 tests changes look like improvements, but some are
likely regressions.

I'm not entirely sure this is the correct place to fix this. It also
seems more complicated than necessary, but the decision to change
the register class is far removed from the point where the decision
to split the virtual register is made. I'm also also not sure if this
should be considering the register classes of all the use indexes
in getUseSlots, rather than just checking if this use index instruction
reads the register.
2025-03-04 10:04:14 +07:00
Daniel Zabawa
415f89905f
[X86] Remove single-use checks when combining xor and vfmulc/vcfmulc. (#128910)
The current implementation to combine xor patterns for conjugation with
complex multiplies will not perform the transformation when either the
conjugate xor result or other multiplicand have other uses. This change
eliminates both single-use checks.

The transformation will eliminate the xor dependence and hence should be
profitable even if the conjugate is used elsewhere - and more profitable
if the xor is used in multiple fmulc/fcmulc instructions, eventually
going dead.

The check of the other multiplicand isn't required for correctness and
has no apparent performance implications.
2025-03-04 09:35:37 +08:00
Jeffrey Byrnes
3963d21482
[MachineSink] Fix typo in loop sinking (#127133)
Failure to sink a candidate should not block us from attempting to sink
other candidates. There are mechanisms in place to handle the case where
the failed to be sunk instruction uses an instruction that gets sunk (we
do not delete the original instruction corresponding with the sunk
instruction if it still has uses).
2025-03-03 17:30:12 -08:00
JaydeepChauhan14
cf05b6e25a
[X86] Added support for 8 and 16bit LEA instructions (#122102) 2025-03-04 08:12:17 +08:00
Petr Penzin
b44fbdee00
[RISCV] Tune flag for fast vrgather.vv (#124664)
Add tune knob for N*Log2(N) vrgather.vv cost.
2025-03-03 16:04:49 -08:00
Brendan Sweeney
4fd5d935a3
[RISCV] Emitting proper atomic ABI tag when Zalasr is enabled (#121017)
When Zalasr is enabled, it will emit the A7 atomic ABI tag. Zalasr is
the load-acquire and store-release extension, and the reason A7 (and
A6S) exists is to support it.

The A7 atomic ABI is compatible with A6S (which is what is currently
emitted as the tag), but A7 is not compatible with A6C, while A6C and
A6S are compatible.


https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-atomic.adoc#risc-v-atomics-mappings


https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#tag_riscv_atomic_abi-14-uleb128version
2025-03-03 11:34:52 -08:00
Stanislav Mekhanoshin
6c9a9d9fe2
[AMDGPU] Set inst_pref_size to maximum (#126981)
On gfx11 and gfx12 set initial instruction prefetch size to a
minimum of kernel size and maximum allowed value.

Fixes: SWDEV-513122
2025-03-03 10:40:31 -08:00
Daniel Paoliello
e93cd15f9e
[win] Enable test/CodeGen/MIR/AArch64 on Windows (#122832)
Not sure why this was disabled in the first place (dates back to
<fbe9c04c5f>),
but it appears to be working for me.
2025-03-03 09:54:28 -08:00
Abhilash Majumder
7c580893ea
[NVPTX] Add Intrinsics for discard.* (#128404)
[NVPTX] Add  Intrinsics for discard.*
This PR adds intrinsics for all variations of discard.*

* These intrinsics supports generic or global for all variations.
* The lowering is handled from nvvm to nvptx tablegen directly.
* Lit tests are added as part of discard.ll
* The generated PTX is verified with a 12.3 ptxas executable.
* Added docs for these intrinsics in NVPTXUsage.rst.

For more information, refer to the PTX ISA

<https://docs.nvidia.com/cuda/parallel-thread-execution/#data-movement-and-conversion-instructions-discard>_.

---------

Co-authored-by: abmajumder <abmajumder@nvidia.com>
Co-authored-by: gonzalobg <65027571+gonzalobg@users.noreply.github.com>
2025-03-03 22:53:49 +05:30
zhijian lin
0303fd2746
[PowerPC] hoist xxspltib out of loop body (#127121)
Fixes https://github.com/llvm/llvm-project/issues/127119

Remove `hasSideEffects` from `xxspltib` since there is no special
restriction specified in the ISA that prevent it from being reordered,
move, CSE, or LICM. Removing this restriction will allow `xxspltib` to
be hoisted out of loop bodies.
2025-03-03 11:14:02 -05:00
Frederik Harwath
ba9bd22e1b
[AMDGPU] Account for existing SDWA selections (#123221)
The si-peephole-sdwa pass adjusts the selections on sdwa instructions to
the selections on their operands during its conversions. For instance,
if an instruction selects `BYTE_0` and its operand selects `WORD_1`, the
combined selection should be `BYTE_2`, i.e. "`BYTE_0` of `WORD_1`". The
existing implementation does not always handle this correctly in some
complex situations with instructions across different basic blocks as
demonstrated by the test cases included in this PR.

This PR adds an additional selection combination step to the conversion
to fix this issue. It reverts the changes made by PR #123942 which had
disabled the conversion of preexisting SDWA instructions completely as a
quick fix.

---------

Co-authored-by: Jeffrey Byrnes <Jeffrey.Byrnes@amd.com>
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-03-03 17:07:28 +01:00
David Green
cb850fef2a
[AArch64] Don't try to custom lower fp16 selects with nofp (#129492)
If we do not have fp then we do not need to try and custom lower fp16
selects.

Fixes #129394.
2025-03-03 15:50:11 +00:00
Abhishek Kaushik
17857d9241
[X86] Generate kmov for masking integers (#120593)
When we have an integer used as a bit mask the llvm ir looks something
like this
```
%1 = and <16 x i32> %.splat, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768>
%cmp1 = icmp ne <16 x i32> %1, zeroinitializer
```
where `.splat` is vector containing the mask in all lanes. The assembly
generated for this looks like
```
vpbroadcastd    %ecx, %zmm0
vptestmd        .LCPI0_0(%rip), %zmm0, %k1
```
where we have a constant table of powers of 2.
Instead of doing this we could just move the relevant bits directly to
`k` registers using a `kmov` instruction.
```
kmovw   %ecx, %k1
```
This is faster and also reduces code size.
2025-03-03 20:35:09 +05:30
Sergey Kachkov
3dc799162f
[RISCV] Add DAG combine to convert (iN reduce.add (zext (vXi1 A to vXiN)) into vcpop.m (#127497)
This patch combines (iN vector.reduce.add (zext (vXi1 A to vXiN)) into
vcpop.m instruction (similarly to bitcast + ctpop pattern). It can be
useful for counting number of set bits in scalable vector types, which
can't be expressed with bitcast + ctpop (this was previously discussed
here: https://github.com/llvm/llvm-project/pull/74294).
2025-03-03 16:27:52 +03:00
Phoebe Wang
3c9429f133
[X86] Remove redundant test after setzucc (#129506)
Patch #96594 substitutes setcc + zext pair with setzucc, but it results
in redundant test because X86FlagsCopyLowering doesn't recognize it.

This patch removes redundant test by reverting setzucc to setcc
(optimized) + zext.
2025-03-03 21:07:59 +08:00
Benjamin Maxwell
55fdeccc45
[SDAG][X86] Remove hack needed to avoid missing x87 FPU stack pops (#128055)
If a (two-result) node like `FMODF` or `FFREXP` is expanded to a library
call, where said library has the function prototype like: `float(float,
float*)` -- that is it returns a float from the call and via an output
pointer. The first result of the node maps to the value returned by
value and the second result maps to the value returned via the output
pointer.

If only the second result is used after the expansion, we hit an issue
on x87 targets:

```
// Before expansion: 
t0, t1 = fmodf x
return t1  // t0 is unused
```

Expanded result:
```
ptr = alloca
ch0 = call modf ptr
t0, ch1 = copy_from_reg, ch0 // t0 unused
t1, ch2 = ldr ptr, ch1
return t1
```

So far things are alright, but the DAGCombiner optimizes this to:
```
ptr = alloca
ch0 = call modf ptr
// copy_from_reg optimized out
t1, ch1 = ldr ptr, ch0
return t1
```

On most targets this is fine. The optimized out `copy_from_reg` is
unused and is a NOP. However, x87 uses a floating-point stack, and if
the `copy_from_reg` is optimized out it won't emit a pop needed to
remove the unused result.

The prior solution for this was to attach the chain from the
`copy_from_reg` to the root, which did work, however, the root is not
always available (it's set to null during legalize types). So the
alternate solution in this patch is to replace the `copy_from_reg` with
an `X86ISD::POP_FROM_X87_REG` within the X86 call lowering. This node is
the same as `copy_from_reg` except this node makes it explicit that it
may lower to an x87 FPU stack pop. Optimizations should be more cautious
when handling this node than a normal CopyFromReg to avoid removing a
required FPU stack pop.

```
ptr = alloca
ch0 = call modf ptr
t0, ch1 = pop_from_x87_reg, ch0 // t0 unused
t1, ch2 = ldr ptr, ch1
return t1
```

Using this node ensures a required x87 FPU pop is not removed due to the
DAGCombiner.

This is an alternate solution for #127976.
2025-03-03 12:23:28 +00:00
Sergey Kachkov
a55786170d [RISCV][NFC] Add pre-commit test 2025-03-03 13:55:04 +03:00
Akshat Oke
77f44a9642
[CodeGen][NewPM] Port MachineSink to NPM (#115434)
Targets can set the EnableSinkAndFold option in CGPassBuilderOptions for
the NPM pipeline in buildCodeGenPipeline(... &Opts, ...)
2025-03-03 15:49:37 +05:30
Matt Arsenault
49a533a485
AMDGPU: Stop introducing v_accvgpr_write_b32 for reg-to-reg copy (#129059)
This was trying to hack around the intermediate VGPR requirement
to copy to AGPRs on gfx908. We should still use a copy for all
reg-to-reg cases. This should matter less these days, as we
reserve a VGPR to handle it when required (and no end to end tests
need updating).

This was also an obstacle to handling this fold for input registers
which are larger than 32-bits.
2025-03-03 16:22:47 +07:00
Matt Arsenault
7be8b78f82
AMDGPU: Add mir test for agpr constant reg_sequence handling (#129058) 2025-03-03 16:19:02 +07:00
Akshat Oke
69c8312c0a
[CodeGen][NewPM] Port MachineCycleInfo to NPM (#114745) 2025-03-03 11:26:17 +05:30
Akshat Oke
aa1fe57b19
[RegAlloc][NewPM] Plug Greedy RA in codegen pipeline (#120557)
Use `-passes="regallocgreedy<[all|sgpr|wwm|vgpr]>` to insert the greedy
RA with a filter and `-regalloc-npm=<type>` to control which RA to use
in existing pipeline.
2025-03-03 11:06:15 +05:30
Jim Lin
e42ab4c54e
[RISCV] Handle zvbb instructions in getVectorLowDemandedScalarBits. (#129011) 2025-03-03 11:27:34 +08:00
tangaac
cb7030dbe7
[LoongArch] use TypeWidenVector for most illegal vector types (#126456)
`TypeWidenVector` makes an illegal vector a larger one
e.g. in lsx
v2i32 -> v4i32
v4i16 -> v8i16
With this we can make good use of `vilvh`, `vilvl` instructions in
vector `sext`, `zext` in later pr.

Previous action is `TypePromoteInteger`, which replaces integer with a
larger one
e.g. in lsx
v2i32 -> v2i64
v4i16 -> v4i32
2025-03-03 10:26:11 +08:00
Pedro Lobo
3c80d9b8dd
[Instruction] Set metadata to poison on deletion (#129449)
Represent extant metadata uses of a deleted instruction with `poison`
instead of `undef`.
2025-03-03 07:17:01 +07:00
Billy Laws
8eba022886
[CodeGen][ARM64EC] Mangle EH personality handler names (#121652) 2025-03-02 13:35:51 +01:00
Sebastian Schaller
cc5d8a4b2f
[AArch64] fall back to SDAG for instructions with emulated TLS variables (#129215)
Fixes #126200 
At the moment, GlobalISel is missing an implementation for emulated TLS
variables.
I fixed the issue by falling back to SDAG in this case, as I currently
don't have the knowledge to implement it myself.

Co-authored-by: Schaller, Sebastian <sebastian.schaller@dentsplysirona.com>
2025-03-01 15:47:25 +00:00
Yingwei Zheng
2709366f75
[DAGCombiner] Don't ignore N2's undef elements in foldVSelectOfConstants (#129272)
Since N2 will be reused in the fold, we cannot skip N2's undef elements
if the corresponding element in N1 is well-defined.
For example:
```
t2: v4i32 = BUILD_VECTOR Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>
t24: v4i32 = BUILD_VECTOR undef:i32, undef:i32, Constant:i32<1>, undef:i32
t11: v4i32 = vselect t8, t2, t10
```
Before this patch, we fold t11 into:
```
t26: v4i32 = sign_extend t8
t27: v4i32 = add t26, t24
```
The last element of t27 is incorrect.

Closes https://github.com/llvm/llvm-project/issues/129181.
2025-03-01 20:21:28 +08:00
João Gouveia
0751418024
[X86] Extend combinei64TruncSrlAdd to handle patterns with or and xor (#128435)
As discussed in #126448, the fold implemented by #126448 / #128353 can
be extended to operations other than `add`. This patch extends the fold
performed by `combinei64TruncSrlAdd` to include `or` and `xor` (proof:
https://alive2.llvm.org/ce/z/AXuaQu). There's no need to extend it to
`sub` and `and`, as similar folds are already being performed for those
operations.

CC: @phoebewang @RKSimon
2025-03-01 18:05:49 +08:00
Alex MacLean
0065343159
[NVPTX] Improve device function byval parameter lowering (#129188)
PTX supports 2 methods of accessing device function parameters:

- "simple" case: If a parameters is only loaded, and all loads can
address the parameter via a constant offset, then the parameter may be
loaded via the ".param" address space. This case is not possible if the
parameters is stored to or has it's address taken. This method is
preferable when possible.

- "move param" case: For more complex cases the address of the param may
be placed in a register via a "mov" instruction. This mov also
implicitly moves the param to the ".local" address space and allows for
it to be written to. This essentially defers the responsibilty of the
byval copy to the PTX calling convention.

The handling of these cases in the NVPTX backend for byval pointers has
some major issues. We currently attempt to determine if a copy is
necessary in NVPTXLowerArgs and either explicitly make an additional
copy in the IR, or insert "addrspacecast" to move the param to the param
address space. Unfortunately the criteria for determining which case is
possible are not correct, leading to miscompilations
(https://godbolt.org/z/Gq1fP7a3G). Further, the criteria for the
"simple" case aren't enforceable in LLVM IR across other transformations
and instruction selection, making deciding between the 2 cases in
NVPTXLowerArgs brittle and buggy.

This patch aims to fix these issues and improve address space related
optimization. In NVPTXLowerArgs, we conservatively assume that all
parameters will use the "move param" case and the local address space.
Responsibility for switching to the "simple" case is given to a new
MachineIR pass, NVPTXForwardParams, which runs once it has become clear
whether or not this is possible. This ensures that the correct address
space is known for the "move param" case allowing for optimization,
while still using the "simple" case where ever possible.
2025-02-28 14:15:25 -08:00
Alex MacLean
c13be8f0d5
[NVPTX] Add some basic folds for ADDRSPACECAST (#129157) 2025-02-28 12:31:55 -08:00
Vyacheslav Levytskyy
494f67282f
[SPIR-V] Prevent type change of GEP results in type inference (#129250)
The following reproducer demonstrates the issue with invalid definition
of GEP results during type inference

```
define spir_kernel void @foo(i1 %fl, i64 %idx, ptr addrspace(1) %dest, ptr addrspace(3) %src) {
  %p1 = getelementptr inbounds i8, ptr addrspace(1) %dest, i64 %idx
  %res = tail call spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyjPU3AS1iPU3AS3Kimm9ocl_event(i32 2, ptr addrspace(1) %p1, ptr addrspace(3) %src, i64 128, i64 1, target("spirv.Event") zeroinitializer)
  ret void
}

declare dso_local spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyjPU3AS1iPU3AS3Kimm9ocl_event(i32, ptr addrspace(1), ptr addrspace(3), i64, i64, target("spirv.Event"))
```

Here `OpGroupAsyncCopy` expects i32* arguments and type inference fails
to set a correct type of the GEP result `%p1`, because it is an argument
of `OpGroupAsyncCopy`.

This PR fixes the issue by preventing type change of GEP results in type
inference.
2025-02-28 20:55:14 +01:00
David Green
a1fdcfa1ea [AArch64] Protect against scalar types in isNVCastToHalfWidthElements.
Fixes #129227
2025-02-28 19:39:11 +00:00
Johannes Doerfert
992b451f08
[Utils][UnifyLoopExits] Avoid costly updates if nothing changed (#129179)
If the ControlFlowHub did not perform any change to the control flow,
there is no need to repair SSA, update the loop structure, and verify a
bunch of things. This is not completely NFC though, repairSSA introduced
PHI nodes with a single entry that are now missing.

My code went from 400+ seconds to 1 second, since no loop required the
exits to be unified, but there were many "complex" loops.
2025-02-28 10:14:31 -08:00
RolandF77
a73e591f33
[PowerPC] custom lower v1024i1 load/store (#126969)
Support moving PPC dense math register values to and from storage with
LLVM IR load/store.
2025-02-28 10:25:07 -05:00
Jim Lin
94f6b6d538
[SelectionDAG][RISCV] Promote VECREDUCE_{FMAX,FMIN,FMAXIMUM,FMINIMUM} (#128800)
This patch also adds the tests for VP_REDUCE_{FMAX,FMIN,FMAXIMUM,FMINIMUM}, which have been supported for a while.
2025-02-28 23:13:30 +08:00
Brox Chen
db973cea7c
[AMDGPU][True16][CodeGen] True16 Add OpSel when optimizing exec mask (#128928)
True16 Add OpSel when optimizing exec mask

True16 VOPCX have the opsel argument. Add it when we create these
instructions in SIOptimizeExecMasking.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-02-28 09:41:05 -05:00
Jonas Paulsson
c298f71ea6
[SystemZ] Fix regstate of SELRMux operand in selectSLRMux(). (#128555)
It seems that there can be other cases with this that also can lead to
wrong code (discovered with csmith). This time it involved not the kill
flag but the undef flag.

Use the intersection of the flags from both MachineOperand:s instead
of the RegState from just one of them.
2025-02-28 15:03:04 +01:00
Nikita Popov
5d89123a39 [X86] Add tests for sspstrong with phi nodes (NFC) 2025-02-28 14:56:41 +01:00
Paul Walker
1aea0241f1
[LLVM][SVE] Add isel for bfloat based select operations. (#128881)
Patch also adds missing tests for unpacked half and float types.
2025-02-28 10:56:09 +00:00
Matt Arsenault
6a46cf4dc6
AMDGPU/GlobalISel: Restore disabled test (#129001) 2025-02-28 17:24:28 +07:00
Alex MacLean
85f8bd111f
[NVPTX] Combine addressing-mode variants of ld, st, wmma (#129102)
This change fold together the _ari, _ari64, and _asi variants of these
instructions into a single instruction capable of holding any address.
This allows for the removal of a lot of unnecessary code and moves us
towards a standard way of representing an address in NVPTX.
2025-02-27 16:05:30 -08:00
Krzysztof Drewniak
f8cc509b69
Reapply "[AMDGPU] Handle memcpy()-like ops in LowerBufferFatPointers (#126621)" (#129078)
This reverts commit 1559a65efaf327f9c72e14d4bb1834f076e7fc20.

Fixed test (I suspect broken by unrelated change in the merge)
2025-02-27 11:26:13 -06:00
Nikita Popov
b2aba39001 [StackProtector] Handle atomicrmw xchg in HasAddressTaken heuristic
Atomicrmw xchg can directly take a pointer operand, so we should
treat it similarly to store or cmpxchg.

In practice, I believe that all targets that support stack protectors
will convert this to an integer atomicrmw xchg in AtomicExpand, so
there is no issue in practice. We still should handle it correctly
if that doesn't happen.
2025-02-27 17:03:24 +01:00
Nikita Popov
7defbf987a [StackProtector] Add test for atomicrmw xchg (NFC)
This is an opt based test because usually AtomicExpand will
convert it to an integer atomicrmw first.
2025-02-27 17:03:24 +01:00
Brox Chen
8635b8eb51
[AMDGPU][True16][MC] true16 for v_alignbit_b32 (#119409)
Support true16 format for v_alignbit_b32 in MC.

Since we are replacing `v_alignbit_b32` to
`v_alignbit_b32_t16/v_alignbit_b32_fake16` in Post-GFX11, have to update
the CodeGen pattern for `v_alignbit_b32_fake16` to get CodeGen test
passing. There is no pattern modified/created, but just replacing the
`v_alignbit_b32` with fake16 format.

Some of the true16 CodeGen test are impacted since `v_alignbit_b32`
selection are removed in Post-GFX11 while `v_alignbit_b32_t16` are not
yet supported. The CodeGen patch for `v_alignbit_b32_t16` will be done
in the following patch.
2025-02-27 11:00:01 -05:00
Simon Pilgrim
61aab82135
[X86] getFauxShuffleMask - insert_subvector - skip undemanded subvectors (#129042)
If the shuffle combine doesn't require the subvector of a insert_subvector node, we can just combine the base vector directly.
2025-02-27 15:25:02 +00:00
Viktoria Maximova
c19a303867
[SPIR-V] Support 2 more instructions from SPV_INTEL_long_composites (#128190)
This change adds support for `OpSpecConstantCompositeContinuedINTEL` and
`OpCompositeConstructContinuedINTEL` instructions and continues work
done in #126545.

Specification:

https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_long_composites.html
2025-02-27 15:46:23 +01:00
Matt Arsenault
a88f4f1962 AMDGPU: Fix a test typo reading a partially undefined vector
This avoids a surprising test diff in a future commit that
happened to change the read registers to something else. Also
migrate from undef to poison.
2025-02-27 20:17:20 +07:00