[clang] [llvm] [HLSL] [DXIL] Implement the `AddUint64` HLSL function and the `UAddc` DXIL op (PR #125319)
Deric Cheung via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 3 16:29:01 PST 2025
================
@@ -19105,6 +19105,51 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
return nullptr;
switch (BuiltinID) {
+ case Builtin::BI__builtin_hlsl_adduint64: {
----------------
Icohedron wrote:
`__builtin_addc` was not able to be used to implement `AddUint64` in `hlsl_intrinsics.h` and (by extension) `hlsl_detail.h` because its `carryout` argument is a pointer (as documented [here](https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGBuiltin.cpp#L5508)).
Since pointers are not supported in HLSL, an error is emitted when running HLSL codegen tests with an example implementation like the following in `hlsl_intrinsics.h`.
```cpp
_HLSL_AVAILABILITY(shadermodel, 6.0)
const inline uint32_t2 AddUint64(uint32_t2 a, uint32_t2 b) {
uint32_t carry;
uint32_t low_sum = __builtin_addc(a.x, b.x, 0, &carry);
uint32_t high_sum = __builtin_addc(a.y, b.y, carry, nullptr);
return uint32_t2(low_sum, high_sum);
}
```
```
build/lib/clang/20/include/hlsl/hlsl_intrinsics.h:158:50: error: the '&' operator is unsupported in HLSL
158 | uint32_t low_sum = __builtin_addc(a.x, b.x, 0, &carry);
```
https://github.com/llvm/llvm-project/pull/125319
More information about the cfe-commits
mailing list