case OpSignBitSet:
return mapValue(BV,
transRelational(static_cast<SPIRVInstruction *>(BV), BB));
+ case OpIAddCarry: {
+ IRBuilder Builder(BB);
+ auto *BC = static_cast<SPIRVBinary *>(BV);
+ return mapValue(BV, Builder.CreateBinaryIntrinsic(
+ Intrinsic::uadd_with_overflow,
+ transValue(BC->getOperand(0), F, BB),
+ transValue(BC->getOperand(1), F, BB)));
+ }
case OpGetKernelWorkGroupSize:
case OpGetKernelPreferredWorkGroupSizeMultiple:
return mapValue(
case Intrinsic::dbg_label:
case Intrinsic::trap:
case Intrinsic::arithmetic_fence:
+ case Intrinsic::uadd_with_overflow:
return true;
default:
// Unknown intrinsics' declarations should always be translated
SPIRVValue *Zero = transValue(Constant::getNullValue(II->getType()), BB);
return BM->addSelectInst(Cmp, Sub, Zero, BB);
}
+ case Intrinsic::uadd_with_overflow: {
+ return BM->addBinaryInst(OpIAddCarry, transType(II->getType()),
+ transValue(II->getArgOperand(0), BB),
+ transValue(II->getArgOperand(1), BB), BB);
+ }
case Intrinsic::memset: {
// Generally there is no direct mapping of memset to SPIR-V. But it turns
// out that memset is emitted by Clang for initialization in default
--- /dev/null
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck --check-prefix CHECK-SPIRV %s
+; RUN: llvm-spirv %t.bc -o %t.spv
+; Current implementation doesn't comply with specification and should be fixed in future.
+; TODO: spirv-val %t.spv
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o - | FileCheck --check-prefix CHECK-LLVM %s
+
+target triple = "spir64-unknown-unknown"
+
+; CHECK-SPIRV: TypeInt [[#I16TYPE:]] 16
+; CHECK-SPIRV: TypeInt [[#I32TYPE:]] 32
+; CHECK-SPIRV: TypeInt [[#I64TYPE:]] 64
+; CHECK-SPIRV: TypeBool [[#BTYPE:]]
+; CHECK-SPIRV: TypeStruct [[#S0TYPE:]] [[#I16TYPE]] [[#BTYPE]]
+; CHECK-SPIRV: TypeStruct [[#S1TYPE:]] [[#I32TYPE]] [[#BTYPE]]
+; CHECK-SPIRV: TypeStruct [[#S2TYPE:]] [[#I64TYPE]] [[#BTYPE]]
+; CHECK-SPIRV: TypeVector [[#V4XI32TYPE:]] [[#I32TYPE]] 4
+; CHECK-SPIRV: TypeVector [[#V4XBTYPE:]] [[#BTYPE]] 4
+; CHECK-SPIRV: TypeStruct [[#S3TYPE:]] [[#V4XI32TYPE]] [[#V4XBTYPE]]
+; CHECK-SPIRV: IAddCarry [[#S0TYPE]]
+; CHECK-SPIRV: IAddCarry [[#S1TYPE]]
+; CHECK-SPIRV: IAddCarry [[#S2TYPE]]
+; CHECK-SPIRV: IAddCarry [[#S3TYPE]]
+; CHECK-LLVM: call { i16, i1 } @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
+; CHECK-LLVM: call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
+; CHECK-LLVM: call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
+; CHECK-LLVM: call { <4 x i32>, <4 x i1> } @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
+
+define spir_func void @test_uadd_with_overflow_i16(i16 %a, i16 %b) {
+entry:
+ %res = call {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
+ ret void
+}
+
+define spir_func void @test_uadd_with_overflow_i32(i32 %a, i32 %b) {
+entry:
+ %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
+ ret void
+}
+
+define spir_func void @test_uadd_with_overflow_i64(i64 %a, i64 %b) {
+entry:
+ %res = call {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
+ ret void
+}
+
+define spir_func void @test_uadd_with_overflow_v4i32(<4 x i32> %a, <4 x i32> %b) {
+entry:
+ %res = call {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
+ ret void
+}
+
+declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
+declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
+declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
+declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)