[PATCH] D147476: [WebAssembly] Add libcall signatures for roundeven

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 14:56:08 PDT 2023


tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
tlively requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Since clang started emitting roundeven intrinsics in a7d6593a0a17 <https://reviews.llvm.org/rGa7d6593a0a17a1e7f46a3c9cd5c4aeeb7dfc6e0a>, they would
cause a crash in the WebAssembly backend because it did not know the roundeven
library function signatures. Fix the crash by adding the signatures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147476

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
  llvm/test/CodeGen/WebAssembly/libcalls.ll


Index: llvm/test/CodeGen/WebAssembly/libcalls.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/libcalls.ll
+++ llvm/test/CodeGen/WebAssembly/libcalls.ll
@@ -18,10 +18,9 @@
 declare double @llvm.powi.f64.i32(double, i32)
 declare double @llvm.log.f64(double)
 declare double @llvm.exp.f64(double)
+declare double @llvm.roundeven.f64(double)
 declare i32 @llvm.lround(double)
 
-
-
 define fp128 @fp128libcalls(fp128 %x, fp128 %y, i32 %z) {
   ; compiler-rt call
 ; CHECK-LABEL: fp128libcalls:
@@ -236,18 +235,19 @@
 ; CHECK-LABEL: f64libcalls:
 ; CHECK:         .functype f64libcalls (f64, f64, i32) -> (i32)
 ; CHECK-NEXT:  # %bb.0:
-; CHECK-NEXT:    local.get $push8=, 0
-; CHECK-NEXT:    call $push0=, cos, $pop8
+; CHECK-NEXT:    local.get $push9=, 0
+; CHECK-NEXT:    call $push0=, cos, $pop9
 ; CHECK-NEXT:    call $push1=, log10, $pop0
-; CHECK-NEXT:    local.get $push9=, 1
-; CHECK-NEXT:    call $push2=, pow, $pop1, $pop9
-; CHECK-NEXT:    local.get $push10=, 2
-; CHECK-NEXT:    call $push3=, __powidf2, $pop2, $pop10
+; CHECK-NEXT:    local.get $push10=, 1
+; CHECK-NEXT:    call $push2=, pow, $pop1, $pop10
+; CHECK-NEXT:    local.get $push11=, 2
+; CHECK-NEXT:    call $push3=, __powidf2, $pop2, $pop11
 ; CHECK-NEXT:    call $push4=, log, $pop3
 ; CHECK-NEXT:    call $push5=, exp, $pop4
 ; CHECK-NEXT:    call $push6=, cbrt, $pop5
-; CHECK-NEXT:    call $push7=, lround, $pop6
-; CHECK-NEXT:    return $pop7
+; CHECK-NEXT:    call $push7=, roundeven, $pop6
+; CHECK-NEXT:    call $push8=, lround, $pop7
+; CHECK-NEXT:    return $pop8
  %a = call double @llvm.cos.f64(double %x)
  %b = call double @llvm.log10.f64(double %a)
  %c = call double @llvm.pow.f64(double %b, double %y)
@@ -255,8 +255,9 @@
  %e = call double @llvm.log.f64(double %d)
  %f = call double @llvm.exp.f64(double %e)
  %g = call fast double @llvm.pow.f64(double %f, double 0x3FD5555555555555)
- %h = call i32 @llvm.lround(double %g)
- ret i32 %h
+ %h = call double @llvm.roundeven.f64(double %g)
+ %i = call i32 @llvm.lround(double %h)
+ ret i32 %i
 }
 
 ; fcmp ord and unord (RTLIB::O_F32 / RTLIB::UO_F32 etc) are a special case (see
Index: llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
@@ -218,6 +218,9 @@
     Table[RTLIB::ROUND_F32] = f32_func_f32;
     Table[RTLIB::ROUND_F64] = f64_func_f64;
     Table[RTLIB::ROUND_F128] = i64_i64_func_i64_i64;
+    Table[RTLIB::ROUNDEVEN_F32] = f32_func_f32;
+    Table[RTLIB::ROUNDEVEN_F64] = f64_func_f64;
+    Table[RTLIB::ROUNDEVEN_F128] = i64_i64_func_i64_i64;
     Table[RTLIB::LROUND_F32] = iPTR_func_f32;
     Table[RTLIB::LROUND_F64] = iPTR_func_f64;
     Table[RTLIB::LROUND_F128] = iPTR_func_i64_i64;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147476.510614.patch
Type: text/x-patch
Size: 2929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230403/c22dca9c/attachment.bin>


More information about the llvm-commits mailing list