[llvm] r252653 - [WebAssembly] Support for floating point min and max.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 10 13:40:21 PST 2015
Author: djg
Date: Tue Nov 10 15:40:21 2015
New Revision: 252653
URL: http://llvm.org/viewvc/llvm-project?rev=252653&view=rev
Log:
[WebAssembly] Support for floating point min and max.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td
llvm/trunk/test/CodeGen/WebAssembly/f32.ll
llvm/trunk/test/CodeGen/WebAssembly/f64.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=252653&r1=252652&r2=252653&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Tue Nov 10 15:40:21 2015
@@ -132,6 +132,9 @@ WebAssemblyTargetLowering::WebAssemblyTa
for (auto Op : {ISD::FCEIL, ISD::FFLOOR, ISD::FTRUNC, ISD::FNEARBYINT,
ISD::FRINT})
setOperationAction(Op, T, Legal);
+ // Support minnan and maxnan, which otherwise default to expand.
+ setOperationAction(ISD::FMINNAN, T, Legal);
+ setOperationAction(ISD::FMAXNAN, T, Legal);
}
for (auto T : {MVT::i32, MVT::i64}) {
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td?rev=252653&r1=252652&r2=252653&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrFloat.td Tue Nov 10 15:40:21 2015
@@ -22,6 +22,9 @@ defm ABS : UnaryFP<fabs, "abs">;
defm NEG : UnaryFP<fneg, "neg">;
defm COPYSIGN : BinaryFP<fcopysign, "copysign">;
+defm MIN : BinaryFP<fminnan, "min">;
+defm MAX : BinaryFP<fmaxnan, "max">;
+
defm CEIL : UnaryFP<fceil, "ceil">;
defm FLOOR : UnaryFP<ffloor, "floor">;
defm TRUNC : UnaryFP<ftrunc, "trunc">;
@@ -52,13 +55,6 @@ def : Pat<(setle f64:$lhs, f64:$rhs), (L
def : Pat<(setgt f64:$lhs, f64:$rhs), (GT_F64 f64:$lhs, f64:$rhs)>;
def : Pat<(setge f64:$lhs, f64:$rhs), (GE_F64 f64:$lhs, f64:$rhs)>;
-/*
- * TODO(jfb): Add the following for 32-bit and 64-bit.
- *
- * f32.min: minimum (binary operator); if either operand is NaN, returns NaN
- * f32.max: maximum (binary operator); if either operand is NaN, returns NaN
- */
-
def SELECT_F32 : I<(outs F32:$dst), (ins I32:$cond, F32:$lhs, F32:$rhs),
[(set F32:$dst, (select I32:$cond, F32:$lhs, F32:$rhs))],
"f32.select $dst, $cond, $lhs, $rhs">;
Modified: llvm/trunk/test/CodeGen/WebAssembly/f32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/f32.ll?rev=252653&r1=252652&r2=252653&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/f32.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/f32.ll Tue Nov 10 15:40:21 2015
@@ -126,3 +126,27 @@ define float @nearest32_via_rint(float %
%a = call float @llvm.rint.f32(float %x)
ret float %a
}
+
+; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
+; cases where there's a single fcmp with a select and it can prove that one
+; of the arms is never NaN, so we only test that case. In the future if LLVM
+; learns to form fminnan/fmaxnan in more cases, we can write more general
+; tests.
+
+; CHECK-LABEL: fmin32:
+; CHECK: f32.min push, (get_local 1), (get_local 2){{$}}
+; CHECK-NEXT: set_local 3, pop{{$}}
+define float @fmin32(float %x) {
+ %a = fcmp ult float %x, 0.0
+ %b = select i1 %a, float %x, float 0.0
+ ret float %b
+}
+
+; CHECK-LABEL: fmax32:
+; CHECK: f32.max push, (get_local 1), (get_local 2){{$}}
+; CHECK-NEXT: set_local 3, pop{{$}}
+define float @fmax32(float %x) {
+ %a = fcmp ugt float %x, 0.0
+ %b = select i1 %a, float %x, float 0.0
+ ret float %b
+}
Modified: llvm/trunk/test/CodeGen/WebAssembly/f64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/f64.ll?rev=252653&r1=252652&r2=252653&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/f64.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/f64.ll Tue Nov 10 15:40:21 2015
@@ -126,3 +126,27 @@ define double @nearest64_via_rint(double
%a = call double @llvm.rint.f64(double %x)
ret double %a
}
+
+; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
+; cases where there's a single fcmp with a select and it can prove that one
+; of the arms is never NaN, so we only test that case. In the future if LLVM
+; learns to form fminnan/fmaxnan in more cases, we can write more general
+; tests.
+
+; CHECK-LABEL: fmin64:
+; CHECK: f64.min push, (get_local 1), (get_local 2){{$}}
+; CHECK-NEXT: set_local 3, pop{{$}}
+define double @fmin64(double %x) {
+ %a = fcmp ult double %x, 0.0
+ %b = select i1 %a, double %x, double 0.0
+ ret double %b
+}
+
+; CHECK-LABEL: fmax64:
+; CHECK: f64.max push, (get_local 1), (get_local 2){{$}}
+; CHECK-NEXT: set_local 3, pop{{$}}
+define double @fmax64(double %x) {
+ %a = fcmp ugt double %x, 0.0
+ %b = select i1 %a, double %x, double 0.0
+ ret double %b
+}
More information about the llvm-commits
mailing list