
Fixes #99205. - Implements the HLSL intrinsic `AddUint64` used to perform unsigned 64-bit integer addition by using pairs of unsigned 32-bit integers instead of native 64-bit types - The LLVM intrinsic `uadd_with_overflow` is used in the implementation of `AddUint64` in `CGBuiltin.cpp` - The DXIL op `UAddc` was defined in `DXIL.td`, and a lowering of the LLVM intrinsic `uadd_with_overflow` to the `UAddc` DXIL op was implemented in `DXILOpLowering.cpp` Notes: - `__builtin_addc` was not able to be used to implement `AddUint64` in `hlsl_intrinsics.h` because its `CarryOut` argument is a pointer, and pointers are not supported in HLSL - A lowering of the LLVM intrinsic `uadd_with_overflow` to SPIR-V [already exists](https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/SPIRV/llvm-intrinsics/uadd.with.overflow.ll) - When lowering the LLVM intrinsic `uadd_with_overflow` to the `UAddc` DXIL op, the anonymous struct type `{ i32, i1 }` is replaced with a named struct type `%dx.types.i32c`. This aspect of the implementation may be changed when issue #113192 gets addressed - Fixes issues mentioned in the comments on the original PR #125319 --------- Co-authored-by: Finn Plummer <50529406+inbelic@users.noreply.github.com> Co-authored-by: Farzon Lotfi <farzonlotfi@microsoft.com> Co-authored-by: Chris B <beanz@abolishcrlf.org> Co-authored-by: Justin Bogner <mail@justinbogner.com>
31 lines
1.1 KiB
LLVM
31 lines
1.1 KiB
LLVM
; We use llc for this test so that we don't abort after the first error.
|
|
; RUN: not llc %s -o /dev/null 2>&1 | FileCheck %s
|
|
|
|
target triple = "dxil-pc-shadermodel6.3-library"
|
|
|
|
; DXIL operation UAddc only supports i32. Other integer types are unsupported.
|
|
; CHECK: error:
|
|
; CHECK-SAME: in function uaddc_i16
|
|
; CHECK-SAME: Cannot create UAddc operation: Invalid overload type
|
|
|
|
define noundef i16 @uaddc_i16(i16 noundef %a, i16 noundef %b) "hlsl.export" {
|
|
%uaddc = call { i16, i1 } @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
|
|
%carry = extractvalue { i16, i1 } %uaddc, 1
|
|
%sum = extractvalue { i16, i1 } %uaddc, 0
|
|
%carry_zext = zext i1 %carry to i16
|
|
%result = add i16 %sum, %carry_zext
|
|
ret i16 %result
|
|
}
|
|
|
|
; CHECK: error:
|
|
; CHECK-SAME: in function uaddc_return
|
|
; CHECK-SAME: DXIL ops that return structs may only be used by insert- and extractvalue
|
|
|
|
define noundef { i32, i1 } @uaddc_return(i32 noundef %a, i32 noundef %b) "hlsl.export" {
|
|
%uaddc = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
|
|
ret { i32, i1 } %uaddc
|
|
}
|
|
|
|
declare { i16, i1 } @llvm.uadd.with.overflow.i16(i16, i16)
|
|
|