]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Target/X86/X86InstrFPStack.td
Merge llvm-project main llvmorg-17-init-19304-gd0b54bb50e51
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Target / X86 / X86InstrFPStack.td
1 //===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file describes the X86 x87 FPU instruction set, defining the
10 // instructions, and properties of the instructions which are needed for code
11 // generation, machine code emission, and analysis.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // FPStack specific DAG Nodes.
17 //===----------------------------------------------------------------------===//
18
19 def SDTX86Fld       : SDTypeProfile<1, 1, [SDTCisFP<0>,
20                                            SDTCisPtrTy<1>]>;
21 def SDTX86Fst       : SDTypeProfile<0, 2, [SDTCisFP<0>,
22                                            SDTCisPtrTy<1>]>;
23 def SDTX86Fild      : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
24 def SDTX86Fist      : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
25
26 def SDTX86CwdStore  : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
27 def SDTX86CwdLoad   : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
28 def SDTX86FPEnv     : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
29
30 def X86fp80_add     : SDNode<"X86ISD::FP80_ADD", SDTFPBinOp, [SDNPCommutative]>;
31 def X86strict_fp80_add : SDNode<"X86ISD::STRICT_FP80_ADD", SDTFPBinOp,
32                         [SDNPHasChain,SDNPCommutative]>;
33 def any_X86fp80_add : PatFrags<(ops node:$lhs, node:$rhs),
34                                [(X86strict_fp80_add node:$lhs, node:$rhs),
35                                 (X86fp80_add node:$lhs, node:$rhs)]>;
36
37 def X86fld          : SDNode<"X86ISD::FLD", SDTX86Fld,
38                              [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
39 def X86fst          : SDNode<"X86ISD::FST", SDTX86Fst,
40                              [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
41 def X86fild         : SDNode<"X86ISD::FILD", SDTX86Fild,
42                              [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
43 def X86fist         : SDNode<"X86ISD::FIST", SDTX86Fist,
44                              [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
45 def X86fp_to_mem : SDNode<"X86ISD::FP_TO_INT_IN_MEM", SDTX86Fst,
46                           [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
47 def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m",          SDTX86CwdStore,
48                              [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
49                               SDNPMemOperand]>;
50 def X86fp_cwd_set16 : SDNode<"X86ISD::FLDCW16m",           SDTX86CwdLoad,
51                              [SDNPHasChain, SDNPMayLoad, SDNPSideEffect,
52                               SDNPMemOperand]>;
53 def X86fpenv_get    : SDNode<"X86ISD::FNSTENVm",           SDTX86FPEnv,
54                              [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
55                               SDNPMemOperand]>;
56 def X86fpenv_set    : SDNode<"X86ISD::FLDENVm",            SDTX86FPEnv,
57                              [SDNPHasChain, SDNPMayLoad, SDNPSideEffect,
58                               SDNPMemOperand]>;
59
60 def X86fstf32 : PatFrag<(ops node:$val, node:$ptr),
61                         (X86fst node:$val, node:$ptr), [{
62   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
63 }]>;
64 def X86fstf64 : PatFrag<(ops node:$val, node:$ptr),
65                         (X86fst node:$val, node:$ptr), [{
66   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
67 }]>;
68 def X86fstf80 : PatFrag<(ops node:$val, node:$ptr),
69                         (X86fst node:$val, node:$ptr), [{
70   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
71 }]>;
72
73 def X86fldf32 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
74   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
75 }]>;
76 def X86fldf64 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
77   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
78 }]>;
79 def X86fldf80 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
80   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
81 }]>;
82
83 def X86fild16 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
84   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
85 }]>;
86 def X86fild32 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
87   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
88 }]>;
89 def X86fild64 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
90   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
91 }]>;
92
93 def X86fist32 : PatFrag<(ops node:$val, node:$ptr),
94                         (X86fist node:$val, node:$ptr), [{
95   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
96 }]>;
97
98 def X86fist64 : PatFrag<(ops node:$val, node:$ptr),
99                         (X86fist node:$val, node:$ptr), [{
100   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
101 }]>;
102
103 def X86fp_to_i16mem : PatFrag<(ops node:$val, node:$ptr),
104                               (X86fp_to_mem node:$val, node:$ptr), [{
105   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
106 }]>;
107 def X86fp_to_i32mem : PatFrag<(ops node:$val, node:$ptr),
108                               (X86fp_to_mem node:$val, node:$ptr), [{
109   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
110 }]>;
111 def X86fp_to_i64mem : PatFrag<(ops node:$val, node:$ptr),
112                               (X86fp_to_mem node:$val, node:$ptr), [{
113   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
114 }]>;
115
116 //===----------------------------------------------------------------------===//
117 // FPStack pattern fragments
118 //===----------------------------------------------------------------------===//
119
120 def fpimm0 : FPImmLeaf<fAny, [{
121   return Imm.isExactlyValue(+0.0);
122 }]>;
123
124 def fpimmneg0 : FPImmLeaf<fAny, [{
125   return Imm.isExactlyValue(-0.0);
126 }]>;
127
128 def fpimm1 : FPImmLeaf<fAny, [{
129   return Imm.isExactlyValue(+1.0);
130 }]>;
131
132 def fpimmneg1 : FPImmLeaf<fAny, [{
133   return Imm.isExactlyValue(-1.0);
134 }]>;
135
136 // Some 'special' instructions - expanded after instruction selection.
137 // Clobbers EFLAGS due to OR instruction used internally.
138 // FIXME: Can we model this in SelectionDAG?
139 let usesCustomInserter = 1, hasNoSchedulingInfo = 1, Defs = [EFLAGS] in {
140   def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
141                               [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
142   def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
143                               [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
144   def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
145                               [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
146   def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
147                               [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
148   def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
149                               [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
150   def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
151                               [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
152   def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
153                               [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
154   def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
155                               [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
156   def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
157                               [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
158
159   def FP80_ADDr : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
160                           [(set RFP80:$dst,
161                                 (any_X86fp80_add  RFP80:$src1, RFP80:$src2))]>;
162   def FP80_ADDm32 : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, f32mem:$src2),
163                             [(set RFP80:$dst,
164                                   (any_X86fp80_add RFP80:$src1,
165                                                    (f80 (extloadf32 addr:$src2))))]>;
166 }
167
168 // All FP Stack operations are represented with four instructions here.  The
169 // first three instructions, generated by the instruction selector, use "RFP32"
170 // "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
171 // 64-bit or 80-bit floating point values.  These sizes apply to the values,
172 // not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
173 // copied to each other without losing information.  These instructions are all
174 // pseudo instructions and use the "_Fp" suffix.
175 // In some cases there are additional variants with a mixture of different
176 // register sizes.
177 // The second instruction is defined with FPI, which is the actual instruction
178 // emitted by the assembler.  These use "RST" registers, although frequently
179 // the actual register(s) used are implicit.  These are always 80 bits.
180 // The FP stackifier pass converts one to the other after register allocation
181 // occurs.
182 //
183 // Note that the FpI instruction should have instruction selection info (e.g.
184 // a pattern) and the FPI instruction should have emission info (e.g. opcode
185 // encoding and asm printing info).
186
187 // FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
188 // f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
189 // f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
190 // f80 instructions cannot use SSE and use neither of these.
191 class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
192              FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
193 class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
194              FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
195
196 // Factoring for arithmetic.
197 multiclass FPBinary_rr<SDPatternOperator OpNode> {
198 // Register op register -> register
199 // These are separated out because they have no reversed form.
200 def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
201                 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
202 def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
203                 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
204 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
205                 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
206 }
207 // The FopST0 series are not included here because of the irregularities
208 // in where the 'r' goes in assembly output.
209 // These instructions cannot address 80-bit memory.
210 multiclass FPBinary<SDPatternOperator OpNode, Format fp, string asmstring,
211                     bit Forward = 1> {
212 // ST(0) = ST(0) + [mem]
213 def _Fp32m  : FpIf32<(outs RFP32:$dst),
214                      (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
215                   [!if(Forward,
216                        (set RFP32:$dst,
217                         (OpNode RFP32:$src1, (loadf32 addr:$src2))),
218                        (set RFP32:$dst,
219                         (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
220 def _Fp64m  : FpIf64<(outs RFP64:$dst),
221                      (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
222                   [!if(Forward,
223                        (set RFP64:$dst,
224                         (OpNode RFP64:$src1, (loadf64 addr:$src2))),
225                        (set RFP64:$dst,
226                         (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
227 def _Fp64m32: FpIf64<(outs RFP64:$dst),
228                      (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
229                   [!if(Forward,
230                        (set RFP64:$dst,
231                         (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
232                        (set RFP64:$dst,
233                         (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
234 def _Fp80m32: FpI_<(outs RFP80:$dst),
235                    (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
236                   [!if(Forward,
237                        (set RFP80:$dst,
238                         (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
239                        (set RFP80:$dst,
240                         (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
241 def _Fp80m64: FpI_<(outs RFP80:$dst),
242                    (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
243                   [!if(Forward,
244                        (set RFP80:$dst,
245                         (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
246                        (set RFP80:$dst,
247                         (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
248 let mayLoad = 1 in
249 def _F32m  : FPI<0xD8, fp, (outs), (ins f32mem:$src),
250                  !strconcat("f", asmstring, "{s}\t$src")>;
251 let mayLoad = 1 in
252 def _F64m  : FPI<0xDC, fp, (outs), (ins f64mem:$src),
253                  !strconcat("f", asmstring, "{l}\t$src")>;
254 // ST(0) = ST(0) + [memint]
255 def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
256                        OneArgFPRW,
257                        [!if(Forward,
258                             (set RFP32:$dst,
259                              (OpNode RFP32:$src1, (X86fild16 addr:$src2))),
260                             (set RFP32:$dst,
261                              (OpNode (X86fild16 addr:$src2), RFP32:$src1)))]>;
262 def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
263                        OneArgFPRW,
264                        [!if(Forward,
265                             (set RFP32:$dst,
266                              (OpNode RFP32:$src1, (X86fild32 addr:$src2))),
267                             (set RFP32:$dst,
268                              (OpNode (X86fild32 addr:$src2), RFP32:$src1)))]>;
269 def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
270                        OneArgFPRW,
271                        [!if(Forward,
272                             (set RFP64:$dst,
273                              (OpNode RFP64:$src1, (X86fild16 addr:$src2))),
274                             (set RFP64:$dst,
275                              (OpNode (X86fild16 addr:$src2), RFP64:$src1)))]>;
276 def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
277                        OneArgFPRW,
278                        [!if(Forward,
279                             (set RFP64:$dst,
280                              (OpNode RFP64:$src1, (X86fild32 addr:$src2))),
281                             (set RFP64:$dst,
282                              (OpNode (X86fild32 addr:$src2), RFP64:$src1)))]>;
283 def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
284                      OneArgFPRW,
285                      [!if(Forward,
286                           (set RFP80:$dst,
287                            (OpNode RFP80:$src1, (X86fild16 addr:$src2))),
288                           (set RFP80:$dst,
289                            (OpNode (X86fild16 addr:$src2), RFP80:$src1)))]>;
290 def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
291                      OneArgFPRW,
292                      [!if(Forward,
293                           (set RFP80:$dst,
294                            (OpNode RFP80:$src1, (X86fild32 addr:$src2))),
295                           (set RFP80:$dst,
296                            (OpNode (X86fild32 addr:$src2), RFP80:$src1)))]>;
297 let mayLoad = 1 in
298 def _FI16m  : FPI<0xDE, fp, (outs), (ins i16mem:$src),
299                   !strconcat("fi", asmstring, "{s}\t$src")>;
300 let mayLoad = 1 in
301 def _FI32m  : FPI<0xDA, fp, (outs), (ins i32mem:$src),
302                   !strconcat("fi", asmstring, "{l}\t$src")>;
303 }
304
305 let Uses = [FPCW], mayRaiseFPException = 1 in {
306 // FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
307 // resources.
308 let hasNoSchedulingInfo = 1 in {
309 defm ADD : FPBinary_rr<any_fadd>;
310 defm SUB : FPBinary_rr<any_fsub>;
311 defm MUL : FPBinary_rr<any_fmul>;
312 defm DIV : FPBinary_rr<any_fdiv>;
313 }
314
315 // Sets the scheduling resources for the actual NAME#_F<size>m definitions.
316 let SchedRW = [WriteFAddLd] in {
317 defm ADD : FPBinary<any_fadd, MRM0m, "add">;
318 defm SUB : FPBinary<any_fsub, MRM4m, "sub">;
319 defm SUBR: FPBinary<any_fsub ,MRM5m, "subr", 0>;
320 }
321
322 let SchedRW = [WriteFMulLd] in {
323 defm MUL : FPBinary<any_fmul, MRM1m, "mul">;
324 }
325
326 let SchedRW = [WriteFDivLd] in {
327 defm DIV : FPBinary<any_fdiv, MRM6m, "div">;
328 defm DIVR: FPBinary<any_fdiv, MRM7m, "divr", 0>;
329 }
330 } // Uses = [FPCW], mayRaiseFPException = 1
331
332 class FPST0rInst<Format fp, string asm>
333   : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
334 class FPrST0Inst<Format fp, string asm>
335   : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
336 class FPrST0PInst<Format fp, string asm>
337   : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
338
339 // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
340 // of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
341 // we have to put some 'r's in and take them out of weird places.
342 let SchedRW = [WriteFAdd], Uses = [FPCW], mayRaiseFPException = 1 in {
343 def ADD_FST0r   : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
344 def ADD_FrST0   : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
345 def ADD_FPrST0  : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
346 def SUBR_FST0r  : FPST0rInst <MRM5r, "fsubr\t{$op, %st|st, $op}">;
347 def SUB_FrST0   : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
348 def SUB_FPrST0  : FPrST0PInst<MRM5r, "fsub{r}p\t{%st, $op|$op, st}">;
349 def SUB_FST0r   : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
350 def SUBR_FrST0  : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
351 def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
352 } // SchedRW
353 let SchedRW = [WriteFCom], Uses = [FPCW], mayRaiseFPException = 1 in {
354 def COM_FST0r   : FPST0rInst <MRM2r, "fcom\t$op">;
355 def COMP_FST0r  : FPST0rInst <MRM3r, "fcomp\t$op">;
356 } // SchedRW
357 let SchedRW = [WriteFMul], Uses = [FPCW], mayRaiseFPException = 1 in {
358 def MUL_FST0r   : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
359 def MUL_FrST0   : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
360 def MUL_FPrST0  : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
361 } // SchedRW
362 let SchedRW = [WriteFDiv], Uses = [FPCW], mayRaiseFPException = 1 in {
363 def DIVR_FST0r  : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
364 def DIV_FrST0   : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
365 def DIV_FPrST0  : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
366 def DIV_FST0r   : FPST0rInst <MRM6r, "fdiv\t{$op, %st|st, $op}">;
367 def DIVR_FrST0  : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
368 def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t{%st, $op|$op, st}">;
369 } // SchedRW
370
371 // Unary operations.
372 multiclass FPUnary<SDPatternOperator OpNode, Format fp, string asmstring> {
373 def _Fp32  : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
374                  [(set RFP32:$dst, (OpNode RFP32:$src))]>;
375 def _Fp64  : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
376                  [(set RFP64:$dst, (OpNode RFP64:$src))]>;
377 def _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
378                  [(set RFP80:$dst, (OpNode RFP80:$src))]>;
379 def _F     : FPI<0xD9, fp, (outs), (ins), asmstring>;
380 }
381
382 let SchedRW = [WriteFSign] in {
383 defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
384 defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
385 }
386
387 let Uses = [FPCW], mayRaiseFPException = 1 in {
388 let SchedRW = [WriteFSqrt80] in
389 defm SQRT: FPUnary<any_fsqrt,MRM_FA, "fsqrt">;
390
391 let SchedRW = [WriteFCom] in {
392 let hasSideEffects = 0 in {
393 def TST_Fp32  : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
394 def TST_Fp64  : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
395 def TST_Fp80  : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
396 } // hasSideEffects
397
398 def TST_F  : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
399 } // SchedRW
400 } // Uses = [FPCW], mayRaiseFPException = 1
401
402 let SchedRW = [WriteFTest], Defs = [FPSW] in {
403 def XAM_Fp32  : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
404 def XAM_Fp64  : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
405 def XAM_Fp80  : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
406 def XAM_F     : FPI<0xD9, MRM_E5, (outs), (ins), "fxam">;
407 } // SchedRW
408
409 // Versions of FP instructions that take a single memory operand.  Added for the
410 //   disassembler; remove as they are included with patterns elsewhere.
411 let SchedRW = [WriteFComLd], Uses = [FPCW], mayRaiseFPException = 1,
412     mayLoad = 1 in {
413 def FCOM32m  : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
414 def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
415
416 def FCOM64m  : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
417 def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
418
419 def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
420 def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
421
422 def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
423 def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
424 } // SchedRW
425
426 let SchedRW = [WriteMicrocoded] in {
427 let Defs = [FPSW, FPCW], mayLoad = 1 in {
428 def FRSTORm  : FPI<0xDD, MRM4m, (outs), (ins anymem:$src), "frstor\t$src">;
429 let Predicates = [HasX87] in
430 def FLDENVm  : I<0xD9, MRM4m, (outs), (ins anymem:$src), "fldenv\t$src",
431                  [(X86fpenv_set addr:$src)]>;
432 }
433
434 let Defs = [FPSW, FPCW], Uses = [FPSW, FPCW], mayStore = 1 in {
435 def FSAVEm   : FPI<0xDD, MRM6m, (outs), (ins anymem:$dst), "fnsave\t$dst">;
436 let Predicates = [HasX87] in
437 def FSTENVm  : I<0xD9, MRM6m, (outs), (ins anymem:$dst), "fnstenv\t$dst",
438                  [(X86fpenv_get addr:$dst)]>;
439 }
440
441 let Uses = [FPSW], mayStore = 1 in
442 def FNSTSWm  : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
443
444 let mayLoad = 1 in
445 def FBLDm    : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
446 let Uses = [FPCW] ,mayRaiseFPException = 1, mayStore = 1 in
447 def FBSTPm   : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
448 } // SchedRW
449
450 // Floating point cmovs.
451 class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
452   FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMOV]>;
453 class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
454   FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMOV]>;
455
456 multiclass FPCMov<PatLeaf cc> {
457   def _Fp32  : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
458                        CondMovFP,
459                      [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
460                                         cc, EFLAGS))]>;
461   def _Fp64  : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
462                        CondMovFP,
463                      [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
464                                         cc, EFLAGS))]>;
465   def _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
466                      CondMovFP,
467                      [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
468                                         cc, EFLAGS))]>,
469                                         Requires<[HasCMOV]>;
470 }
471
472 let SchedRW = [WriteFCMOV] in {
473 let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
474 defm CMOVB  : FPCMov<X86_COND_B>;
475 defm CMOVBE : FPCMov<X86_COND_BE>;
476 defm CMOVE  : FPCMov<X86_COND_E>;
477 defm CMOVP  : FPCMov<X86_COND_P>;
478 defm CMOVNB : FPCMov<X86_COND_AE>;
479 defm CMOVNBE: FPCMov<X86_COND_A>;
480 defm CMOVNE : FPCMov<X86_COND_NE>;
481 defm CMOVNP : FPCMov<X86_COND_NP>;
482 } // Uses = [EFLAGS], Constraints = "$src1 = $dst"
483
484 let Predicates = [HasCMOV] in {
485 // These are not factored because there's no clean way to pass DA/DB.
486 def CMOVB_F  : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
487                   "fcmovb\t{$op, %st|st, $op}">;
488 def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
489                   "fcmovbe\t{$op, %st|st, $op}">;
490 def CMOVE_F  : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
491                   "fcmove\t{$op, %st|st, $op}">;
492 def CMOVP_F  : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
493                   "fcmovu\t{$op, %st|st, $op}">;
494 def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
495                   "fcmovnb\t{$op, %st|st, $op}">;
496 def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
497                   "fcmovnbe\t{$op, %st|st, $op}">;
498 def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
499                   "fcmovne\t{$op, %st|st, $op}">;
500 def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
501                   "fcmovnu\t{$op, %st|st, $op}">;
502 } // Predicates = [HasCMOV]
503 } // SchedRW
504
505 let mayRaiseFPException = 1 in {
506 // Floating point loads & stores.
507 let SchedRW = [WriteLoad], Uses = [FPCW] in {
508 let canFoldAsLoad = 1 in {
509 def LD_Fp32m   : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
510                   [(set RFP32:$dst, (loadf32 addr:$src))]>;
511 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
512                   [(set RFP64:$dst, (loadf64 addr:$src))]>;
513 def LD_Fp80m   : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
514                   [(set RFP80:$dst, (loadf80 addr:$src))]>;
515 } // canFoldAsLoad
516 def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
517                   [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
518 def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
519                   [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
520 def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
521                   [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
522 let mayRaiseFPException = 0 in {
523 def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
524                   [(set RFP32:$dst, (X86fild16 addr:$src))]>;
525 def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
526                   [(set RFP32:$dst, (X86fild32 addr:$src))]>;
527 def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
528                   [(set RFP32:$dst, (X86fild64 addr:$src))]>;
529 def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
530                   [(set RFP64:$dst, (X86fild16 addr:$src))]>;
531 def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
532                   [(set RFP64:$dst, (X86fild32 addr:$src))]>;
533 def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
534                   [(set RFP64:$dst, (X86fild64 addr:$src))]>;
535 def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
536                   [(set RFP80:$dst, (X86fild16 addr:$src))]>;
537 def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
538                   [(set RFP80:$dst, (X86fild32 addr:$src))]>;
539 def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
540                   [(set RFP80:$dst, (X86fild64 addr:$src))]>;
541 } // mayRaiseFPException = 0
542 } // SchedRW
543
544 let SchedRW = [WriteStore], Uses = [FPCW] in {
545 def ST_Fp32m   : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
546                   [(store RFP32:$src, addr:$op)]>;
547 def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
548                   [(truncstoref32 RFP64:$src, addr:$op)]>;
549 def ST_Fp64m   : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
550                   [(store RFP64:$src, addr:$op)]>;
551 def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
552                   [(truncstoref32 RFP80:$src, addr:$op)]>;
553 def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
554                   [(truncstoref64 RFP80:$src, addr:$op)]>;
555 // FST does not support 80-bit memory target; FSTP must be used.
556
557 let mayStore = 1, hasSideEffects = 0 in {
558 def ST_FpP32m    : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
559 def ST_FpP64m32  : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
560 def ST_FpP64m    : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
561 def ST_FpP80m32  : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
562 def ST_FpP80m64  : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
563 } // mayStore
564
565 def ST_FpP80m    : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
566                     [(store RFP80:$src, addr:$op)]>;
567
568 let mayStore = 1, hasSideEffects = 0 in {
569 def IST_Fp16m32  : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
570 def IST_Fp32m32  : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
571                           [(X86fist32 RFP32:$src, addr:$op)]>;
572 def IST_Fp64m32  : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
573                           [(X86fist64 RFP32:$src, addr:$op)]>;
574 def IST_Fp16m64  : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
575 def IST_Fp32m64  : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
576                           [(X86fist32 RFP64:$src, addr:$op)]>;
577 def IST_Fp64m64  : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
578                           [(X86fist64 RFP64:$src, addr:$op)]>;
579 def IST_Fp16m80  : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
580 def IST_Fp32m80  : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
581                         [(X86fist32 RFP80:$src, addr:$op)]>;
582 def IST_Fp64m80  : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
583                         [(X86fist64 RFP80:$src, addr:$op)]>;
584 } // mayStore
585 } // SchedRW, Uses = [FPCW]
586
587 let mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
588 def LD_F32m   : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
589 def LD_F64m   : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
590 def LD_F80m   : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
591 let mayRaiseFPException = 0 in {
592 def ILD_F16m  : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
593 def ILD_F32m  : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
594 def ILD_F64m  : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
595 }
596 }
597 let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
598 def ST_F32m   : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
599 def ST_F64m   : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
600 def ST_FP32m  : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
601 def ST_FP64m  : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
602 def ST_FP80m  : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
603 def IST_F16m  : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
604 def IST_F32m  : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
605 def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
606 def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
607 def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
608 }
609
610 // FISTTP requires SSE3 even though it's a FPStack op.
611 let Predicates = [HasSSE3], SchedRW = [WriteStore], Uses = [FPCW] in {
612 def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
613                     [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
614 def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
615                     [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
616 def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
617                     [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
618 def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
619                     [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
620 def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
621                     [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
622 def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
623                     [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
624 def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
625                     [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
626 def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
627                     [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
628 def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
629                     [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
630 } // Predicates = [HasSSE3]
631
632 let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
633 def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
634 def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
635 def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
636 }
637
638 // FP Stack manipulation instructions.
639 let SchedRW = [WriteMove], Uses = [FPCW] in {
640 def LD_Frr   : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
641 def ST_Frr   : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
642 def ST_FPrr  : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
643 let mayRaiseFPException = 0 in
644 def XCH_F    : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
645 }
646
647 // Floating point constant loads.
648 let SchedRW = [WriteZero], Uses = [FPCW] in {
649 def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
650                 [(set RFP32:$dst, fpimm0)]>;
651 def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
652                 [(set RFP32:$dst, fpimm1)]>;
653 def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
654                 [(set RFP64:$dst, fpimm0)]>;
655 def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
656                 [(set RFP64:$dst, fpimm1)]>;
657 def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
658                 [(set RFP80:$dst, fpimm0)]>;
659 def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
660                 [(set RFP80:$dst, fpimm1)]>;
661 }
662
663 let SchedRW = [WriteFLD0], Uses = [FPCW], mayRaiseFPException = 0 in
664 def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
665
666 let SchedRW = [WriteFLD1], Uses = [FPCW], mayRaiseFPException = 0 in
667 def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
668
669 let SchedRW = [WriteFLDC], Defs = [FPSW], Uses = [FPCW], mayRaiseFPException = 0 in {
670 def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
671 def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
672 def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
673 def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
674 def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
675 } // SchedRW
676
677 // Floating point compares.
678 let SchedRW = [WriteFCom], Uses = [FPCW], hasSideEffects = 0 in {
679 def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
680 def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
681 def UCOM_Fpr80 : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
682 def COM_Fpr32  : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
683 def COM_Fpr64  : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
684 def COM_Fpr80  : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
685 } // SchedRW
686 } // mayRaiseFPException = 1
687
688 let SchedRW = [WriteFCom], mayRaiseFPException = 1 in {
689 // CC = ST(0) cmp ST(i)
690 let Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
691 def UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
692                   [(set EFLAGS, (X86any_fcmp RFP32:$lhs, RFP32:$rhs))]>,
693                   Requires<[FPStackf32, HasCMOV]>;
694 def UCOM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
695                   [(set EFLAGS, (X86any_fcmp RFP64:$lhs, RFP64:$rhs))]>,
696                   Requires<[FPStackf64, HasCMOV]>;
697 def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
698                   [(set EFLAGS, (X86any_fcmp RFP80:$lhs, RFP80:$rhs))]>,
699                   Requires<[HasCMOV]>;
700 def COM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
701                   [(set EFLAGS, (X86strict_fcmps RFP32:$lhs, RFP32:$rhs))]>,
702                   Requires<[FPStackf32, HasCMOV]>;
703 def COM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
704                   [(set EFLAGS, (X86strict_fcmps RFP64:$lhs, RFP64:$rhs))]>,
705                   Requires<[FPStackf64, HasCMOV]>;
706 def COM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
707                   [(set EFLAGS, (X86strict_fcmps RFP80:$lhs, RFP80:$rhs))]>,
708                   Requires<[HasCMOV]>;
709 }
710
711 let Uses = [ST0, FPCW] in {
712 def UCOM_Fr    : FPI<0xDD, MRM4r,    // FPSW = cmp ST(0) with ST(i)
713                     (outs), (ins RSTi:$reg), "fucom\t$reg">;
714 def UCOM_FPr   : FPI<0xDD, MRM5r,    // FPSW = cmp ST(0) with ST(i), pop
715                     (outs), (ins RSTi:$reg), "fucomp\t$reg">;
716 def UCOM_FPPr  : FPI<0xDA, MRM_E9,       // cmp ST(0) with ST(1), pop, pop
717                     (outs), (ins), "fucompp">;
718 }
719
720 let Defs = [EFLAGS, FPSW], Uses = [ST0, FPCW] in {
721 def UCOM_FIr   : FPI<0xDB, MRM5r,     // CC = cmp ST(0) with ST(i)
722                     (outs), (ins RSTi:$reg), "fucomi\t{$reg, %st|st, $reg}">;
723 def UCOM_FIPr  : FPI<0xDF, MRM5r,     // CC = cmp ST(0) with ST(i), pop
724                     (outs), (ins RSTi:$reg), "fucompi\t{$reg, %st|st, $reg}">;
725
726 def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg),
727                   "fcomi\t{$reg, %st|st, $reg}">;
728 def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
729                    "fcompi\t{$reg, %st|st, $reg}">;
730 }
731 } // SchedRW
732
733 // Floating point flag ops.
734 let SchedRW = [WriteALU] in {
735 let Defs = [AX, FPSW], Uses = [FPSW], hasSideEffects = 0 in
736 def FNSTSW16r : I<0xDF, MRM_E0,                  // AX = fp flags
737                   (outs), (ins), "fnstsw\t{%ax|ax}", []>;
738 let Defs = [FPSW], Uses = [FPCW] in
739 def FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
740                   (outs), (ins i16mem:$dst), "fnstcw\t$dst",
741                   [(X86fp_cwd_get16 addr:$dst)]>;
742 } // SchedRW
743 let Defs = [FPSW,FPCW], mayLoad = 1 in
744 def FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
745                   (outs), (ins i16mem:$dst), "fldcw\t$dst",
746                   [(X86fp_cwd_set16 addr:$dst)]>,
747                 Sched<[WriteLoad]>;
748
749 // FPU control instructions
750 let SchedRW = [WriteMicrocoded] in {
751 def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
752 def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
753
754 let Defs = [FPSW, FPCW] in
755 def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
756 // Clear exceptions
757 let Defs = [FPSW] in
758 def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
759 } // SchedRW
760
761 // Operand-less floating-point instructions for the disassembler.
762 let Defs = [FPSW] in
763 def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
764
765 let SchedRW = [WriteMicrocoded] in {
766 let Defs = [FPSW] in {
767 def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
768 def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
769 def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
770 let Uses = [FPCW], mayRaiseFPException = 1 in {
771 def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
772 def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
773 def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
774 def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
775 def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
776 def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
777 def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
778 def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
779 def FSIN : I<0xD9, MRM_FE, (outs), (ins), "fsin", []>;
780 def FCOS : I<0xD9, MRM_FF, (outs), (ins), "fcos", []>;
781 def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
782 def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
783 def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
784 def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
785 } // Uses = [FPCW], mayRaiseFPException = 1
786 } // Defs = [FPSW]
787
788 let Uses = [FPSW, FPCW] in {
789 def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
790              "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, PS,
791              Requires<[HasFXSR]>;
792 def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
793                "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
794                PS, Requires<[HasFXSR, In64BitMode]>;
795 } // Uses = [FPSW, FPCW]
796
797 let Defs = [FPSW, FPCW] in {
798 def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
799               "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
800               PS, Requires<[HasFXSR]>;
801 def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
802                 "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
803                 PS, Requires<[HasFXSR, In64BitMode]>;
804 } // Defs = [FPSW, FPCW]
805 } // SchedRW
806
807 //===----------------------------------------------------------------------===//
808 // Non-Instruction Patterns
809 //===----------------------------------------------------------------------===//
810
811 // Required for RET of f32 / f64 / f80 values.
812 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m addr:$src)>;
813 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m64 addr:$src)>;
814 def : Pat<(X86fldf64 addr:$src), (LD_Fp64m addr:$src)>;
815 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m80 addr:$src)>;
816 def : Pat<(X86fldf64 addr:$src), (LD_Fp64m80 addr:$src)>;
817 def : Pat<(X86fldf80 addr:$src), (LD_Fp80m addr:$src)>;
818
819 // Required for CALL which return f32 / f64 / f80 values.
820 def : Pat<(X86fstf32 RFP32:$src, addr:$op), (ST_Fp32m addr:$op, RFP32:$src)>;
821 def : Pat<(X86fstf32 RFP64:$src, addr:$op), (ST_Fp64m32 addr:$op, RFP64:$src)>;
822 def : Pat<(X86fstf64 RFP64:$src, addr:$op), (ST_Fp64m addr:$op, RFP64:$src)>;
823 def : Pat<(X86fstf32 RFP80:$src, addr:$op), (ST_Fp80m32 addr:$op, RFP80:$src)>;
824 def : Pat<(X86fstf64 RFP80:$src, addr:$op), (ST_Fp80m64 addr:$op, RFP80:$src)>;
825 def : Pat<(X86fstf80 RFP80:$src, addr:$op), (ST_FpP80m addr:$op, RFP80:$src)>;
826
827 // Floating point constant -0.0 and -1.0
828 def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
829 def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
830 def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
831 def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
832 def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
833 def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
834
835 // FP extensions map onto simple pseudo-value conversions if they are to/from
836 // the FP stack.
837 def : Pat<(f64 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
838           Requires<[FPStackf32]>;
839 def : Pat<(f80 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
840            Requires<[FPStackf32]>;
841 def : Pat<(f80 (any_fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
842            Requires<[FPStackf64]>;
843
844 // FP truncations map onto simple pseudo-value conversions if they are to/from
845 // the FP stack.  We have validated that only value-preserving truncations make
846 // it through isel.
847 def : Pat<(f32 (any_fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
848           Requires<[FPStackf32]>;
849 def : Pat<(f32 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
850            Requires<[FPStackf32]>;
851 def : Pat<(f64 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
852            Requires<[FPStackf64]>;