392 Commits

Author SHA1 Message Date
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
Justin Bogner
91439985b3
[DirectX] Fix llc-pipeline test after #188573 (#188676)
Missed this update in the previous commit. We now expect CycleInfo
instead of LoopInfo.
2026-03-25 21:51:06 -07:00
Justin Bogner
f83697d69f
[DirectX] Handle byte type in DXILBitcodeWriter (#187157)
The byte type was introduced to LLVM IR in #186888. DXILBitcodeWriter
needs to handle this type by generating valid LLVM 3.7 era bitcode,
which is as simple as treating byte equivalently to an integer.
2026-03-25 20:57:08 +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
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
Steven Perron
a57db57e1b
[HLSL] Implement Texture2D::operator[] (#186110)
Implments the Texture2D::operator[] method. It uses the same design as
Buffer::operator[]. However, this requires us to chagne the
resource_getpointer intrinsic to accept integer vectors for the index.

Assisted-by: Gemini
2026-03-23 15:51:22 +00:00
Kaitlin Peng
33cfe2843b
[DirectX] Fix TypedBuffer load shader flag mismatch (#187393)
Fixes #187225.

The `TypedUAVLoadAdditionalFormats` shader flag was being set for all
TypedBuffer vector loads, so loading from a `Buffer<int64_t2>` was
incorrectly triggering this flag and causing the mismatch. This PR
changes it so the flag is only set for UAV loads.
2026-03-19 14:03:46 -07:00
joaosaffran
8176bc0e9b
[HLSL][SPIRV] Use 0 to represent unbounded arrays on shader flags (#187174)
this patch updates the shader flags to account for 0 being used to
represent unbounded arrays. This was a missed updated from the previous
pr #186022. This change is required to make sure the following offload
test pass dxv validation:

```
  OffloadTest-clang-d3d12 :: Feature/ResourceArrays/multi-dim-unbounded-array-nuri.test
  OffloadTest-clang-d3d12 :: Feature/ResourceArrays/multi-dim-unbounded-array.test
  OffloadTest-clang-d3d12 :: Feature/ResourceArrays/unbounded-array-nuri.test
  OffloadTest-clang-d3d12 :: Feature/ResourceArrays/unbounded-array.test
```

---------

Co-authored-by: Joao Saffran <jderezende@microsoft.com>
2026-03-19 00:22:41 +00: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
puneeth_aditya_56
aef7e5768e
[DirectX] Fix assertion in PointerTypeAnalysis with empty global_ctors (#179034)
When `llvm.global_ctors` has no elements (e.g., when all resources are
unused in a shader library), its initializer is a `zeroinitializer`
(`ConstantAggregateZero`) rather than a `ConstantArray`. The previous
code used `cast<ConstantArray>` which asserts on incompatible types:

> "cast<Ty>() argument of incompatible type!"

This patch uses `dyn_cast` and returns early if the initializer is not a
`ConstantArray`, handling the edge case gracefully.

Fixes #178993.

Co-authored-by: Kaitlin Peng <kaitlinpeng@microsoft.com>
2026-03-17 12:06:07 -07: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
Deric C.
9210b3a099
[HLSL][DirectX] Add transpose HLSL intrinsic and DXIL lowering of llvm.matrix.transpose (#186263)
Fixes #184922

- [x] Implement `transpose` clang builtin in `Builtins.td`
- [x] Link `transpose` clang builtin with `hlsl_alias_intrinsics.h`
- [x] Add sema checks for `transpose` to `CheckHLSLBuiltinFunctionCall`
in `SemaHLSL.cpp`
- [x] Add codegen for `transpose` to `EmitHLSLBuiltinExpr` in
`CGHLSLBuiltins.cpp`
  - `transpose` lowers to the `llvm.matrix.transpose` intrinsic
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/transpose.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/transpose-errors.hlsl`
- [x] Implement lowering of the `llvm.matrix.transpose` intrinsic in the
DXIL backend in `DXILIntrinsicExpansion.cpp`
- The intrinsic lowers to a shufflevector like in DXC
https://hlsl.godbolt.org/z/Gj959q6sq
- [x] Add DXIL lowering tests to
`llvm/test/CodeGen/DirectX/matrix-transpose.ll`

Assisted-by: claude-opus-4.6
2026-03-13 15:00:27 -07: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
Justin Bogner
6e93c4a19d
[DirectX] Specify element-aligned vectors (#180622)
Use the new "ve" Data Layout specifier to indicate that vectors are
element-aligned for the target.

Part of #123968
2026-03-11 15:49:48 -07:00
Justin Bogner
6fc6de073c
[DirectX] Split long vectors in DXILResourceAccess (#184732)
If a vector has more than 4 elements, the `resource.load` and
`resource.store`
intrinsics aren't able to handle it. Split these into multiple calls.

Fixes #167542
2026-03-11 08:54:53 -07: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
Deric C.
9d65b65a9a
[HLSL][Matrix] Add half type overloads to mul and exercise them (#185506)
PR #184882 was missing `half` type-specific overloads for `mul`. 
This PR introduces `half` type-specific overloads for `mul` and
additional codegen tests for the half type.
Also added f16 tests for the lowering of llvm.matrix.multiply.

The offload test suite already has a `mul.fp16` test for exercising half
types at runtime, so no change is needed there.

Assisted-by: claude-opus-4.6
2026-03-10 15:11:10 -07: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
Deric C.
06f7cd439c
[HLSL][DirectX] Implement HLSL mul function and DXIL lowering of llvm.matrix.multiply (#184882)
Fixes #99138

- Defines a `__builtin_hlsl_mul` clang builtin in `Builtins.td`.
- Links the `__builtin_hlsl_mul` clang builtin with
`hlsl_alias_intrinsics.h` under the name `mul` for matrix cases
- Implement scalar and vector elementwise multiplication cases of the
`mul` function in `hlsl_intrinsics.h` and `hlsl_intrinsic_helpers.h`
- Adds sema for `__builtin_hlsl_mul` to `CheckBuiltinFunctionCall` in
`SemaHLSL.cpp`
- Adds codegen for `__builtin_hlsl_mul` to `EmitHLSLBuiltinExpr` in
`CGHLSLBuiltins.cpp`
- Vector-vector cases lower to `dot` (except double vectors, which
expands to scalar multiply-adds).
- Matrix-matrix, matrix-vector, and vector-matrix multiplication lower
to the `llvm.matrix.multiply` intrinsic
- Adds codegen tests to `clang/test/CodeGenHLSL/builtins/mul.hlsl`
- Adds sema tests to `clang/test/SemaHLSL/BuiltIns/mul-errors.hlsl`
- Implements lowering of the `llvm.matrix.multiply` intrinsic to DXIL in
`DXILIntrinsicExpansion.cpp`

Note: Currently the SPIRV backend does not support row-major matrix
memory layouts when lowering matrix multiply, and just assumes
column-major layout. Therefore this PR also makes the DirectX backend
only assume column-major layout. Implementing support for row-major
order shall be done in a separate PR. (Tracked by
https://github.com/llvm/llvm-project/issues/184906)

This PR locally passes the `mul` offload tests in both DirectX 12 and
Vulkan: https://github.com/llvm/offload-test-suite/pull/941

Assisted-by: claude-opus-4.6
2026-03-06 13:32:07 -08:00
Joshua Batista
34541e5a54
[HLSL] Add WaveActiveAllEqual functions (#183634)
This PR adds the WaveActiveAllEqual function to HLSL.
It also adds extra macro logic to CGHLSLBuiltins so that you can specify
a different intrinsic name for the SPIRV intrinsic.
Fixes https://github.com/llvm/llvm-project/issues/99162
2026-03-04 10:37:22 -08:00
Finn Plummer
9081ac255a
[DirectX][ResourceAccess] Resolve resource handles at access (#182106)
This change resolves handles (or corresponding ptr) that all point into
a unique global resource by propagating an index into that global
resource through control flow.

If a unique global resource can't be resolved, an error is reported
instead.

This specifically resolves all handles that point into the same global
resource array.

Resolves: https://github.com/llvm/llvm-project/issues/165288

By reporting an error, this is part of resolving
https://github.com/llvm/llvm-project/issues/179303.
2026-03-03 09:06:43 -08:00
joaosaffran
0cabe93381
[HLSL] Reintroduce dx.disable_optimizations to set DisableOptimization Shader Flag (#180069)
This patch removes optnone from HLSL entry functions and instead uses
`dx.disable_optimizations` module flag to know when to enable
`DisableOptimization` Shader Flag. This is part of: #167936

---------

Co-authored-by: Joao Saffran <jderezende@microsoft.com>
2026-03-02 10:53:55 -08:00
Farzon Lotfi
844619e526
Revert "[HLSL][DXIL][SPRIV] Added WaveActiveProduct intrinsic #164385" (#182741)
Reverts llvm/llvm-project#165109
2026-02-22 08:23:17 -05:00
Sietze Riemersma
c42ad5898e
[HLSL][DXIL][SPRIV] Added WaveActiveProduct intrinsic #164385 (#165109)
From issue #99165, adds the implementation of WaveActiveProduct. Mainly
followed how WaveActiveSum was implemented

- [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

Also created the [offload
tests](https://github.com/llvm/offload-test-suite/pull/486)
2026-02-22 08:13:22 -05:00
Finn Plummer
fa1cda8f09
[DirectX] Mark dx.resource.getpointer as convergent (#182099)
By marking `dx.resource.getpointer` as convergent, we are able to
prevent unwanted code transforms that make resource access look illegal.
Namely, this prevents the creation of a ptr into a resource handle to be
moved throughout control flow (eg in `SimplifyCFG`), further preventing
sink/hoist optimizations on the returned ptr during `InstCombine`.

Previously, these transforms were undone by the `phiNodeReplacement`
function in `dxil-resource-access`. However, in general, we would like
to follow a policy of preventing these transforms from occurring rather
than having to undo the work. This change is aligned with this.

This is a pre-requisite to resolving
https://github.com/llvm/llvm-project/issues/165288.
2026-02-20 09:00:24 -08:00
Kai
6fe2aee9e6
[HLSL][DXIL][SPIRV] WavePrefixProduct intrinsic support (#179423)
This PR adds WavePrefixProduct intrinsic support in HLSL with codegen
for both DirectX and SPIRV backends. Resolves
https://github.com/llvm/llvm-project/issues/99173.

- [x] Implement `WavePrefixProduct` clang builtin
- [x] Link `WavePrefixProduct` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `WavePrefixProduct` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `WavePrefixProduct` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/WavePrefixProduct.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/WavePrefixProduct-errors.hlsl`
- [x] Create the `int_dx_WavePrefixProduct` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_WavePrefixProduct` to `121`
in `DXIL.td`
- [x] Create the `WavePrefixProduct.ll` and
`WavePrefixProduct_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_WavePrefixProduct` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In `SPIRVInstructionSelector.cpp` create the `WavePrefixProduct`
lowering and map it to `int_spv_WavePrefixProduct` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WavePrefixProduct.ll`
2026-02-17 17:32:40 -05:00
Paul Walker
96d2cb4145
[LLVM][CodeGen][DirectX] Fix scalarisation when vector ConstantFP is used. (#172684)
When using -use-constant-fp-for-fixed-length-splat `splat (float C)`
becomes ConstantFP(C) rather than ConstantVector(C, C, C...).
2026-02-05 13:18:38 +00:00
Kai
751a546fa9
[HLSL][DXIL][SPIRV] WavePrefixSum intrinsic support (#167946)
Issue: https://github.com/llvm/llvm-project/issues/99172
- [x] Implement `WavePrefixSum` clang builtin
- [x] Link `WavePrefixSum` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `WavePrefixSum` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `WavePrefixSum` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/WavePrefixSum.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/WavePrefixSum-errors.hlsl`
- [x] Create the `int_dx_WavePrefixSum` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_WavePrefixSum` to `121` in
`DXIL.td`
- [x] Create the `WavePrefixSum.ll` and `WavePrefixSum_errors.ll` tests
in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_WavePrefixSum` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In SPIRVInstructionSelector.cpp create the `WavePrefixSum`
lowering and map it to `int_spv_WavePrefixSum` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WavePrefixSum.ll`

I also added a new macro
`GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED` in conjunction with
the new function `getUnsignedIntrinsicVariant` to make selecting
unsigned variants of the intrinsic easier. As a result, I was able to
replace `getWaveActiveSumIntrinsic`, `getWaveActiveMaxIntrinsic`, and
`getWaveActiveMinIntrinsic` using the new macro.
2026-02-03 03:00:45 -05:00
Joshua Batista
293a668329
[HLSL] Add wave prefix count bits function (#178059)
This PR adds the WavePrefixCountBits function to HLSL, including spirv
and DXIL code generation.
Fixes https://github.com/llvm/llvm-project/issues/99171
2026-01-29 12:09:27 -08:00
Tim Corringham
d5f405558d
[HLSL] Implement f32tof16() intrinsic (#172469)
Implement the f32tof16() intrinsic, DXIL and SPIRV codegen, and related
tests.

Fixes #99113

---------

Co-authored-by: Tim Corringham <tcorring@amd.com>
2026-01-26 15:06:48 +00:00
Joshua Batista
058a223388
[HLSL] Add wave active ballot to set of wave ops that set waveops shader flag (#177043)
This PR simply adds wave active ballot to the set of wave ops that
switch on the waveops shader flag.
2026-01-21 10:06:04 -08:00
Joshua Batista
11b1836282
[HLSL] Handle WaveActiveBallot struct return type appropriately (#175105)
The previous WaveActiveBallot implementation did not account for the
fact that the DXC implementation of the intrinsic returns a struct type
with 4 uints, rather than a vector of 4 uints. This must be respected,
otherwise the validator will reject the uses of WaveActiveBallot that
return a vector of 4 uints.
This PR updates the return type and adds the DXC-specific return type
`fouri32` to use for the intrinsic.
2026-01-20 10:08:26 -08:00
Joshua Batista
ff617bce04
[HLSL] Fix WaveBallot dxil op function name (#174901)
Just fixing a typo from a copy paste.
2026-01-08 10:17:47 -08:00
Joshua Batista
65b0de42e7
[HLSL] Add WaveActiveBallot builtins and lower to DXIL / SPIR-V (#174638)
This PR adds WaveActiveBallot as a builtin function to HLSL.
Fixes https://github.com/llvm/llvm-project/issues/99163
2026-01-07 10:06:27 -08:00
Deric C.
57b0d8379e
[DirectX] Account for GlobalOffset in CurrentIndex calculation for cbuffer loads with GEPs in DXILResourceAccess pass (#174666)
Fixes #174656

---------

Co-authored-by: Alex Sepkowski <alexsepkowski@gmail.com>
2026-01-07 08:39:25 -08:00
Joshua Batista
52e815f1cd
[HLSL] Add allresourcesbound option to DXC driver and set corresponding module flag (#173411)
This PR adds a new CC1 option and a new dxc driver option. The DXC
option, when set, is translated into the new CC1 option.
The `all-resources-bound` dxc option will create a metadata module flag,
and the print-dx-shader-flags pass will set the appropriate shader
module flag from this metadata module flag.

Fixes https://github.com/llvm/llvm-project/issues/112264
2025-12-30 10:15:46 -08:00
Justin Bogner
ac602d887b
[DirectX] Disallow ElementIndex for raw buffer accesses (#173320)
Raw (as in ByteAddress) buffer accesses in DXIL must specify
ElementIndex as undef, and Structured buffer accesses must specify a
value. Ensure that we do this correctly in DXILResourceAccess, and
enforce that the operations are valid in DXILOpLowering.

Fixes #173316
2025-12-23 13:32:50 -07:00
Justin Bogner
38cdadd9c7
[DirectX] Teach MemIntrinsics about structs and nested arrays (#173078)
Add handling for more complicated cases than simple arrays.
2025-12-22 13:28:41 -07:00
Justin Bogner
b359616349
[DirectX] Resources and simple GEP traversal in DXILMemIntrinsics (#173054)
Walk through GEPs and recognize resource target extension types when
trying to infer the underlying types of memory intrinsics.
2025-12-22 11:47:50 -07:00
Justin Bogner
b324c9f4fa
[DirectX] Move memset and memcpy handling to a new pass. NFC (#172921)
This introduces the DXILMemIntrinsics pass and moves memset and memcpy
handling from DXILLegalize to here. We need to do this so that we can
handle memory intrinsics before the DXILResourceAccess pass so that we
can properly deal with arrays and large structures in resources.
2025-12-18 22:08:43 -07:00
Justin Bogner
c3039a7dc5
[DirectX] Avoid precalculating GEPs in DXILResourceAccess (#172720)
Instead of trying to precalculate GEP offsets ahead of time and then
process resource accesses based off of these offsets, traverse the GEP
chain inline for each access. This makes it easier to get the types
correct when translating GEPs for cbuffer and structured buffer
accesses, which in turn lets us access individual elements of those
structures directly.

Fixes #160208, #164517, and #169430
2025-12-18 22:15:12 +00:00
Finn Plummer
2185596c07
[DirectX] Add lowering support for llvm.fsh[l|r].* (#170570)
This pr adds support to emulate the `llvm.fshl.*` and `llvm.fshr.*`
intrinsics by expanding them, as described
[here](https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic).

Resolves  #165750.
2025-12-15 10:03:42 -08:00
Alexander Johnston
4ca2caeab6
[HLSL] Implement ddx/ddy_fine intrinsics (#168874)
Implements the HLSL ddx_fine and ddy_fine intrinsics.
For the SPIRV backend the intrinsics are ensured to be unavailable in
opencl (as they require fragment execution stage).

Closes https://github.com/llvm/llvm-project/issues/99098
Closes https://github.com/llvm/llvm-project/issues/99101
2025-12-12 09:34:41 -08:00
Finn Plummer
ed6078c023
[NFC] Add missing analysis to DirectX/llc-pipeline (#170714)
The Runtime Library Function Analysis pass was added in
https://github.com/llvm/llvm-project/pull/168622 but the backend test
case was not updating accordingly.
2025-12-04 18:56:23 +00:00
Deric C.
06c8ee61ab
[NFC] [DirectX] Make DirectX codegen test CBufferAccess/gep-ce-two-uses.ll more strict (#169855)
Continuation of PR #169848 to address PR comments.

This PR makes the test more strict by adding CHECKs to ensure the loads
are indeed using the same or different GEPs.
2025-11-27 13:58:47 -08:00
Deric C.
a1f30c24ea
[NFC] [DirectX] Update DirectX codegen test CBufferAccess/gep-ce-two-uses.ll due to changes to ReplaceConstant (#169848)
Fixes an LLVM DirectX codegen test after it broke due to #169141

The CBuffer loads and GEPs are no longer duplicated when there are two
or more accesses within the same basic block.
This PR removes the duplicate check for CBuffer load and GEP from the
original test function `@f` and adds a new test function `@g` which
places duplicate CBuffer loads into separate basic blocks.
2025-11-27 12:02:15 -08:00
Deric C.
f5e228b32a
[DirectX] Simplify DXIL data scalarization, and data scalarize whole GEP chains (#168096)
- The DXIL data scalarizer only needs to change vectors into arrays. It
does not need to change the types of GEPs to match the pointer type.
This PR simplifies the `visitGetElementPtrInst` method to do just that
while also accounting for nested GEPs from ConstantExprs. (Before this
PR, there were still vector types lingering in nested GEPs with
ConstantExprs.)
- The `equivalentArrayTypeFromVector` function was awkwardly placed near
the top of the file and away from the other helper functions. The
function is now moved next to the other helper functions.
- Removed an unnecessary `||` condition from `isVectorOrArrayOfVectors`

Related tests have also been cleaned up, and the test CHECKs have been
modified to account for the new simplified behavior.
2025-11-24 10:56:20 -08:00
Alexander Johnston
76f1949cfa
[HLSL] Implement the fwidth intrinsic for DXIL and SPIR-V target (#161378)
Adds the fwidth intrinsic for HLSL.
The DXIL path only requires modification to the hlsl headers.
The SPIRV path implements the OpFwidth builtin in Clang and instruction
selection for the OpFwidth instruction in LLVM.
Also adds shader stage tests to the ddx_coarse and ddy_coarse
instructions used by fwidth.

Closes #99120

---------

Co-authored-by: Alexander Johnston <alexander.johnston@amd.com>
2025-11-20 07:38:32 -05:00
Justin Bogner
c4898f3f22
[HLSL][DirectX] Use a padding type for HLSL buffers. (#167404)
This change drops the use of the "Layout" type and instead uses explicit
padding throughout the compiler to represent types in HLSL buffers.

There are a few parts to this, though it's difficult to split them up as
they're very interdependent:

1. Refactor HLSLBufferLayoutBuilder to allow us to calculate the padding
of arbitrary types.
2. Teach Clang CodeGen to use HLSL specific paths for cbuffers when
generating aggregate copies, array accesses, and structure accesses.
3. Simplify DXILCBufferAccesses such that it directly replaces accesses
with dx.resource.getpointer rather than recalculating the layout.
4. Basic infrastructure for SPIR-V handling, but the implementation
itself will need work in follow ups.

Fixes several issues, including #138996, #144573, and #156084.
Resolves #147352.
2025-11-18 13:38:43 -08:00
Alexander Johnston
ed60cd2563
[HLSL] Implement ddx/ddy_coarse intrinsics (#164831)
Closes https://github.com/llvm/llvm-project/issues/99097
Closes https://github.com/llvm/llvm-project/issues/99100

As ddx and ddy are near identical implementations I've combined them in
this PR. This aims to unblock
https://github.com/llvm/llvm-project/pull/161378

---------

Co-authored-by: Alexander Johnston <alexander.johnston@amd.com>
2025-11-18 16:41:07 +01:00