58420 Commits

Author SHA1 Message Date
Nathan Gauër
c1940cd0de
[SPIR-V] Add store legalization for ptrcast (#135369)
This commits adds handling for spv.ptrcast result being used in a store
instruction, modifying the store to operate on the source type.
2025-04-22 11:58:55 +02:00
Nathan Gauër
d8b0e616b7
[SPIR-V] Fix OpVectorShuffle operands on load (#135954)
The generated OpVectorShuffle was wrong, as the indices we pass are not
to select the vector to sample from, but the position in the vector.
2025-04-22 11:07:02 +02:00
Frederik Harwath
f541a3aad8
[AMDGPU] SIInstrInfo: Fix resultDependsOnExec for VOPC instructions (#134629)
SIInstrInfo::resultDependsOnExec assumes that operand 0 of a comparison
is always the destination of the instruction. This is not true for
instructions in VOPC form where it is "src0". This led to a crash in
machine-cse.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-04-22 10:17:35 +02:00
Liao Chunyu
9e26c797ae
[RISCV] Add smcntrpmf extension (#136556)
spec: https://github.com/riscvarchive/riscv-smcntrpmf
2025-04-22 12:34:39 +08:00
Jim Lin
ddb8870a5f [RISCV] Remove the FIXME for using sraiw+and. NFC.
https://github.com/llvm/llvm-project/pull/102034 has implemented it.
2025-04-22 09:13:11 +08:00
Jim Lin
698cd48db9
[RISCV] Fix Lsb > Msb case in (sra (sext_inreg X, _), C) for th.ext (#136287)
According the
[spec](https://github.com/XUANTIE-RV/thead-extension-spec/releases/tag/2.3.0),
the operation of `th.ext rd, rs1, msb, lsb` is

  reg[rd] := sign_extend(reg[rs1][msb:lsb])

The spec doesn't specify if lsb is greater than msb.

I don't think lsb can be greater than msb. So that If the shift-right
amount is greater than msb, we can set lsb equal to msb to extract the
bit rs1[msb] and sign-extend it.
2025-04-22 09:17:37 +08:00
Alex MacLean
56910a8b1b
[NVPTX] Improve kernel byval parameter lowering (#136008)
This change introduces a new pattern for lowering kernel byval
parameters in `NVPTXLowerArgs`. Each byval argument is wrapped in a call
to a new intrinsic, `@llvm.nvvm.internal.addrspace.wrap`. This intrinsic
explicitly equates to no instructions and is removed during operation
legalization in SDAG. However, it allows us to change the addrspace of
the arguments to 101 to reflect the fact that they will occupy this
space when lowered by `LowerFormalArgs` in `NVPTXISelLowering`.
Optionally, if a generic pointer to a param is needed, a standard
`addrspacecast` is used. This approach offers several advantages:

- Exposes addrspace optimizations: By using a standard `addrspacecast`
back to generic space we allow InferAS to optimize this instruction,
potentially sinking it through control flow or in other ways unsupported
by `NVPTXLowerArgs`. This is demonstrated in several existing tests.

- Clearer, more consistent semantics: Previously an `addrspacecast` from
generic to param space was implicitly a no-op. This is problematic
because it's not reciprocal with the inverse cast, violating LLVM
semantics. Further it is very confusing given the existence of
`cvta.to.param`. After this change the cast equates to this instruction.

- Allow for the removal of all nvvm.ptr.* intrinsics: In a follow-up
change the nvvm.ptr.gen.to.param and nvvm.ptr.param.to.gen intrinsics
may be removed.
2025-04-21 15:55:06 -07:00
Maryam Moghadas
c40d3a411c
[PowerPC] Add dense math bfloat16 floating-point outer-product accumulate to DMR instructions (#133109)
This patch adds the following Dense Math Facility bfloat16
floating-point calculation instructions: dmxvbf16gerx2,
dmxvbf16gerx2pp,dmxvbf16gerx2pn, dmxvbf16gerx2np, dmxvbf16gerx2nn,
pmdmxvbf16gerx2, pmdmxvbf16gerx2pp, pmdmxvbf16gerx2pn,
pmdmxvbf16gerx2np, pmdmxvbf16gerx2nn, along with their corresponding
intrinsics and tests.
2025-04-21 18:39:44 -04:00
Princeton Ferro
92c0b425ad
[NVPTX] add test case for vector reduction intrinsics (#136381)
Test how these intrinsics are handled by the NVPTX backend. Currently, these intrinsics are lowered to sequential reductions by the ExpandReductions pass.
2025-04-21 15:21:39 -07:00
Changpeng Fang
a945f5917c
AMDGPU: Add global-isel checks and rename fptrunc.v2f16.fpmath.ll (#136609)
Also remove the checks with -enable-unsafe-fp-math (already in fptrunc.f16.ll)
2025-04-21 14:38:02 -07:00
Shilei Tian
9968ba8652 Revert "[AMDGPU] Insert readfirstlane in the function returns in sgpr. (#135326)"
This reverts commit 76ced7fa782f0d7db9efea871fa6de74706dd9cc since it breaks a
lot of bots.
2025-04-21 14:31:10 -04:00
Jim Lin
b95ec24ff0
[SDAG] Handle insert_subvector in isKnownNeverNaN (#131989)
Propagate nnan across insert_subvector.
2025-04-22 01:19:56 +08:00
Pankaj Dwivedi
76ced7fa78
[AMDGPU] Insert readfirstlane in the function returns in sgpr. (#135326)
insert `readfirstlane` in the function returns in sgpr.
2025-04-21 21:57:16 +05:30
Nico Weber
e18a77cfbe Revert "[SelectionDAG] Folding ZERO-EXTEND/SIGN_EXTEND poison to Poison value in getNode (#122741)"
This reverts commit f12078e72601e7c03e5d66afab034313caf8f791.

Breaks `check-llvm`, see comments on https://github.com/llvm/llvm-project/pull/122741
2025-04-21 10:51:03 -04:00
Farzon Lotfi
111af76bd7
[DirectX] add Function name to DiagnosticInfoUnsupported Msg in DXILOpLowering (#136234)
fixes #135654

In #128613 we added safe guards to prevent the lowering of just any
intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do
this.

What we found was when using `opt` the diagnostic print function was
called but when using clang the diagnostic message was used.

Printing message in the clang version means we miss valuable debugging
information like function name and function type when LLVMContext was
only needed to call `getBestLocationFromDebugLoc`.

There are a few potential fixes

1. Write a custom DiagnosticInfoUnsupported so we can change the Message
just for DirectX. Too heavy handed so rejected.

2. Add the function name to the Message in DirectX code. Very simple one
line change. Downside is when using opt you see the function name twice.
But makes the clang-dxc bugs more actionable.

3. change CodeGenAction.cpp to always use the print function and not the
message directly. Downside is a bunch of innacurate information shows up
in the message if you don't specify `-debug-info-kind=standalone`.

4. add some book keeping to know which function called the intrinsic
keep a map of these so we can pass the calling function to
`DiagnosticInfoUnsupported` instead of the intrinsic. This would only be
useful if we had debug info so we could distinguish different uses of
the intrinsic by line\col number. We would also need to change from
iterating on every function to doing something like a LazyCallGraph
which is a nonstarter.

5. pick a different means of doing a Diagnostic error, because other
uses of `DiagnosticInfoUnsupported` error when we are in the body of a
function not when we see one being used like in the intrinsic case.

This PR went with a combo of option 2 & 5. Its low code change that also
only impacts the DirectX backend.
2025-04-21 10:26:27 -04:00
zhijian lin
f12078e726
[SelectionDAG] Folding ZERO-EXTEND/SIGN_EXTEND poison to Poison value in getNode (#122741)
The PR will fix the issue
https://github.com/llvm/llvm-project/issues/122728

This patch addresses the signed/zero extension of poison by using a
poison value of the extended type instead of a constant zero of the
extended type.
2025-04-21 10:02:21 -04:00
Simon Pilgrim
788b50a438 [X86] Add test coverage for #136368 2025-04-21 13:24:20 +01:00
tangaac
4853bf0956
[LoongArch] Lower build_vector to broadcast load if possible (#135896) 2025-04-21 16:04:28 +08:00
Ryotaro Kasuga
b6820c35c5
[MachinePipeliner] Remove UB from tests (NFC) (#123169)
This patch removes UB from some tests for MachinePipeliner. This patch
fixes following cases.

- Branching on an `undef` value.
- Using `undef`/`null` as a pointer operand of a load/store.

There are other tests of pipeliner that contain the same UB, but for
now, this patch fixes particularly unstable cases when I developed
pipeliner.
2025-04-21 16:12:25 +09:00
Jim Lin
f024aab844 [RISCV] Remove the TODO that lbu and lhu should be selected to avoid the unnecessary masking. NFC.
RISCVTargetLowering::isZExtFree has been implemented in
15e894baee.
2025-04-21 11:02:04 +08:00
Phoebe Wang
ddee2d8559
[X86][APX] Combine (X86Sub 0, AND(X, Y)) to (X86And X, Y) for CLOAD/CSTORE (#136429)
https://godbolt.org/z/TsWochrbf
2025-04-21 10:07:45 +08:00
Evgenii Kudriashov
e8245d5324
[X86][GlobalISel] Support addr matching in SDAG patterns (#130445)
addr matching was the only gatekeeper for starting selecting G_LOAD
and G_STORE using SDAG patterns.

* Introduce a complex renderer gi_addr for addr. In this patch only
the existing functionality has been implemented. The renderer's name is
the same as in SDAG: selectAddr. Apparently the type of
GIComplexOperandMatcher doesn't matter as RISCV also uses s32 for
both 64 and 32 bit pointers.
* X86SelectAddress now is used for both: pattern matching and manual
selection. As a result it accumulates all the code that previously was
distributed among different selection functions.
* Replace getLoadStoreOp with getPtrLoadStoreOp in Load/Store
selector as GlobalISel matcher or emitter can't map the pointer type
into i32/i64 types used in SDAG patterns for pointers. So the load and
store selection of pointers is still manual. getLoadStoreOp is still
present because it is used in G_FCONSTANT lowering that requires extra
efforts to select it using SDAG patterns.
* Since truncating stores are not supported, we custom legalize them by
matching types of store and MMO.
* Introduce a constant pool flag in X86AddressMode because otherwise
we need to introduce a GlobalISel copy for X86ISelAddressMode.
* Also please notice in the tests that GlobalISel prefers to fold memory
operands immediately comparing to SDAG. The reason is that GlobalISel
doesn't have target hooks in GIM_CheckIsSafeToFold. Or maybe another
check on profitability is required along with safety check that is
currently not present.
2025-04-19 22:59:18 +02:00
Evgenii Kudriashov
db97d56c97
[X86][APX] Handle AND_NF instruction for compare peephole (#136233) 2025-04-19 01:48:40 +02:00
Alex MacLean
aed4ecc456
[DAGCombiner] Fold and/or of NaN SETCC - tests follow up (#136168)
Follow up to #135645 to address test cleanup review.
2025-04-18 14:32:20 -07:00
Kaitlin Peng
a79e257ff1
[HLSL] XFAIL smoothstep.ll and SV_GroupIndex.ll SPIR-V backend tests (#136343)
When SPIRV-Tools is enabled, tests that specify the target environment
`vulkan1.3` in the validation step fail. This is because SPIRV-Tools
seems to have [grown some capability checks for vulkan
1.3](7e41c7130f).
The failing tests are:
- `CodeGen/SPIRV/hlsl-intrinsics/SV_GroupIndex.ll`
- `CodeGen/SPIRV/hlsl-intrinsics/smoothstep.ll`

For now, the fix is to XFAIL these tests to unblock the pipeline.

Issue #136344 tracks the long-term solution for this.
2025-04-18 14:22:52 -07:00
Matt Arsenault
a3f8836ae8 AMDGPU: Regenerate baseline checks
Clean up now unnecessary second check prefix.
2025-04-18 22:07:47 +02:00
Philip Reames
722d5890cc
[RISCV] Lower e64 vector_deinterleave via ri.vunzip2{a,b} if available (#136321)
If XRivosVizip is available, the ri.vunzip2a and ri.vunzip2b can be used
to the concatenation and register deinterleave shuffle. This patch only
effects the intrinsic lowering (and thus scalable vectors because the
fixed vectors go through shuffle lowering).

Note that this patch is restricted to e64 for staging purposes only. e64
is obviously profitable (i.e. we remove a vcompress). At e32 and below,
our alternative is a vnsrl instead, and we need a bit more complexity
around lowering with fractional LMUL before the ri.vunzip2a/b versions
becomes always profitable. I'll post the followup change once this
lands.
2025-04-18 10:40:15 -07:00
Andrei Safronov
5ad32fa697
[Xtensa] Implement Xtensa Mul and Div Options. (#132157)
Implement Xtensa Mul16, Mul32, Mul32High and Div32 Options. Also fix callw test.
2025-04-18 20:22:03 +03:00
Paul Kirth
b3d2dc321c
[RISCV] Fix assertion failure when using -fstack-clash-protection (#135248)
We can't assume MBBI is still pointing at MBB if we've already expanded
a probe. We need to re-query the MBB from MBBI. Fixes #135206

Co-authored-by: Craig Topper <craig.topper@sifive.com>
2025-04-18 09:12:52 -07:00
Matt Arsenault
9bdd9dc895
AMDGPU: Mark workitem ID intrinsics with range attribute (#136196)
This avoids the need to have special handling at every use site.
Unfortunately this means we unnecessarily emit AssertZext in the DAG
(where we already directly understand the range of the intrinsic), andt
we regress in undefined cases as we don't fold out asserts on undef.
2025-04-18 12:27:38 +02:00
Akshat Oke
31ddaef8d1
[CodeGen][NPM] Port UnreachableMachineBlockElim to NPM (#136127) 2025-04-18 15:06:30 +05:30
Simon Pilgrim
64ffecfc43
[DAG] isKnownNeverNaN - add DemandedElts element mask to isKnownNeverNaN calls (#135952)
Matches what we've done for computeKnownBits etc. to improve vector handling
2025-04-18 09:24:02 +01:00
Shoreshen
a3f38f27cd
Revert "[AMDGPU] Implement vop3p complex pattern optmization for gisel" (#136249)
Reverts llvm/llvm-project#130234
2025-04-17 23:45:30 -04:00
tangaac
594bfadbd6
[LoongArch] Pre-commit for broadcast load (#136070) 2025-04-18 11:17:17 +08:00
Shoreshen
a04580f71b
[AMDGPU] Implement vop3p complex pattern optmization for gisel (#130234)
Seeking opportunities to optimize VOP3P instructions by altering opsel,
opsel_hi, neg, neg_hi bits

Tests differences:
1. fix op_sel_hi bit for inline constant:
   1. `CodeGen/AMDGPU/packed-fp32.ll`
2. use neg bit to remove xor with 0x80008000
   1. `CodeGen/AMDGPU/strict_fsub.f16.ll`
   2. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.fdot2.ll`
   3. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot4.ll`
   4. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot8.ll`
   5. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot2.ll`
   6. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot4.ll`
   7. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot8.ll`
3. Remove xor 0x80008000, and use opsel, opsel_hi to remove alignbit
   1. `CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot2.ll`
2025-04-18 10:56:20 +08:00
Philip Reames
50f9b34b53
[RISCV] Prefer vmv.s.x for build_vector a, undef, ..., undef (#136164)
If we have a build vector which could be either a splat or a scalar
insert, prefer the scalar insert. At high LMUL, this reduces vector
register pressure (locally, the use will likely still be aligned), and
the amount of work performed for the splat.
2025-04-17 19:51:35 -07:00
Philip Reames
b6dff56600 [RISCV] Add vizip check lines to (de)interleave tests
Reducing churn in advance of a change which makes better use of these.
Note that for very short fixed length shuffles, we already use the
vizip family instructions - but mostly in the form of zipeven/zipodd.
2025-04-17 19:50:43 -07:00
Philip Reames
62b9cbd878 [RISCV] Simplify check lines in vector-deinterleave.ll [nfc]
RV32 and RV64 are unused.  Output with zvfh vs zvfhmin are the same,
so just use the weaker predicate.
2025-04-17 16:34:13 -07:00
Alex MacLean
f0f55453a2
[NVPTX] Address warning and typo in fp128 support (#136207) 2025-04-17 15:45:09 -07:00
Alex MacLean
3001387219
[NVPTX] Basic support for fp128 as a storage type (#136006)
While fp128 operations are not natively supported in hardware, emulation
for them is supported by nvcc. This change adds basic support for
fp128 as a storage type allowing for lowering of IR containing these
types.

Fixes: https://github.com/llvm/llvm-project/issues/95471
2025-04-17 13:19:48 -07:00
Changpeng Fang
8b46b98b91
AMDGPU: Fix the double rounding issue in v2f64 -> v2f16 conversion (#135659)
On targets that support v_cvt_pk_f16_f32 instruction, if we make v2f64
-> v2f16 Legal, we will generate the following sequence of instructions:
  v_cvt_f32_f64_e32 v1, s[6:7]
  v_cvt_f32_f64_e32 v2, s[4:5]
  v_cvt_pk_f16_f32 v1, v2, v1
It possibly returns imprecise results due to double rounding. This patch
fixes the issue by not setting the conversion Legal. While we may still
expect the above sequence of code when unsafe fpmath is set, I hope
https://github.com/llvm/llvm-project/pull/134738 can address that
performance concern.

Fixes: SWDEV-523856
2025-04-17 11:15:49 -07:00
Philip Reames
7866fc2bd9
[RISCV] Rewrite vrgather.vx undef, (vmv.s.x), 0, v0 as vmv.v.x (#136010)
This extends the DAG combine introduced in 336b2909 to handle the case
where the prior value is defined by a vmv.s.x instead of a vmv.v.x. If
the vrgather splats the single source element, and has no passthru we
can replace it with a vmv.v.x - which will in turn usually get folded
into a vmerge if a select follows.
2025-04-17 10:06:43 -07:00
Koakuma
2ef0104862
[SPARC] Use native bitcast instructions when we have VIS3
Reviewers: brad0, s-barannikov, rorth

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/135716
2025-04-17 23:39:46 +07:00
Koakuma
8210ca0198
[SPARC] Use lzcnt to implement CTLZ when we have VIS3
Reviewers: s-barannikov, brad0, rorth

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/135715
2025-04-17 23:37:00 +07:00
Farzon Lotfi
168092e2ba
[DirectX] Legalize Freeze instruction (#136043)
fixes #135719

LLVM 3.7 did not have a freeze instruction
Further this instruction is really only used as syntactic sugar
in LLVM's optimizer passes to not aggressively optimize things that
could be undef or poison ie x*2 to x+x.
Most backends treat it as a no-op so we will do the same
by removing it and replacing its uses with its input.
2025-04-17 09:02:05 -07:00
Alex MacLean
7daa5010ab
[NVPTX] Cleanup and document nvvm.fabs intrinsics, adding f16 support (#135644)
This change unifies the NVVM intrinsics for floating point absolute
value into two new overloaded intrinsics "llvm.nvvm.fabs.*" and
"llvm.nvvm.fabs.ftz.*". Documentation has been added specifying the
semantics of these intrinsics to clarify how they differ from
"llvm.fabs.*". In addition, support for these new intrinsics is
extended to cover the f16 variants.
2025-04-17 07:37:24 -07:00
zhijian lin
3dfdb4dad5
[SelectionDAG] Propagate poison in getNode with two operands if the input is poison. (#135387)
Propagation to poison in function `SDValue
SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,SDValue
N1, SDValue N2, const SDNodeFlags Flags) ` if one of the input is
poison.
 
 The patch also revert the test cases
 llvm/test/CodeGen/X86/pr119158.ll
 llvm/test/CodeGen/X86/half.ll
 
which are mentioned in
https://github.com/llvm/llvm-project/pull/125883#discussion_r2021390919

---------

Co-authored-by: Amy Kwan <amy.kwan1@ibm.com>
2025-04-17 09:23:14 -04:00
Yingwei Zheng
5a993558c5
[InstSimplify] Fold getelementptr inbounds null, idx -> null (#130742)
Proof: https://alive2.llvm.org/ce/z/5ZkPx-
See also https://github.com/llvm/llvm-project/pull/130734 for the motivation.
2025-04-17 20:44:46 +08:00
Paul Walker
6f91bfcc8a
[LLVM][AArch64ISel] Fix IsLE predicate setting so it does not affect BE codegen. (#135978)
Ensure little endian specific patterns, not just their multi-classes,
are protected by IsLE.
2025-04-17 11:43:10 +01:00
Yingwei Zheng
7e5317139d
[PowerPC] Pre-commit tests for PR130742. NFC. (#135606)
Needed by https://github.com/llvm/llvm-project/pull/130742.
2025-04-17 17:52:49 +08:00