590 Commits

Author SHA1 Message Date
ambergorzynski
9238b0f765
[NFC][SPIRV] New test for untested case in SPIRVEmitIntrinsics (#188950)
[This
case](bc35715696/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (L2815-L2818))
is not covered by any existing test (checked via code coverage and
inserting an `abort`). New test proposed that covers this line, as
demonstrated by test failure when an `abort` is present in that line.
2026-03-27 17:05:42 +00:00
ambergorzynski
294dc1b894
[NFC][SPIRV] Add test for untested line in SPIRVEmitIntrinsics (#188962)
[This
body](73768f88fb/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (L857-L860))
is not covered by any existing test (checked via code coverage and
inserting an abort). New test proposed that covers this line, as
demonstrated by test failure when an abort is present in that line.
2026-03-27 15:55:59 +00:00
Marina Taylor
55322f2d43
[ObjCARC] Run ObjCARCContract before PreISelIntrinsicLowering (#184149)
74e4694 moved ObjCARCContract from running before the codegen pipeline
into addISelPrepare(), which runs after PreISelIntrinsicLowering.

This broke ObjCARCContract's retainRV-to-claimRV optimization because
ObjCARCContract identifies ARC calls via intrinsics, not their lowered
counterparts.

This patch restores the pre-74e4694 ordering by moving ObjCARCContract
to addISelPasses.

The IntrinsicInst.cpp change looks extraneous but is required here:
ObjCARCContract may now rewrite the bundle operand from retainRV to
claimRV. When PreISelIntrinsicLowering then encounters this new
intrinsic use, lowerObjCCall asserts mayLowerToFunctionCall.

Assisted-by: claude

rdar://137997453
2026-03-27 15:37:47 +00:00
Arseniy Obolenskiy
b7b9368738
[SPIR-V] Support for C++ for OpenCL source language (#188791)
- Add CPP_for_OpenCL source language operand
- Handle opencl.cxx.version metadata

Align handling with SPIR-V translator logic and tests presented there
2026-03-27 15:36:27 +01:00
Arseniy Obolenskiy
5145d72a84
[SPIR-V] Emit OpSpecConstantComposite for composites with spec constant operands (#188557)
- The SPIR-V spec requires that OpConstantComposite must not reference
spec constant operands. When a composite contains non-constant
constitued, OpSpecConstantComposite should be emitted instead of
OpConstantComposite
- Avoid creating function pointer types when the
SPV_INTEL_function_pointers extension is unavailable, falling back to i8
as the pointee type
- Re-enable spirv-val validation in tests that previously failed due to
this issue, and un-XFAIL the block_w_struct_return and global_block
transcoding tests

related to #60133
fixes #186756
2026-03-27 11:00:45 +01:00
idubinov
88c5774562
[SPIRV] Add bitreverse expansion for kernel (#186412)
The OpBitReverse is available when Shader or SPV_KHR_bit_instructions
extension is enabled. For targets without these capabilities, introduce
software emulation of G_BITREVERSE based on the parallel bit reversal
algorithm:
https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel

The emulation supports 8/16/32/64-bit scalars and vectors using bitwise
operations (shifts, AND, OR). A helper lambda avoids undefined behavior
when computing masks for 64-bit types.

Tests added for both emulation and native paths across all supported
types.

Assisted-by: Claude Code
2026-03-27 10:55:22 +01:00
Nick Sarnie
09951fd475
Revert "[HLSL][SPIRV] Add support for -g to generate NonSemantic Debug Info" (#188771)
Reverts llvm/llvm-project#187051

Breaks some OpenMP offload tests
2026-03-26 18:58:47 +00:00
Sietze Riemersma
593f82ab9d
[HLSL][DXIL][SPRIV] Added GroupMemoryBarrier() (#185383)
Adds the `GroupMemoryBarrier()` HLSL function to SPIRV and DirectX with
additional tests for the different backends.

When this moves in, will create another PR with this as a template for
the other Barriers:
- `AllMemoryBarrier()` #99076
- `AllMemoryBarrierWithGroupSync()` #99090
- `DeviceMemoryBarrier()` #99105
- `DeviceMemoryBarrierWithGroupSync()` #99106

`Barrier()` does not have support for SPIRV, so I will exclude that from
the next PR.

- [x] Implement GroupMemoryBarrier clang builtin,
- [x] Link GroupMemoryBarrier clang builtin with hlsl_intrinsics.h
- [x] Add sema checks for GroupMemoryBarrier to
CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
- [x] Add codegen for GroupMemoryBarrier to EmitHLSLBuiltinExpr in
CGBuiltin.cpp
- [x] Add codegen tests to
clang/test/CodeGenHLSL/builtins/GroupMemoryBarrier.hlsl
- [x] Add sema tests to
clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrier-errors.hlsl
- [x] Create the int_dx_GroupMemoryBarrier intrinsic in
IntrinsicsDirectX.td
- [x] Create the DXILOpMapping of int_dx_GroupMemoryBarrier to 80 in
DXIL.td
- [x] Create the GroupMemoryBarrier.ll and GroupMemoryBarrier_errors.ll
tests in llvm/test/CodeGen/DirectX/
- [x] Create the int_spv_GroupMemoryBarrier intrinsic in
IntrinsicsSPIRV.td
- [x] In SPIRVInstructionSelector.cpp create the GroupMemoryBarrier
lowering and map it to int_spv_GroupMemoryBarrier in
SPIRVInstructionSelector::selectIntrinsic.
- [x] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/GroupMemoryBarrier.ll

<!-- branch-stack-start -->

<!-- branch-stack-end -->
2026-03-26 13:24:27 -04:00
Arseniy Obolenskiy
038ddb2e15
[SPIR-V] Update tests for opaque pointer migration (#187674)
Enable tests `linked-list.ll`, `pstruct.ll`, and
`extract_insert_value.ll` where additional code changes are not required

related to #60133
2026-03-26 17:08:35 +01:00
joaosaffran
0e2f4d6acf
[HLSL][SPIRV] Fix firstbitset in spirv (#186939)
This patch fixes the logic when lowering firsbithigh and low when
targeting spirv. It adds an aditional check to make sure the second half
is also -1, if it is it returns -1 otherwise returns the resulting sum.

Fix: #143003 and #143171

---------

Co-authored-by: Finn Plummer <mail@inbelic.dev>
2026-03-25 19:35:32 +00:00
Kai
a546c77478
[HLSL][DXIL][SPIRV] QuadReadAcrossY intrinsic support (#187440)
This PR adds QuadReadAcrossY intrinsic support in HLSL with codegen for
both DirectX and SPIRV backends. Resolves
https://github.com/llvm/llvm-project/issues/99176.

- [x] Implement `QuadReadAcrossY` clang builtin,
- [x] Link `QuadReadAcrossY` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `QuadReadAcrossY` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `QuadReadAcrossY` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/QuadReadAcrossY.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/QuadReadAcrossY-errors.hlsl`
- [x] Create the `int_dx_QuadReadAcrossY` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_QuadReadAcrossY` to `123` in
`DXIL.td`
- [x] Create the `QuadReadAcrossY.ll` and `QuadReadAcrossY_errors.ll`
tests in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_QuadReadAcrossY` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In SPIRVInstructionSelector.cpp create the `QuadReadAcrossY`
lowering and map it to `int_spv_QuadReadAcrossY` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadReadAcrossY.ll`
2026-03-25 11:32:35 -07:00
Diego Novillo
85049fc357
[HLSL][SPIRV] Add support for -g to generate NonSemantic Debug Info (#187051)
This adds two related changes to HLSL debug info support in the SPIR-V
backend. It's a first small step towards the plan I described in
https://discourse.llvm.org/t/hlsl-spirv-nsdi-debug-info-support-for-clang-dxc/90149.

## Tag HLSL shaders with `DW_LANG_HLSL` in the front-end

`GetSourceLanguage()` in `clang/lib/CodeGen/CGDebugInfo.cpp` checked
`LO.CPlusPlus` before `LO.HLSL`. Since HLSL is compiled as C++, the HLSL
check was never reached. Shaders compiled with `-g` were tagged with
`DW_LANG_C_plus_plus_14` instead of `DW_LANG_HLSL`. The NSDI pass
already had the correct mapping for `DW_LANG_HLSL` but it was never
triggered.

This fixes #136929 and #136995.

## Make `SPIRVEmitNonSemanticDI` activate automatically when `-g` is
used

`SPIRVPassConfig::addPreEmitPass()` only scheduled
`SPIRVEmitNonSemanticDI` when `--spv-emit-nonsemantic-debug-info` was
set or the target vendor was AMD. Passing `-g` to clang had no effect on
the SPIR-V backend pass.

The pass is now added unconditionally and self-activates by checking for
`llvm.dbg.cu` in the module. When no debug metadata is present it exits
early with no effect. This avoids the need to inspect module metadata at
pass-configuration time, which is not reliably available.

`--spv-emit-nonsemantic-debug-info` is now a deprecated synonym for
`-g`.

The alternative to the unconditional pass approach is to check at
pass-configuration time whether the module was compiled with debug info
(e.g. via `TargetOptions::DebugInfoForProfiling` or a similar flag
forwarded from the driver). I went with the unconditional approach
because it is simpler and the pass is cheap to enter and exit when no
`llvm.dbg.cu` is present.

I'm not sure whether adding a pass unconditionally is acceptable. Does
this sound reasonable, or would it be better to implement the
flag-forwarding approach?

Changes to tests:

- `clang/test/CodeGenHLSL/` (new): verifies that `-g` on an HLSL SPIR-V
target produces `DebugCompilationUnit` with language code 5
(`DW_LANG_HLSL`).
-
`llvm/test/CodeGen/SPIRV/debug-info/hlsl-debug-info-auto-activation.ll`
(new): verifies that a module with `llvm.dbg.cu` and `DW_LANG_HLSL`
produces `DebugCompilationUnit` without
`--spv-emit-nonsemantic-debug-info`.
- Existing `debug-compilation-unit.ll`, `debug-type-basic.ll`,
`debug-type-pointer.ll`: updated to verify NSDI is emitted whenever
debug metadata is present.
- `llc-pipeline.ll`: updated to reflect that `SPIRVEmitNonSemanticDI` is
now always in the pipeline.

---------

Co-authored-by: Eric Christopher <echristo@gmail.com>
2026-03-25 11:17:09 -07:00
ambergorzynski
741eb80152
[SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager (#188285)
Registered SPIRVEmitIntrinsics with the new pass manager as
`spirv-emit-intrinsics`. The motivation for this is to allow it to be run from
`opt` as a standalone pass for testing purposes. A simple pipeline test
is also included to check that the registration works.
2026-03-25 16:39:41 +00:00
Dmitry Sidorov
d2dab9788a
[SPIR-V] Decompose bitcasts involving bool vectors (#187960)
OpTypeBool has no defined bitwidth in SPIR-V, so OpBitcast is invalid
for boolean vector types. Decompose `<N x i1> <-> iN` bitcasts into
element-wise extract/shift/OR and AND/icmp/insert sequences during IR
preprocessing.

Fixes:
https://github.com/kuhar/iree/blob/amdgcn-spirv/spirv-repros/bitcast_crash.ll
and https://github.com/llvm/llvm-project/issues/185815
2026-03-24 23:58:07 +01:00
Alex Duran
de0c366e4b
[llvm][SPIRV] Add pass to lower Ctors/Dtors for SPIRV (#187509)
This PR adds a new SPIRV pass that generates a kernel named
"spirv$device$init" that iterates the pointers in the table pointed by
__init_array_start and __init_array_end and executes them. It also
generates symbols for each constructor with the form
__init_array_object_NAME_PRIORITY.

These symbols will be used by the Level Zero plugin in the liboffload
runtime (with the support introduced by #187510) to generate the
aforementioned table as spirv-link cannot create the table itself.

It also does the same thing for destructors, with the kernel name being
"spirv$device$fini", the table pointers __fini_array_start and
__fini_array_end, and the generated symbols prefix __fini_array_object.

The code was mostly generated by Claude 4.5 and has been reviewed by me
to the best of my ability.
2026-03-24 21:47:09 +00:00
idubinov
e672e88a96
[SPIRV] Fix OpBuildNDRange (#186153)
- Fix buildNDRange according to OpenCL and SPIRV specs.
- Fix tablegen SPIRV builtins for ndrange_* functions: despite of OpenCL
spec, the real call has additional first argument - structure return,
changed min and max num arguments accordingly.
 - Update test, add checks, combined with BuildNDRange_2
2026-03-23 19:11:04 +01:00
Joshua Batista
54a3518fc3
[HLSL] Add WaveActiveBitAnd builtin function (#187149)
This PR adds the WaveActiveBitAnd HLSL function.
Fixes https://github.com/llvm/llvm-project/issues/99166
2026-03-23 10:19:18 -07:00
Arseniy Obolenskiy
97a1a70208
[SPIR-V] Fix SPV_INTEL_long_composites continued instruction handling (#187262) 2026-03-20 17:58:15 +01:00
Alex Voicu
d8104bfc9e
[SPIR-V] Add llvm.spv.named.boolean.spec.constant (#187420)
This adds a SPIR-V intrinsic for associating a name (textual identifier)
to a specialisation constant. The name is encoded in metadata, and is
intended to be used within LLVM / by the SPIR-V BE (e.g. #134016 would
be a direct user), as it is never emitted into the SPIR-V object.
Non-boolean and composite specialisation constants will be handled in
the future, via dedicated intrinsics, if there is interest.
2026-03-20 16:41:42 +00:00
Juan Manuel Martinez Caamaño
bb070ea56b
[SPIRV][NFC] Update SPV_INTEL_function_pointers tests to check spirv-val output (#182549)
https://github.com/KhronosGroup/SPIRV-Tools/pull/6232 added support for
`SPV_INTEL_function_pointers` on `spirv-val`.

This PR updates some relevant tests to run `spirv-val` and document why
some others are failing.
2026-03-20 17:16:36 +01:00
Arseniy Obolenskiy
14de6dafee
[SPIR-V] Support global variable annotations in llvm.global.annotations (#187241)
SPIR-V backend previously only supported function annotations in
llvm.global.annotations and crashed with a fatal error when encountering
global variable entries
2026-03-20 11:19:12 +01:00
Arseniy Obolenskiy
d8a83a1123
[NFC][SPIR-V] Disable tests failed after spirv-val update (#187028)
Issues:
- https://github.com/llvm/llvm-project/issues/186344
- https://github.com/llvm/llvm-project/issues/186756
2026-03-19 16:38:41 +01:00
Juan Manuel Martinez Caamaño
f104b7355c
[NFC][SPIRV] Run spirv-val on tests related to SPV_ALTERA_arbitrary_precision_integers (#187464)
https://github.com/KhronosGroup/SPIRV-Tools/pull/6232 landed support for
this extension in `spirv-val`.

This PR updates some relevant tests to run `spirv-val` on their output.
2026-03-19 12:25:45 +01:00
Viktoria Maximova
eaf04be341
[SPIR-V] Complete SPV_INTEL_16bit_atomics extension support (#184312)
Add missing capabilities to finalize SPV_INTEL_16bit_atomics extension:
- AtomicInt16CompareExchangeINTEL (6260): for i16
load/store/exchange/cmpxchg
- Int16AtomicsINTEL (6261): for i16 arithmetic atomics (add, sub, min,
max, etc.)
- AtomicBFloat16LoadStoreINTEL (6262): for bfloat16 load/store/exchange

This completes the implementation started in 6ef3218.

Specification:
https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_16bit_atomics.asciidoc
2026-03-19 11:34:57 +01:00
Kai
eabcfcee08
[HLSL][DXIL][SPIRV] QuadReadAcrossX intrinsic support (#184360)
This PR adds QuadReadAcrossX intrinsic support in HLSL with codegen for
both DirectX and SPIRV backends. Resolves
https://github.com/llvm/llvm-project/issues/99175.

- [x] Implement QuadReadAcrossX clang builtin
- [x]  Link QuadReadAcrossX clang builtin with hlsl_intrinsics.h
- [x] Add sema checks for QuadReadAcrossX to
CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
- [x] Add codegen for QuadReadAcrossX to EmitHLSLBuiltinExpr in
CGBuiltin.cpp
- [x] Add codegen tests to
clang/test/CodeGenHLSL/builtins/QuadReadAcrossX.hlsl
- [x] Add sema tests to
clang/test/SemaHLSL/BuiltIns/QuadReadAcrossX-errors.hlsl
- [x] Create the int_dx_QuadReadAcrossX intrinsic in
IntrinsicsDirectX.td
- [x] Create the DXILOpMapping of int_dx_QuadReadAcrossX to 123 in
DXIL.td
- [x] Create the QuadReadAcrossX.ll and QuadReadAcrossX_errors.ll tests
in llvm/test/CodeGen/DirectX/
- [x] Create the int_spv_QuadReadAcrossX intrinsic in IntrinsicsSPIRV.td
- [x] In SPIRVInstructionSelector.cpp create the QuadReadAcrossX
lowering and map it to int_spv_QuadReadAcrossX in
SPIRVInstructionSelector::selectIntrinsic.
- [x] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadReadAcrossX.ll
2026-03-18 11:49:34 -07:00
YixingZhang007
db4f8f7af0
[SPIR-V] Add support for arbitrary precision integer constants in instruction printer (#185306)
This PR improves the SPIR-V instruction printer output for integer
constants using `SPV_ALTERA_arbitrary_precision_integers` extension.

Previously, when `OpConstantI` was encoded with multiple 32-bit words
(for integer widths > 64), the inst printer printed the raw per-word
immediates. This was hard to read and did not reflect the actual value
at the declared integer bitwidth.

Now, with the change in this patch, the instruction printer reconstructs
the multi-word literal into a single `APInt`, truncates it to the
bitwidth declared by the corresponding `OpTypeInt`, and prints the
resulting value as one readable integer (including correct negative
values where applicable).

---------

Co-authored-by: yixing.zhang <yixingzh@smtp.igk.intel.com>
2026-03-17 15:42:21 +01:00
Arseniy Obolenskiy
bec0f40ef2
[SPIR-V] Handle spirv.MemoryModel metadata (#186138) 2026-03-17 13:59:07 +01:00
Arseniy Obolenskiy
818efd5c95
[SPIR-V] Handle undef aggregate initializers for global variables (#186785)
Expand undef aggregate global initializers into per-element spv_undef
intrinsics
2026-03-17 13:56:46 +01:00
ambergorzynski
b2442a20a9
[NFC][SPIRV] New test for untested SPIRVInstructionSelector case (#186069)
[This
line](https://github.com/ambergorzynski/llvm-project/blob/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L2454)
is untested by the existing test suite (checked using coverage and
inserting an `abort` at that line).

We propose a new test for the untested logical `eq` case, similarly to
the `neq` case added
[here](e45c8b6555).
2026-03-17 09:24:29 +01:00
joaosaffran
a12b612c0d
[HLSL] Use 0 to represent unbounded resources (#186022)
SPIRV backend uses 0 to represent unbounded arrays. This patch makes
unbounded resources be represented with 0 when binding them, as well as
makes sure the backend uses OpTypeRuntimeArray to represent such cases.
Fix: https://github.com/llvm/llvm-project/issues/183367
2026-03-16 13:36:53 -07:00
Dmitry Sidorov
8fa7660ab8
[SPIR-V] Fix scalarization of 1-element vector (#185529)
Previous patch #180735 didn't handle 1-element vectors nested in
aggregates.
2026-03-16 21:01:57 +01:00
Farzon Lotfi
cf5c808198
[SPIRV][Matrix] Add support for Array Vector memory layout (#186215)
- fixes #179879
- Change is three fold:
1. Look for the Matrix Memory layout.
2. refactor out the common pieces of loadVectorFromArray into a helper
that can be shared with the matrix case.
3. The matrix case needs special indexing so we can do vector geps
instead of scalar geps that would require a 2d loop.
2026-03-16 14:49:58 -04:00
Arseniy Obolenskiy
e8f97d4e3b
[SPIR-V] Fix llvm.spv.gep return type for vector-indexed GEPs (#185931)
The `int_spv_gep` intrinsic was defined with `llvm_anyptr_ty` which
forced it to return a scalar pointer. Change the return type to
`llvm_any_ty` to allow the intrinsic to match the actual result type of
the original GEP, whether scalar or vector
2026-03-16 15:31:14 +01:00
Arseniy Obolenskiy
2708cd9db2
[SPIR-V] Address comments on SPV_INTEL_masked_gather_scatter extension implementation (#186336)
Address comments left after merge of #185418
2026-03-16 11:55:34 +01:00
Alexis Engelke
211279d11c
[CodeGenPrepare][NFC] Get BPI/BFI from pass/analysis manager (#186651)
BranchProbabilityInfo will compute it's own dominator tree and
post-dominator tree if none is specified; avoid this by using the
analysis manager/pass manager to get the analysis, which will reuse the
previously computed DomTree.
2026-03-15 17:41:22 +01:00
Joshua Batista
c7e66a66b1
[HLSL] Add WaveActiveBitXor function (#185776)
This PR adds WaveActiveBitXor function to HLSL, with spirv and DXIL code
generation.
Fixes https://github.com/llvm/llvm-project/issues/99168
2026-03-12 14:42:17 -07:00
ambergorzynski
e45c8b6555
[NFC][SPIRV] New test for untested SPIRV backend case (#185686)
[This
line](https://github.com/ambergorzynski/llvm-project/blob/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L2362)
in the SPIRV backend is uncovered by the existing test suite (checked
using coverage, and by asserting that no tests in the existing test
suite fails if we insert an `abort()` at this line).

We propose a test that covers this line. We demonstrate the test by
inserting an `abort()` at that line in commit
[#e37e88e](e37e88e250).
Running all tests shows that only our proposed test fails in the
presence of the `abort`. We've removed the `abort` ahead of merging.

This is the only test that fails in the presence of the abort (which
includes our new test): `LLVM.CodeGen/SPIRV/instructions/icmp.ll`
2026-03-11 19:19:46 +00:00
Arseniy Obolenskiy
ac2567c9f7
[SPIR-V] Fix crash in SPIRVEmitIntrinsics for llvm.assume with operand bundles (#185840) 2026-03-11 18:50:06 +01:00
joaosaffran
208c70f312
[HLSL][SPIRV] Update reversebits codegen for half types (#184936)
In order to make codegen compatible with DXC and pass spirv validation,
this patch updates the codegen for half types following the same codegen
as DXC.

fix: https://github.com/llvm/llvm-project/issues/183611
2026-03-11 10:18:10 -07:00
Steven Perron
bf67e4d4ad
[HLSL][SPIR-V] Add resource load level intrinsics and SPIR-V backend support (#185707)
Adds the intrinsics resource_load_level intrinic for DXIL and SPIR-V. It
will be used to load a value from an specific location in the image at
the given mip level. It will be used to implement the Texture Load and
mips[][] methods.

Assisted-by: Gemini
2026-03-11 16:59:07 +00:00
Simeon David Schaub
b3f56eb490
[SPIRV] fix alloca -> OpVariable lowering (#164175)
fixes #163777

Test was written with help from Copilot

---------

Co-authored-by: Juan Manuel Martinez Caamaño <jmartinezcaamao@gmail.com>
2026-03-11 15:16:22 +01:00
Dmitry Sidorov
18cb220146
[SPIR-V] Fix lowering of declarations with hidden visibility (#185029)
They should be translated to SPIR-V and have Import linkage (unless they
are Interface variables).

Also add a test for protected visibility, just to make sure, that we are
aligned it its translation.
2026-03-11 14:39:32 +01:00
Arseniy Obolenskiy
d8f71b1638
[SPIR-V] Add support for SPV_INTEL_masked_gather_scatter extension (#185418)
Fixes the first bullet in #184638 

Corresponding patch to add support for vector operands in
OpConvertPtrToU/OpConvertUToPtr operations in spirv-val:
https://github.com/KhronosGroup/SPIRV-Tools/pull/6575

SPIR-V extension reference used:
278044a51f/extensions/INTEL/SPV_INTEL_masked_gather_scatter.asciidoc
2026-03-11 13:14:36 +01:00
Juan Manuel Martinez Caamaño
52ea06f884
[SPIRV] Add tests documenting incorrect lowering of load/store atomic (#185628)
This patch only adds the tests documenting the broken behavior, but does
not fix them.
2026-03-11 09:40:10 +01:00
Sietze Riemersma
8d0c686c55
[HLSL][DXIL][SPIRV] Added WaveActiveBitOr HLSL intrinsic (#165156)
Adds the WaveActiveBitOr intrinsic from issue #99167. This intrinsic
required a bit more work than the last intrinsics that I have done.

There are some peculiarities, which I verified with dxcompiler:
- WaveActiveBitOr only works on uint and uint64_t, no other types are
allowed
- There is no 16 bit version of WaveActiveBitOr

Followed the checklist:
- [x] Implement WaveActiveBitOr clang builtin,
- [x] Link WaveActiveBitOr clang builtin with hlsl_intrinsics.h
- [x] Add sema checks for WaveActiveBitOr to
CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
- [x] Add codegen for WaveActiveBitOr to EmitHLSLBuiltinExpr in
CGBuiltin.cpp
- [x] Add codegen tests to
clang/test/CodeGenHLSL/builtins/WaveActiveBitOr.hlsl
- [x] Add sema tests to
clang/test/SemaHLSL/BuiltIns/WaveActiveBitOr-errors.hlsl
- [x] Create the int_dx_WaveActiveBitOr intrinsic in
IntrinsicsDirectX.td
- [x] Create the DXILOpMapping of int_dx_WaveActiveBitOr to 120 in
DXIL.td
- [x] Create the WaveActiveBitOr.ll and WaveActiveBitOr_errors.ll tests
in llvm/test/CodeGen/DirectX/
- [x] Create the int_spv_WaveActiveBitOr intrinsic in IntrinsicsSPIRV.td
- [x] In SPIRVInstructionSelector.cpp create the WaveActiveBitOr
lowering and map it to int_spv_WaveActiveBitOr in
SPIRVInstructionSelector::selectIntrinsic.
- [x] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveBitOr.ll

offload test: https://github.com/llvm/offload-test-suite/pull/487
2026-03-10 18:30:37 -04:00
Diego Novillo
79c9dadc0f
[SPIR-V] Add lowering for G_FPOWI (#185454)
This fixes an assertion I was hitting in the fragment density map sample
in Vulkan Samples. In starfield.frag.hlsl, we have

float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0);

The optimizer recognizes 16.0 as a whole number and converts the call to
`llvm.powi`. The backend goes on to fail with:

fatal error: error in backend: cannot select: %46:fid(s64) = nnan ninf
nsz arcp afn reassoc G_FPOWI %44:fid, %45:iid(s64) (in function:
_Z9starFieldDv3_f)

On Vulkan, there is no integer-exponent for pow. This patch lowers it by
converting the exponent to float and calling GLSL.std.450's Pow.

---------

Co-authored-by: Steven Perron <stevenperron@google.com>
2026-03-10 15:34:36 -04:00
Dmitry Sidorov
19a5a3536e
[SPIR-V] Add overload of getConstraintType for inline asm lowering (#185422)
Without the overload constrain lowering would go with a default path
which would later result in a crash in case if for example AMDGPU asm is
inlined (for example v_ would be Unknown).

Overload sets ConstraintType to be always RegClass for SPIR-V.
2026-03-10 12:09:26 +01:00
Sietze Riemersma
5464d68290
[HLSL][DXIL][SPRIV] Added WaveActiveProduct intrinsic (#184645)
From issue #99165, adds the implementation of WaveActiveProduct. This
time with the new types for SPIRVTypeInst

- [x] Implement WaveActiveProduct clang builtin,
- [x] Link WaveActiveProduct clang builtin with hlsl_intrinsics.h
- [x] Add sema checks for WaveActiveProduct to
CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
- [x] Add codegen for WaveActiveProduct to EmitHLSLBuiltinExpr in
CGBuiltin.cpp
- [x] Add codegen tests to
clang/test/CodeGenHLSL/builtins/WaveActiveProduct.hlsl
- [x] Add sema tests to
clang/test/SemaHLSL/BuiltIns/WaveActiveProduct-errors.hlsl
- [x] Create the int_dx_WaveActiveProduct intrinsic in
IntrinsicsDirectX.td
- [x] Create the DXILOpMapping of int_dx_WaveActiveProduct to 119 in
DXIL.td
- [x] Create the WaveActiveProduct.ll and WaveActiveProduct_errors.ll
tests in llvm/test/CodeGen/DirectX/
- [x] Create the int_spv_WaveActiveProduct intrinsic in
IntrinsicsSPIRV.td
- [x] In SPIRVInstructionSelector.cpp create the WaveActiveProduct
lowering and map it to int_spv_WaveActiveProduct in
SPIRVInstructionSelector::selectIntrinsic.
- [x] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveProduct.ll
2026-03-10 00:48:40 -04:00
Juan Manuel Martinez Caamaño
1bd075947a
[NFC][SPIRV] Rename files from SPV_INTEL_arbitrary_precision_integers/floating to SPV_ALTERA_arbitrary_precision_integers/floating (#184996)
* The `SPV_INTEL_arbitrary_precision_integers` was renamed to
`SPV_ALTERA_arbitrary_precision_integers` in
https://github.com/llvm/llvm-project/pull/136085.
* The `SPV_INTEL_arbitrary_precision_floating_point` was introduced
directly as `SPV_ALTERA_arbitrary_precision_floating_point` in
https://github.com/llvm/llvm-project/pull/160054.
2026-03-06 18:45:12 +01:00
Juan Manuel Martinez Caamaño
e56b580d40
Reapply "[SPIRV] Emit intrinsics for globals only in function that references them (#178143 (#179268)) (#182552)
This reverts commit 395858d9f172ff1c61c661aa7c2a18b449daffa6.

This PR had been reverted due to an unrelated address-sanitizer failure.
2026-03-05 12:41:20 +01:00