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