[llvm] r244562 - WebAssembly: add basic floating-point tests

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 19:45:15 PDT 2015


Author: jfb
Date: Mon Aug 10 21:45:15 2015
New Revision: 244562

URL: http://llvm.org/viewvc/llvm-project?rev=244562&view=rev
Log:
WebAssembly: add basic floating-point tests

Summary: I somehow forgot to add these when I added the basic floating-point opcodes. Also remove ceil/floor/trunc/nearestint for now, and add them only when properly tested.

Subscribers: llvm-commits, sunfish, jfb

Differential Revision: http://reviews.llvm.org/D11927

Added:
    llvm/trunk/test/CodeGen/WebAssembly/fp32.ll
    llvm/trunk/test/CodeGen/WebAssembly/fp64.ll
Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td?rev=244562&r1=244561&r2=244562&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td Mon Aug 10 21:45:15 2015
@@ -19,10 +19,14 @@ defm FDIV : BinaryFP<fdiv>;
 defm FABS : UnaryFP<fabs>;
 defm FNEG : UnaryFP<fneg>;
 defm COPYSIGN : BinaryFP<fcopysign>;
-defm CEIL : UnaryFP<fceil>;
-defm FLOOR : UnaryFP<ffloor>;
-defm TRUNC : UnaryFP<ftrunc>;
-defm NEARESTINT : UnaryFP<fnearbyint>;
+
+/*
+ * TODO(jfb): add and test these:
+ * defm CEIL : UnaryFP<fceil>;
+ * defm FLOOR : UnaryFP<ffloor>;
+ * defm TRUNC : UnaryFP<ftrunc>;
+ * defm NEARESTINT : UnaryFP<fnearbyint>;
+ */
 
 /*
  * TODO(jfb): Add the following for 32-bit and 64-bit.

Added: llvm/trunk/test/CodeGen/WebAssembly/fp32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/fp32.ll?rev=244562&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/fp32.ll (added)
+++ llvm/trunk/test/CodeGen/WebAssembly/fp32.ll Mon Aug 10 21:45:15 2015
@@ -0,0 +1,69 @@
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+; Test that basic 32-bit floating-point operations assemble as expected.
+
+target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare float @llvm.fabs.f32(float)
+declare float @llvm.copysign.f32(float, float)
+declare float @llvm.sqrt.f32(float)
+
+; CHECK-LABEL: fadd32:
+; CHECK-NEXT: (setlocal @0 (argument 1))
+; CHECK-NEXT: (setlocal @1 (argument 0))
+; CHECK-NEXT: (setlocal @2 (fadd @1 @0))
+; CHECK-NEXT: (return @2)
+define float @fadd32(float %x, float %y) {
+  %a = fadd float %x, %y
+  ret float %a
+}
+
+; CHECK-LABEL: fsub32:
+; CHECK: (setlocal @2 (fsub @1 @0))
+define float @fsub32(float %x, float %y) {
+  %a = fsub float %x, %y
+  ret float %a
+}
+
+; CHECK-LABEL: fmul32:
+; CHECK: (setlocal @2 (fmul @1 @0))
+define float @fmul32(float %x, float %y) {
+  %a = fmul float %x, %y
+  ret float %a
+}
+
+; CHECK-LABEL: fdiv32:
+; CHECK: (setlocal @2 (fdiv @1 @0))
+define float @fdiv32(float %x, float %y) {
+  %a = fdiv float %x, %y
+  ret float %a
+}
+
+; CHECK-LABEL: fabs32:
+; CHECK: (setlocal @1 (fabs @0))
+define float @fabs32(float %x) {
+  %a = call float @llvm.fabs.f32(float %x)
+  ret float %a
+}
+
+; CHECK-LABEL: fneg32:
+; CHECK: (setlocal @1 (fneg @0))
+define float @fneg32(float %x) {
+  %a = fsub float -0., %x
+  ret float %a
+}
+
+; CHECK-LABEL: copysign32:
+; CHECK: (setlocal @2 (copysign @1 @0))
+define float @copysign32(float %x, float %y) {
+  %a = call float @llvm.copysign.f32(float %x, float %y)
+  ret float %a
+}
+
+; CHECK-LABEL: sqrt32:
+; CHECK: (setlocal @1 (sqrt @0))
+define float @sqrt32(float %x) {
+  %a = call float @llvm.sqrt.f32(float %x)
+  ret float %a
+}

Added: llvm/trunk/test/CodeGen/WebAssembly/fp64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/fp64.ll?rev=244562&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/fp64.ll (added)
+++ llvm/trunk/test/CodeGen/WebAssembly/fp64.ll Mon Aug 10 21:45:15 2015
@@ -0,0 +1,69 @@
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+; Test that basic 64-bit floating-point operations assemble as expected.
+
+target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare double @llvm.fabs.f64(double)
+declare double @llvm.copysign.f64(double, double)
+declare double @llvm.sqrt.f64(double)
+
+; CHECK-LABEL: fadd64:
+; CHECK-NEXT: (setlocal @0 (argument 1))
+; CHECK-NEXT: (setlocal @1 (argument 0))
+; CHECK-NEXT: (setlocal @2 (fadd @1 @0))
+; CHECK-NEXT: (return @2)
+define double @fadd64(double %x, double %y) {
+  %a = fadd double %x, %y
+  ret double %a
+}
+
+; CHECK-LABEL: fsub64:
+; CHECK: (setlocal @2 (fsub @1 @0))
+define double @fsub64(double %x, double %y) {
+  %a = fsub double %x, %y
+  ret double %a
+}
+
+; CHECK-LABEL: fmul64:
+; CHECK: (setlocal @2 (fmul @1 @0))
+define double @fmul64(double %x, double %y) {
+  %a = fmul double %x, %y
+  ret double %a
+}
+
+; CHECK-LABEL: fdiv64:
+; CHECK: (setlocal @2 (fdiv @1 @0))
+define double @fdiv64(double %x, double %y) {
+  %a = fdiv double %x, %y
+  ret double %a
+}
+
+; CHECK-LABEL: fabs64:
+; CHECK: (setlocal @1 (fabs @0))
+define double @fabs64(double %x) {
+  %a = call double @llvm.fabs.f64(double %x)
+  ret double %a
+}
+
+; CHECK-LABEL: fneg64:
+; CHECK: (setlocal @1 (fneg @0))
+define double @fneg64(double %x) {
+  %a = fsub double -0., %x
+  ret double %a
+}
+
+; CHECK-LABEL: copysign64:
+; CHECK: (setlocal @2 (copysign @1 @0))
+define double @copysign64(double %x, double %y) {
+  %a = call double @llvm.copysign.f64(double %x, double %y)
+  ret double %a
+}
+
+; CHECK-LABEL: sqrt64:
+; CHECK: (setlocal @1 (sqrt @0))
+define double @sqrt64(double %x) {
+  %a = call double @llvm.sqrt.f64(double %x)
+  ret double %a
+}




More information about the llvm-commits mailing list