[PATCH] D112750: [SparcISelLowering] avoid emitting libcalls to __muloti4 and __mulodi4

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 12:14:04 PDT 2021


nickdesaulniers updated this revision to Diff 383457.
nickdesaulniers retitled this revision from "[SparcISelLowering] avoid emitting libcalls to __muloti4()" to "[SparcISelLowering] avoid emitting libcalls to __muloti4 and __mulodi4".
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

- block __mulodi4 for 32b sparc, add test, rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112750/new/

https://reviews.llvm.org/D112750

Files:
  llvm/lib/Target/Sparc/SparcISelLowering.cpp
  llvm/test/CodeGen/SPARC/overflow-intrinsic-optimizations.ll


Index: llvm/test/CodeGen/SPARC/overflow-intrinsic-optimizations.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Target/Sparc/SparcISelLowering.cpp
===================================================================
--- llvm/lib/Target/Sparc/SparcISelLowering.cpp
+++ 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112750.383457.patch
Type: text/x-patch
Size: 1977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/8856b8dc/attachment.bin>


More information about the llvm-commits mailing list