<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99160>99160</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `WaveActiveAnyTrue` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
backend:DirectX,
HLSL,
backend:SPIR-V,
bot:HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
- [ ] Implement `WaveActiveAnyTrue` clang builtin,
- [ ] Link `WaveActiveAnyTrue` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `WaveActiveAnyTrue` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `WaveActiveAnyTrue` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/WaveActiveAnyTrue.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/WaveActiveAnyTrue-errors.hlsl`
- [ ] Create the `int_dx_WaveActiveAnyTrue` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_WaveActiveAnyTrue` to `113` in `DXIL.td`
- [ ] Create the `WaveActiveAnyTrue.ll` and `WaveActiveAnyTrue_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_WaveActiveAnyTrue` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `WaveActiveAnyTrue` lowering and map it to `int_spv_WaveActiveAnyTrue` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 113 | WaveAnyTrue | 6.0 | ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node') |
## SPIR-V
# [OpGroupNonUniformAny](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpGroupNonUniformAny):
## Description:
Evaluates a predicate for all active invocations in the [group](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Group),
resulting in **true** if predicate evaluates to **true** for any active
[invocation](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Invocation) in the group, otherwise the result is
**false**.
*Result Type* must be a [*Boolean type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Boolean).
*Execution* is a [*Scope*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Scope_-id-) that identifies the group of
invocations affected by this command. It must be **Subgroup**.
*Predicate* must be a [*Boolean type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Boolean).
[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):
**GroupNonUniformVote**
[Missing before](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Unified) **version 1.3**.
<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>5</p></td>
<td class="tableblock halign-left valign-top"><p>335</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result <id></em></a></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#Scope_-id-"><em>Scope <id></em></a><br />
<em>Execution</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Predicate</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc WaveActiveAnyTrue_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export bool fn(bool p1) {
return WaveActiveAnyTrue(p1);
}
```
## HLSL:
Returns true if the expression is true in any of the active lanes in the current wave.
## Syntax
``` syntax
bool WaveActiveAnyTrue(
bool expr
);
```
## Parameters
<dl> <dt>
*expr*
</dt> <dd>
The boolean expression to evaluate.
</dd> </dl>
## Return value
True if the expression is true in any lane.
## Remarks
This function is supported from shader model 6.0 in all shader stages.
## See also
<dl> <dt>
[Overview of Shader Model 6](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/hlsl-shader-model-6-0-features-for-direct3d-12.md)
</dt> <dt>
[Shader Model 6](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/shader-model-6-0.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWc1u4zgSfhrmQsiQqbacHHyQnXg2QPd0o9PTM7eAkkoWNxQpkJRj79MvipQtOXF-ZrHZPmxgxGJVqX6-KpJFmlsrNgpgQWZLMru-4J2rtVlU3PxLK3mR63K_iCiZLSmZXdPbppXQgHKUpPGffAtZ4cQWMrX_YTogaUwLydWG5p2QTijCViTOhtc_C_Xwvjfpo3A1itbSynuhnBHKisJOapLGJzqzsqQWGk6LGooHSyttXjThNLJWKPiPz3efl8HWulOFE1qtuJQoJRRK3UHDvaRQm0nRtufsFrqEDah32LxphBuZvNm1ZjC1-q0nv2XHgXW21-jhImyNNMLWK13Cb6DQBmHrHkVL2PqZUxOE9EUUXzGBiPT6vb-35_VHYIw29qyZlQHugLoaUL9Q7r7c3Z-F7ZjyHqPbYwlcCwOF-2viyte1X_91-_lr-4W3rVAbVKmrt4w6TVFkOk2G5KCa122dTf0k1BJX5Vn2fQ9SkAqgB3tSbptnaSVs3YdN2PptUG27_buo3n27_f7zT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