<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99167>99167</a>
        </td>
    </tr>

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 120 | WaveActiveBit | 6.0 | ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node') |

## SPIR-V

# [OpGroupNonUniformBitwiseOr](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpGroupNonUniformBitwiseOr):

## Description:
  
A bitwise or [group operation](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Group_Operation) of all *Value* operands
contributed by active [invocations](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Invocation) in the
[group](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Group).  
  
*Result Type* must be a scalar or vector of [*integer
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer).  
  
*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**.  
  
The identity *I* for *Operation* is 0. If *Operation* is
**ClusteredReduce**, *ClusterSize* must be present.  
  
The type of *Value* must be the same as *Result Type*.  
  
*ClusterSize* is the size of cluster to use. *ClusterSize* must be a
scalar of [*integer type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer), whose *Signedness* operand is 0.
*ClusterSize* must come from a [*constant
instruction*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#ConstantInstruction). Behavior is undefined unless
*ClusterSize* is at least 1 and a power of 2. If *ClusterSize* is
greater than the size of the [group](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Group), executing this instruction
results in undefined behavior.

[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):  
**GroupNonUniformArithmetic**, **GroupNonUniformClustered**,
**GroupNonUniformPartitionedNV**  
  
[Missing before](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Unified) **version 1.3**.

<table>
<colgroup>
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 12%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>6 + variable</p></td>
<td class="tableblock halign-left valign-top"><p>360</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result &lt;id&gt;</em></a></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#Scope_-id-"><em>Scope &lt;id&gt;</em></a><br />
<em>Execution</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#Group_Operation"><em>Group Operation</em></a><br />
<em>Operation</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Value</em></p></td>
<td class="tableblock halign-left valign-top"><p>Optional<br />
<em>&lt;id&gt;</em><br />
<em>ClusterSize</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

 
 ### Example 1
```hlsl
//dxc WaveActiveBitOr_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint4 fn(uint4 p1) {
    return WaveActiveBitOr(p1);
}
```
## HLSL:

Returns the bitwise OR of all the values of `<expr>` across all active non-helper lanes in the current wave, and replicates it back to all active non-helper lanes.

## Syntax

``` syntax
<int_type> WaveActiveBitOr(
   <int_type> expr
);
```

## Parameters

<dl> <dt>

*expr* 
</dt> <dd>

The expression to evaluate.

</dd> </dl>

## Return value

The bitwise OR value.

## 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/eJzsWd9u47bSfxrmhpAgU7GSXORCduJ-BnabYrPd9i6gxLHFLxQpkJST9OkPhpRt2XGybc_J9lycIuiaM8P585shOaS4c3KtAa7JdEamN2e8942x1ytu_zBanVVGvFwnlExnlExv6LLtFLSgPSVF9hvfQFl7uYGZ9HeWFBmtFddrWvVSeakJm5Os3E_-JPXjn5lHn6RvULBRTj1I7a3UTtYubUiRHWgshaAOWk7rBupHR1fGvmHAG2TMUez_Pt1_mkVLi17XXho950qhlNQodQ8tD5JSr9O6605ZrY2ANejvWrxtpR8ZvH3u7N7Q_KeB_D0rHpx3g8YAFWELpBG2mBsBP4FGG4QtBgQdYYsjl1IE80383jGAaAzag7fLU9oTsNZYd9LI3AL3QH0DqF1q_yCeH04Atkv0gM5yl_gbaaH2v6devK_75vflp7vuM-86qdeo0qzeN-kNRYEJy_ZJQSXvWzqR8DTWD9fiBPNhACfKRKijLaU27atUErYYAiZs8X0wXbf5a2je_7L88u1EhEtNA2upnbd9WBf3oKD2xmJ90vrA9AmTyjyBlXodYGh5R6n0Q02962hYc29YJnlJ8tKF0S4EUmTpKVRQSfKNVrx-BC0C0rTmDr6DdrBN2AKLN9lvNyfWkBqKG_9YTlhOt5mKtIs5xfKhdx2uXDoa_8zbOL5vuABLPxsBaky493wNDimDomT_H_3O-DUhGSmasCzwD4IJlCKNHMIuCbtQsrLcvhB2QRjSLmrTdr2HPYG3nZIrWXPM0J7cgmv2o04-g9oPN2A9PO_HTa9GXGFaLkeq1mBa8GMnLH9ZgwZ7ZFNqD9ZBfUjl-qWRfhSBMg6cP6C10rmRBFeKV2oUpDYijq62GO6SHetrR8Lyu-t-sqbvfjb6Vy1XxrYz6Z-kgztLpjeEXTbedw6LmC0IW1hYS-ftS_rYWKONS41dDwWYYAW6DkLd9VquJIjJtjjTxreKsPwda-wKrRyUJrjayi4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