11; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22
3- ; CHECK: %dx.types.i32c = type { i32, i1 }
3+ ; This test exercises the lowering of the intrinsic @llvm.uadd.with.overflow. i32 to the UAddc DXIL op
44
5+ ; CHECK-DAG: [[DX_TYPES_I32C:%dx\.types\.i32c]] = type { i32, i1 }
6+
7+ ; NOTE: The uint2 overload of AddUint64 HLSL uses @llvm.uadd.with.overflow.i32, resulting in one UAddc op
58define noundef i32 @test_UAddc (i32 noundef %a , i32 noundef %b ) {
69; CHECK-LABEL: define noundef i32 @test_UAddc(
710; CHECK-SAME: i32 noundef [[A:%.*]], i32 noundef [[B:%.*]]) {
8- ; CHECK-NEXT: [[UADDC:%.*]] = call [[DX_TYPES_I32C:%dx\.types\.i32c ]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A]], i32 [[B]]) #[[ATTR0:[0-9]+]]
11+ ; CHECK-NEXT: [[UADDC:%.*]] = call [[DX_TYPES_I32C]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A]], i32 [[B]]) #[[ATTR0:[0-9]+]]
912; CHECK-NEXT: [[CARRY:%.*]] = extractvalue [[DX_TYPES_I32C]] [[UADDC]], 1
1013; CHECK-NEXT: [[SUM:%.*]] = extractvalue [[DX_TYPES_I32C]] [[UADDC]], 0
1114; CHECK-NEXT: [[CARRY_ZEXT:%.*]] = zext i1 [[CARRY]] to i32
@@ -20,12 +23,13 @@ define noundef i32 @test_UAddc(i32 noundef %a, i32 noundef %b) {
2023 ret i32 %result
2124}
2225
26+ ; NOTE: The uint4 overload of AddUint64 HLSL uses @llvm.uadd.with.overflow.v2i32, resulting in two UAddc ops after scalarization
2327define noundef <2 x i32 > @test_UAddc_vec2 (<2 x i32 > noundef %a , <2 x i32 > noundef %b ) {
2428; CHECK-LABEL: define noundef <2 x i32> @test_UAddc_vec2(
2529; CHECK-SAME: <2 x i32> noundef [[A:%.*]], <2 x i32> noundef [[B:%.*]]) {
2630; CHECK-NEXT: [[A_I0:%.*]] = extractelement <2 x i32> [[A]], i64 0
2731; CHECK-NEXT: [[B_I0:%.*]] = extractelement <2 x i32> [[B]], i64 0
28- ; CHECK-NEXT: [[UADDC_I0:%.*]] = call [[DX_TYPES_I32C:%dx\.types\.i32c ]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A_I0]], i32 [[B_I0]]) #[[ATTR0]]
32+ ; CHECK-NEXT: [[UADDC_I0:%.*]] = call [[DX_TYPES_I32C]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A_I0]], i32 [[B_I0]]) #[[ATTR0]]
2933; CHECK-NEXT: [[A_I1:%.*]] = extractelement <2 x i32> [[A]], i64 1
3034; CHECK-NEXT: [[B_I1:%.*]] = extractelement <2 x i32> [[B]], i64 1
3135; CHECK-NEXT: [[UADDC_I1:%.*]] = call [[DX_TYPES_I32C]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A_I1]], i32 [[B_I1]]) #[[ATTR0]]
@@ -56,7 +60,7 @@ define noundef <2 x i32> @test_UAddc_vec2(<2 x i32> noundef %a, <2 x i32> nounde
5660define noundef i32 @test_UAddc_insert (i32 noundef %a , i32 noundef %b ) {
5761; CHECK-LABEL: define noundef i32 @test_UAddc_insert(
5862; CHECK-SAME: i32 noundef [[A:%.*]], i32 noundef [[B:%.*]]) {
59- ; CHECK-NEXT: [[UADDC:%.*]] = call [[DX_TYPES_I32C:%dx\.types\.i32c ]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A]], i32 [[B]]) #[[ATTR0]]
63+ ; CHECK-NEXT: [[UADDC:%.*]] = call [[DX_TYPES_I32C]] @dx.op.binaryWithCarryOrBorrow.i32(i32 44, i32 [[A]], i32 [[B]]) #[[ATTR0]]
6064; CHECK-NEXT: [[UNUSED:%.*]] = insertvalue [[DX_TYPES_I32C]] [[UADDC]], i32 [[A]], 0
6165; CHECK-NEXT: [[RESULT:%.*]] = extractvalue [[DX_TYPES_I32C]] [[UADDC]], 0
6266; CHECK-NEXT: ret i32 [[RESULT]]
0 commit comments