blob: 64569720375c4f5f5ebd2da54a2267e7309b6354 [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001// WebAssemblyInstrFloat.td-WebAssembly Float codegen support ---*- tablegen -*-
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief WebAssembly Floating-point operand code-gen constructs.
12///
13//===----------------------------------------------------------------------===//
14
Dan Gohmanfb3e0592015-11-25 19:36:19 +000015let Defs = [ARGUMENTS] in {
16
Dan Gohman174b2d82015-11-29 22:59:19 +000017let isCommutable = 1 in
Dan Gohman1f29c682015-11-18 16:25:38 +000018defm ADD : BinaryFP<fadd, "add ">;
19defm SUB : BinaryFP<fsub, "sub ">;
Dan Gohman174b2d82015-11-29 22:59:19 +000020let isCommutable = 1 in
Dan Gohman1f29c682015-11-18 16:25:38 +000021defm MUL : BinaryFP<fmul, "mul ">;
22defm DIV : BinaryFP<fdiv, "div ">;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000023defm SQRT : UnaryFP<fsqrt, "sqrt">;
Dan Gohman896e53f2015-08-24 18:23:13 +000024
Dan Gohman1f29c682015-11-18 16:25:38 +000025defm ABS : UnaryFP<fabs, "abs ">;
26defm NEG : UnaryFP<fneg, "neg ">;
Dan Gohmanaf29bd42015-11-05 20:42:30 +000027defm COPYSIGN : BinaryFP<fcopysign, "copysign">;
JF Bastienef172fc2015-08-11 02:45:15 +000028
Dan Gohman174b2d82015-11-29 22:59:19 +000029let isCommutable = 1 in {
Dan Gohman1f29c682015-11-18 16:25:38 +000030defm MIN : BinaryFP<fminnan, "min ">;
31defm MAX : BinaryFP<fmaxnan, "max ">;
Dan Gohman174b2d82015-11-29 22:59:19 +000032} // isCommutable = 1
Dan Gohmanb84ae9b2015-11-10 21:40:21 +000033
Dan Gohmanaf29bd42015-11-05 20:42:30 +000034defm CEIL : UnaryFP<fceil, "ceil">;
35defm FLOOR : UnaryFP<ffloor, "floor">;
36defm TRUNC : UnaryFP<ftrunc, "trunc">;
37defm NEAREST : UnaryFP<fnearbyint, "nearest">;
Dan Gohman896e53f2015-08-24 18:23:13 +000038
Dan Gohmanfb3e0592015-11-25 19:36:19 +000039} // Defs = [ARGUMENTS]
40
Dan Gohmanf170ba02015-12-10 04:55:31 +000041// DAGCombine oddly folds casts into the rhs of copysign. Unfold them.
42def : Pat<(fcopysign F64:$lhs, F32:$rhs),
43 (COPYSIGN_F64 F64:$lhs, (F64_PROMOTE_F32 F32:$rhs))>;
44def : Pat<(fcopysign F32:$lhs, F64:$rhs),
45 (COPYSIGN_F32 F32:$lhs, (F32_DEMOTE_F64 F64:$rhs))>;
46
Dan Gohman896e53f2015-08-24 18:23:13 +000047// WebAssembly doesn't expose inexact exceptions, so map frint to fnearbyint.
Dan Gohmand0bf9812015-09-26 01:09:44 +000048def : Pat<(frint f32:$src), (NEAREST_F32 f32:$src)>;
49def : Pat<(frint f64:$src), (NEAREST_F64 f64:$src)>;
JF Bastiend9767a32015-07-14 21:13:29 +000050
Dan Gohmanfb3e0592015-11-25 19:36:19 +000051let Defs = [ARGUMENTS] in {
52
Dan Gohman174b2d82015-11-29 22:59:19 +000053let isCommutable = 1 in {
Dan Gohman1f29c682015-11-18 16:25:38 +000054defm EQ : ComparisonFP<SETOEQ, "eq ">;
55defm NE : ComparisonFP<SETUNE, "ne ">;
Dan Gohman174b2d82015-11-29 22:59:19 +000056} // isCommutable = 1
Dan Gohman1f29c682015-11-18 16:25:38 +000057defm LT : ComparisonFP<SETOLT, "lt ">;
58defm LE : ComparisonFP<SETOLE, "le ">;
59defm GT : ComparisonFP<SETOGT, "gt ">;
60defm GE : ComparisonFP<SETOGE, "ge ">;
JF Bastiend9767a32015-07-14 21:13:29 +000061
Dan Gohmanfb3e0592015-11-25 19:36:19 +000062} // Defs = [ARGUMENTS]
63
JF Bastien71d29ac2015-08-12 17:53:29 +000064// Don't care floating-point comparisons, supported via other comparisons.
65def : Pat<(seteq f32:$lhs, f32:$rhs), (EQ_F32 f32:$lhs, f32:$rhs)>;
66def : Pat<(setne f32:$lhs, f32:$rhs), (NE_F32 f32:$lhs, f32:$rhs)>;
67def : Pat<(setlt f32:$lhs, f32:$rhs), (LT_F32 f32:$lhs, f32:$rhs)>;
68def : Pat<(setle f32:$lhs, f32:$rhs), (LE_F32 f32:$lhs, f32:$rhs)>;
69def : Pat<(setgt f32:$lhs, f32:$rhs), (GT_F32 f32:$lhs, f32:$rhs)>;
70def : Pat<(setge f32:$lhs, f32:$rhs), (GE_F32 f32:$lhs, f32:$rhs)>;
71def : Pat<(seteq f64:$lhs, f64:$rhs), (EQ_F64 f64:$lhs, f64:$rhs)>;
72def : Pat<(setne f64:$lhs, f64:$rhs), (NE_F64 f64:$lhs, f64:$rhs)>;
73def : Pat<(setlt f64:$lhs, f64:$rhs), (LT_F64 f64:$lhs, f64:$rhs)>;
74def : Pat<(setle f64:$lhs, f64:$rhs), (LE_F64 f64:$lhs, f64:$rhs)>;
75def : Pat<(setgt f64:$lhs, f64:$rhs), (GT_F64 f64:$lhs, f64:$rhs)>;
76def : Pat<(setge f64:$lhs, f64:$rhs), (GE_F64 f64:$lhs, f64:$rhs)>;
77
Dan Gohmanfb3e0592015-11-25 19:36:19 +000078let Defs = [ARGUMENTS] in {
79
Dan Gohmand46b0922016-02-05 17:14:59 +000080def SELECT_F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs, I32:$cond),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000081 [(set F32:$dst, (select I32:$cond, F32:$lhs, F32:$rhs))],
Dan Gohmand46b0922016-02-05 17:14:59 +000082 "f32.select\t$dst, $lhs, $rhs, $cond">;
83def SELECT_F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs, I32:$cond),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000084 [(set F64:$dst, (select I32:$cond, F64:$lhs, F64:$rhs))],
Dan Gohmand46b0922016-02-05 17:14:59 +000085 "f64.select\t$dst, $lhs, $rhs, $cond">;
Dan Gohmanfb3e0592015-11-25 19:36:19 +000086
87} // Defs = [ARGUMENTS]
Dan Gohmand9b42182015-11-25 22:13:48 +000088
89// ISD::SELECT requires its operand to conform to getBooleanContents, but
90// WebAssembly's select interprets any non-zero value as true, so we can fold
91// a setne with 0 into a select.
92def : Pat<(select (i32 (setne I32:$cond, 0)), F32:$lhs, F32:$rhs),
Dan Gohmand46b0922016-02-05 17:14:59 +000093 (SELECT_F32 F32:$lhs, F32:$rhs, I32:$cond)>;
Dan Gohmand9b42182015-11-25 22:13:48 +000094def : Pat<(select (i32 (setne I32:$cond, 0)), F64:$lhs, F64:$rhs),
Dan Gohmand46b0922016-02-05 17:14:59 +000095 (SELECT_F64 F64:$lhs, F64:$rhs, I32:$cond)>;
Dan Gohmand9b42182015-11-25 22:13:48 +000096
97// And again, this time with seteq instead of setne and the arms reversed.
98def : Pat<(select (i32 (seteq I32:$cond, 0)), F32:$lhs, F32:$rhs),
Dan Gohmand46b0922016-02-05 17:14:59 +000099 (SELECT_F32 F32:$rhs, F32:$lhs, I32:$cond)>;
Dan Gohmand9b42182015-11-25 22:13:48 +0000100def : Pat<(select (i32 (seteq I32:$cond, 0)), F64:$lhs, F64:$rhs),
Dan Gohmand46b0922016-02-05 17:14:59 +0000101 (SELECT_F64 F64:$rhs, F64:$lhs, I32:$cond)>;