diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp b/llvm/lib/Target/Sparc/SparcISelLowering.cpp --- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp +++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp @@ -1614,11 +1614,14 @@ if (!Subtarget->is64Bit()) { // These libcalls are not available in 32-bit. + setLibcallName(RTLIB::MULO_I64, nullptr); setLibcallName(RTLIB::SHL_I128, nullptr); setLibcallName(RTLIB::SRL_I128, nullptr); setLibcallName(RTLIB::SRA_I128, nullptr); } + setLibcallName(RTLIB::MULO_I128, nullptr); + if (!Subtarget->isV9()) { // SparcV8 does not have FNEGD and FABSD. setOperationAction(ISD::FNEG, MVT::f64, Custom); diff --git a/llvm/test/CodeGen/SPARC/overflow-intrinsic-optimizations.ll b/llvm/test/CodeGen/SPARC/overflow-intrinsic-optimizations.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/SPARC/overflow-intrinsic-optimizations.ll @@ -0,0 +1,28 @@ +; RUN: llc %s -mtriple=sparc -o - | FileCheck %s +; RUN: llc %s -mtriple=sparc64 -o - | FileCheck %s +declare { i128, i1 } @llvm.smul.with.overflow.i128(i128, i128) +declare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64) + +define i32 @mul(i128 %a, i128 %b, i128* %r) { +; CHECK-LABEL: mul +; CHECK-NOT: call __muloti4 + %mul4 = tail call { i128, i1 } @llvm.smul.with.overflow.i128(i128 %a, i128 %b) + %mul.val = extractvalue { i128, i1 } %mul4, 0 + %mul.ov = extractvalue { i128, i1 } %mul4, 1 + %mul.not.ov = xor i1 %mul.ov, true + store i128 %mul.val, i128* %r, align 16 + %conv = zext i1 %mul.not.ov to i32 + ret i32 %conv +} + +define i32 @mul2(i64 %a, i64 %b, i64* %r) { +; CHECK-LABEL: mul2 +; CHECK-NOT: call __mulodi4 + %mul4 = tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %a, i64 %b) + %mul.val = extractvalue { i64, i1 } %mul4, 0 + %mul.ov = extractvalue { i64, i1 } %mul4, 1 + %mul.not.ov = xor i1 %mul.ov, true + store i64 %mul.val, i64* %r, align 16 + %conv = zext i1 %mul.not.ov to i32 + ret i32 %conv +}