Lower MEMBARRIER on x86 and support processors without SSE2.
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===----------------------------------------------------------------------===//
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 // This file describes the X86 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 // X86 specific DAG Nodes.
18 //
19
20 def SDTIntShiftDOp: SDTypeProfile<1, 3,
21                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22                                    SDTCisInt<0>, SDTCisInt<3>]>;
23
24 def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
29
30 // Unary and binary operator instructions that set EFLAGS as a side-effect.
31 def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
32                                            [SDTCisInt<0>, SDTCisVT<1, i32>]>;
33
34 def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
35                                             [SDTCisSameAs<0, 2>,
36                                              SDTCisSameAs<0, 3>,
37                                              SDTCisInt<0>, SDTCisVT<1, i32>]>;
38 def SDTX86BrCond  : SDTypeProfile<0, 3,
39                                   [SDTCisVT<0, OtherVT>,
40                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
41
42 def SDTX86SetCC   : SDTypeProfile<1, 2,
43                                   [SDTCisVT<0, i8>,
44                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
45 def SDTX86SetCC_C : SDTypeProfile<1, 2,
46                                   [SDTCisInt<0>,
47                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
48
49 def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 
50                                      SDTCisVT<2, i8>]>;
51 def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
52
53 def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
54                                 SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
55 def SDTX86Ret     : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
56
57 def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
58 def SDT_X86CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>,
59                                         SDTCisVT<1, i32>]>;
60
61 def SDT_X86Call   : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
62
63 def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
64                                                          SDTCisVT<1, iPTR>,
65                                                          SDTCisVT<2, iPTR>]>;
66
67 def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
68
69 def SDTX86Void    : SDTypeProfile<0, 0, []>;
70
71 def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
72
73 def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
74
75 def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
76
77 def SDT_X86SegmentBaseAddress : SDTypeProfile<1, 1, [SDTCisPtrTy<0>]>;
78
79 def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
80
81 def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
82
83 def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>;
84 def SDT_X86MEMBARRIERNoSSE : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
85
86 def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER,
87                             [SDNPHasChain]>;
88 def X86MemBarrierNoSSE : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIERNoSSE,
89                                 [SDNPHasChain]>;
90
91 def X86bsf     : SDNode<"X86ISD::BSF",      SDTUnaryArithWithFlags>;
92 def X86bsr     : SDNode<"X86ISD::BSR",      SDTUnaryArithWithFlags>;
93 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
94 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
95
96 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
97 def X86bt      : SDNode<"X86ISD::BT",       SDTX86CmpTest>;
98
99 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
100 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
101                         [SDNPHasChain]>;
102 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
103 def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
104
105 def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
106                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
107                          SDNPMayLoad]>;
108 def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
109                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
110                          SDNPMayLoad]>;
111 def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
112                         [SDNPHasChain, SDNPMayStore, 
113                          SDNPMayLoad, SDNPMemOperand]>;
114 def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
115                         [SDNPHasChain, SDNPMayStore, 
116                          SDNPMayLoad, SDNPMemOperand]>;
117 def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
118                         [SDNPHasChain, SDNPMayStore, 
119                          SDNPMayLoad, SDNPMemOperand]>;
120 def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
121                         [SDNPHasChain, SDNPMayStore, 
122                          SDNPMayLoad, SDNPMemOperand]>;
123 def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
124                         [SDNPHasChain, SDNPMayStore, 
125                          SDNPMayLoad, SDNPMemOperand]>;
126 def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
127                         [SDNPHasChain, SDNPMayStore, 
128                          SDNPMayLoad, SDNPMemOperand]>;
129 def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
130                         [SDNPHasChain, SDNPMayStore, 
131                          SDNPMayLoad, SDNPMemOperand]>;
132 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
133                         [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
134
135 def X86vastart_save_xmm_regs :
136                  SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
137                         SDT_X86VASTART_SAVE_XMM_REGS,
138                         [SDNPHasChain, SDNPVariadic]>;
139
140 def X86callseq_start :
141                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
142                         [SDNPHasChain, SDNPOutFlag]>;
143 def X86callseq_end :
144                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
145                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
146
147 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
148                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
149                          SDNPVariadic]>;
150
151 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
152                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
153 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
154                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
155                          SDNPMayLoad]>;
156
157 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
158                         [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
159
160 def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
161 def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
162
163 def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
164                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
165 def X86SegmentBaseAddress : SDNode<"X86ISD::SegmentBaseAddress",
166                                  SDT_X86SegmentBaseAddress, []>;
167
168 def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
169                         [SDNPHasChain]>;
170
171 def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
172                         [SDNPHasChain,  SDNPOptInFlag, SDNPVariadic]>;
173
174 def X86add_flag  : SDNode<"X86ISD::ADD",  SDTBinaryArithWithFlags,
175                           [SDNPCommutative]>;
176 def X86sub_flag  : SDNode<"X86ISD::SUB",  SDTBinaryArithWithFlags>;
177 def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
178                           [SDNPCommutative]>;
179 def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
180                           [SDNPCommutative]>;
181                           
182 def X86inc_flag  : SDNode<"X86ISD::INC",  SDTUnaryArithWithFlags>;
183 def X86dec_flag  : SDNode<"X86ISD::DEC",  SDTUnaryArithWithFlags>;
184 def X86or_flag   : SDNode<"X86ISD::OR",   SDTBinaryArithWithFlags,
185                           [SDNPCommutative]>;
186 def X86xor_flag  : SDNode<"X86ISD::XOR",  SDTBinaryArithWithFlags,
187                           [SDNPCommutative]>;
188 def X86and_flag  : SDNode<"X86ISD::AND",  SDTBinaryArithWithFlags,
189                           [SDNPCommutative]>;
190
191 def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
192
193 def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
194                             [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
195                             
196 def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
197                         []>;
198
199 //===----------------------------------------------------------------------===//
200 // X86 Operand Definitions.
201 //
202
203 // A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
204 // the index operand of an address, to conform to x86 encoding restrictions.
205 def ptr_rc_nosp : PointerLikeRegClass<1>;
206
207 // *mem - Operand definitions for the funky X86 addressing mode operands.
208 //
209 def X86MemAsmOperand : AsmOperandClass {
210   let Name = "Mem";
211   let SuperClasses = [];
212 }
213 def X86AbsMemAsmOperand : AsmOperandClass {
214   let Name = "AbsMem";
215   let SuperClasses = [X86MemAsmOperand];
216 }
217 class X86MemOperand<string printMethod> : Operand<iPTR> {
218   let PrintMethod = printMethod;
219   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
220   let ParserMatchClass = X86MemAsmOperand;
221 }
222
223 def opaque32mem : X86MemOperand<"printopaquemem">;
224 def opaque48mem : X86MemOperand<"printopaquemem">;
225 def opaque80mem : X86MemOperand<"printopaquemem">;
226 def opaque512mem : X86MemOperand<"printopaquemem">;
227
228 def i8mem   : X86MemOperand<"printi8mem">;
229 def i16mem  : X86MemOperand<"printi16mem">;
230 def i32mem  : X86MemOperand<"printi32mem">;
231 def i64mem  : X86MemOperand<"printi64mem">;
232 def i128mem : X86MemOperand<"printi128mem">;
233 def i256mem : X86MemOperand<"printi256mem">;
234 def f32mem  : X86MemOperand<"printf32mem">;
235 def f64mem  : X86MemOperand<"printf64mem">;
236 def f80mem  : X86MemOperand<"printf80mem">;
237 def f128mem : X86MemOperand<"printf128mem">;
238 def f256mem : X86MemOperand<"printf256mem">;
239
240 // A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
241 // plain GR64, so that it doesn't potentially require a REX prefix.
242 def i8mem_NOREX : Operand<i64> {
243   let PrintMethod = "printi8mem";
244   let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
245   let ParserMatchClass = X86MemAsmOperand;
246 }
247
248 // Special i32mem for addresses of load folding tail calls. These are not
249 // allowed to use callee-saved registers since they must be scheduled
250 // after callee-saved register are popped.
251 def i32mem_TC : Operand<i32> {
252   let PrintMethod = "printi32mem";
253   let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
254   let ParserMatchClass = X86MemAsmOperand;
255 }
256
257
258 let ParserMatchClass = X86AbsMemAsmOperand,
259     PrintMethod = "print_pcrel_imm" in {
260 def i32imm_pcrel : Operand<i32>;
261 def i16imm_pcrel : Operand<i16>;
262
263 def offset8 : Operand<i64>;
264 def offset16 : Operand<i64>;
265 def offset32 : Operand<i64>;
266 def offset64 : Operand<i64>;
267
268 // Branch targets have OtherVT type and print as pc-relative values.
269 def brtarget : Operand<OtherVT>;
270 def brtarget8 : Operand<OtherVT>;
271
272 }
273
274 def SSECC : Operand<i8> {
275   let PrintMethod = "printSSECC";
276 }
277
278 class ImmSExtAsmOperandClass : AsmOperandClass {
279   let SuperClasses = [ImmAsmOperand];
280   let RenderMethod = "addImmOperands";
281 }
282
283 // Sign-extended immediate classes. We don't need to define the full lattice
284 // here because there is no instruction with an ambiguity between ImmSExti64i32
285 // and ImmSExti32i8.
286 //
287 // The strange ranges come from the fact that the assembler always works with
288 // 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
289 // (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
290
291 // [0, 0x7FFFFFFF]                                            |
292 //   [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
293 def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
294   let Name = "ImmSExti64i32";
295 }
296
297 // [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
298 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
299 def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
300   let Name = "ImmSExti16i8";
301   let SuperClasses = [ImmSExti64i32AsmOperand];
302 }
303
304 // [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
305 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
306 def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
307   let Name = "ImmSExti32i8";
308 }
309
310 // [0, 0x0000007F]                                            |
311 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
312 def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
313   let Name = "ImmSExti64i8";
314   let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
315                       ImmSExti64i32AsmOperand];
316 }
317
318 // A couple of more descriptive operand definitions.
319 // 16-bits but only 8 bits are significant.
320 def i16i8imm  : Operand<i16> {
321   let ParserMatchClass = ImmSExti16i8AsmOperand;
322 }
323 // 32-bits but only 8 bits are significant.
324 def i32i8imm  : Operand<i32> {
325   let ParserMatchClass = ImmSExti32i8AsmOperand;
326 }
327
328 //===----------------------------------------------------------------------===//
329 // X86 Complex Pattern Definitions.
330 //
331
332 // Define X86 specific addressing mode.
333 def addr      : ComplexPattern<iPTR, 5, "SelectAddr", [], []>;
334 def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
335                                [add, sub, mul, X86mul_imm, shl, or, frameindex],
336                                []>;
337 def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
338                                [tglobaltlsaddr], []>;
339
340 //===----------------------------------------------------------------------===//
341 // X86 Instruction Predicate Definitions.
342 def HasCMov      : Predicate<"Subtarget->hasCMov()">;
343 def NoCMov       : Predicate<"!Subtarget->hasCMov()">;
344 def HasMMX       : Predicate<"Subtarget->hasMMX()">;
345 def HasSSE1      : Predicate<"Subtarget->hasSSE1()">;
346 def HasSSE2      : Predicate<"Subtarget->hasSSE2()">;
347 def HasSSE3      : Predicate<"Subtarget->hasSSE3()">;
348 def HasSSSE3     : Predicate<"Subtarget->hasSSSE3()">;
349 def HasSSE41     : Predicate<"Subtarget->hasSSE41()">;
350 def HasSSE42     : Predicate<"Subtarget->hasSSE42()">;
351 def HasSSE4A     : Predicate<"Subtarget->hasSSE4A()">;
352 def HasAVX       : Predicate<"Subtarget->hasAVX()">;
353 def HasFMA3      : Predicate<"Subtarget->hasFMA3()">;
354 def HasFMA4      : Predicate<"Subtarget->hasFMA4()">;
355 def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
356 def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
357 def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
358 def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
359 def IsWin64      : Predicate<"Subtarget->isTargetWin64()">;
360 def NotWin64     : Predicate<"!Subtarget->isTargetWin64()">;
361 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
362 def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
363 def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
364                              "TM.getCodeModel() != CodeModel::Kernel">;
365 def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
366                              "TM.getCodeModel() == CodeModel::Kernel">;
367 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
368 def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
369 def OptForSize   : Predicate<"OptForSize">;
370 def OptForSpeed  : Predicate<"!OptForSize">;
371 def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
372 def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
373 def HasAES       : Predicate<"Subtarget->hasAES()">;
374
375 //===----------------------------------------------------------------------===//
376 // X86 Instruction Format Definitions.
377 //
378
379 include "X86InstrFormats.td"
380
381 //===----------------------------------------------------------------------===//
382 // Pattern fragments...
383 //
384
385 // X86 specific condition code. These correspond to CondCode in
386 // X86InstrInfo.h. They must be kept in synch.
387 def X86_COND_A   : PatLeaf<(i8 0)>;  // alt. COND_NBE
388 def X86_COND_AE  : PatLeaf<(i8 1)>;  // alt. COND_NC
389 def X86_COND_B   : PatLeaf<(i8 2)>;  // alt. COND_C
390 def X86_COND_BE  : PatLeaf<(i8 3)>;  // alt. COND_NA
391 def X86_COND_E   : PatLeaf<(i8 4)>;  // alt. COND_Z
392 def X86_COND_G   : PatLeaf<(i8 5)>;  // alt. COND_NLE
393 def X86_COND_GE  : PatLeaf<(i8 6)>;  // alt. COND_NL
394 def X86_COND_L   : PatLeaf<(i8 7)>;  // alt. COND_NGE
395 def X86_COND_LE  : PatLeaf<(i8 8)>;  // alt. COND_NG
396 def X86_COND_NE  : PatLeaf<(i8 9)>;  // alt. COND_NZ
397 def X86_COND_NO  : PatLeaf<(i8 10)>;
398 def X86_COND_NP  : PatLeaf<(i8 11)>; // alt. COND_PO
399 def X86_COND_NS  : PatLeaf<(i8 12)>;
400 def X86_COND_O   : PatLeaf<(i8 13)>;
401 def X86_COND_P   : PatLeaf<(i8 14)>; // alt. COND_PE
402 def X86_COND_S   : PatLeaf<(i8 15)>;
403
404 def immSext8 : PatLeaf<(imm), [{
405   return N->getSExtValue() == (int8_t)N->getSExtValue();
406 }]>;
407
408 def i16immSExt8  : PatLeaf<(i16 immSext8)>;
409 def i32immSExt8  : PatLeaf<(i32 immSext8)>;
410
411 /// Load patterns: these constraint the match to the right address space.
412 def dsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
413   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
414     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
415       if (PT->getAddressSpace() > 255)
416         return false;
417   return true;
418 }]>;
419
420 def gsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
421   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
422     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
423       return PT->getAddressSpace() == 256;
424   return false;
425 }]>;
426
427 def fsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
428   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
429     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
430       return PT->getAddressSpace() == 257;
431   return false;
432 }]>;
433
434
435 // Helper fragments for loads.
436 // It's always safe to treat a anyext i16 load as a i32 load if the i16 is
437 // known to be 32-bit aligned or better. Ditto for i8 to i16.
438 def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
439   LoadSDNode *LD = cast<LoadSDNode>(N);
440   if (const Value *Src = LD->getSrcValue())
441     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
442       if (PT->getAddressSpace() > 255)
443         return false;
444   ISD::LoadExtType ExtType = LD->getExtensionType();
445   if (ExtType == ISD::NON_EXTLOAD)
446     return true;
447   if (ExtType == ISD::EXTLOAD)
448     return LD->getAlignment() >= 2 && !LD->isVolatile();
449   return false;
450 }]>;
451
452 def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
453   LoadSDNode *LD = cast<LoadSDNode>(N);
454   if (const Value *Src = LD->getSrcValue())
455     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
456       if (PT->getAddressSpace() > 255)
457         return false;
458   ISD::LoadExtType ExtType = LD->getExtensionType();
459   if (ExtType == ISD::EXTLOAD)
460     return LD->getAlignment() >= 2 && !LD->isVolatile();
461   return false;
462 }]>;
463
464 def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
465   LoadSDNode *LD = cast<LoadSDNode>(N);
466   if (const Value *Src = LD->getSrcValue())
467     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
468       if (PT->getAddressSpace() > 255)
469         return false;
470   ISD::LoadExtType ExtType = LD->getExtensionType();
471   if (ExtType == ISD::NON_EXTLOAD)
472     return true;
473   if (ExtType == ISD::EXTLOAD)
474     return LD->getAlignment() >= 4 && !LD->isVolatile();
475   return false;
476 }]>;
477
478 def loadi8  : PatFrag<(ops node:$ptr), (i8  (dsload node:$ptr))>;
479 def loadi64 : PatFrag<(ops node:$ptr), (i64 (dsload node:$ptr))>;
480 def loadf32 : PatFrag<(ops node:$ptr), (f32 (dsload node:$ptr))>;
481 def loadf64 : PatFrag<(ops node:$ptr), (f64 (dsload node:$ptr))>;
482 def loadf80 : PatFrag<(ops node:$ptr), (f80 (dsload node:$ptr))>;
483
484 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
485 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
486 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
487
488 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
489 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
490 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
491 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
492 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
493 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
494
495 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
496 def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
497 def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
498 def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
499 def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
500 def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
501
502
503 // An 'and' node with a single use.
504 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
505   return N->hasOneUse();
506 }]>;
507 // An 'srl' node with a single use.
508 def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
509   return N->hasOneUse();
510 }]>;
511 // An 'trunc' node with a single use.
512 def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
513   return N->hasOneUse();
514 }]>;
515
516 // Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
517 def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
518   if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
519     return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
520
521   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
522   APInt Mask = APInt::getAllOnesValue(BitWidth);
523   APInt KnownZero0, KnownOne0;
524   CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
525   APInt KnownZero1, KnownOne1;
526   CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
527   return (~KnownZero0 & ~KnownZero1) == 0;
528 }]>;
529
530 //===----------------------------------------------------------------------===//
531 // Instruction list...
532 //
533
534 // ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
535 // a stack adjustment and the codegen must know that they may modify the stack
536 // pointer before prolog-epilog rewriting occurs.
537 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
538 // sub / add which can clobber EFLAGS.
539 let Defs = [ESP, EFLAGS], Uses = [ESP] in {
540 def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt),
541                            "#ADJCALLSTACKDOWN",
542                            [(X86callseq_start timm:$amt)]>,
543                           Requires<[In32BitMode]>;
544 def ADJCALLSTACKUP32   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
545                            "#ADJCALLSTACKUP",
546                            [(X86callseq_end timm:$amt1, timm:$amt2)]>,
547                           Requires<[In32BitMode]>;
548 }
549
550 // x86-64 va_start lowering magic.
551 let usesCustomInserter = 1 in {
552 def VASTART_SAVE_XMM_REGS : I<0, Pseudo,
553                               (outs),
554                               (ins GR8:$al,
555                                    i64imm:$regsavefi, i64imm:$offset,
556                                    variable_ops),
557                               "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset",
558                               [(X86vastart_save_xmm_regs GR8:$al,
559                                                          imm:$regsavefi,
560                                                          imm:$offset)]>;
561
562 // Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets.  Calls
563 // to _alloca is needed to probe the stack when allocating more than 4k bytes in
564 // one go. Touching the stack at 4K increments is necessary to ensure that the
565 // guard pages used by the OS virtual memory manager are allocated in correct
566 // sequence.
567 // The main point of having separate instruction are extra unmodelled effects
568 // (compared to ordinary calls) like stack pointer change.
569
570 def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins),
571                      "# dynamic stack allocation",
572                      [(X86MingwAlloca)]>;
573 }
574
575 // Nop
576 let neverHasSideEffects = 1 in {
577   def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
578   def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
579                 "nop{w}\t$zero", []>, TB, OpSize;
580   def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
581                 "nop{l}\t$zero", []>, TB;
582 }
583
584 // Trap
585 def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>;
586 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", []>;
587 // FIXME: need to make sure that "int $3" matches int3
588 def INT : Ii8<0xcd, RawFrm, (outs), (ins i8imm:$trap), "int\t$trap", []>;
589 def IRET16 : I<0xcf, RawFrm, (outs), (ins), "iret{w}", []>, OpSize;
590 def IRET32 : I<0xcf, RawFrm, (outs), (ins), "iret{l}", []>;
591
592 // PIC base construction.  This expands to code that looks like this:
593 //     call  $next_inst
594 //     popl %destreg"
595 let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in
596   def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label),
597                       "", []>;
598
599 //===----------------------------------------------------------------------===//
600 //  Control Flow Instructions.
601 //
602
603 // Return instructions.
604 let isTerminator = 1, isReturn = 1, isBarrier = 1,
605     hasCtrlDep = 1, FPForm = SpecialFP in {
606   def RET    : I   <0xC3, RawFrm, (outs), (ins variable_ops),
607                     "ret",
608                     [(X86retflag 0)]>;
609   def RETI   : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
610                     "ret\t$amt",
611                     [(X86retflag timm:$amt)]>;
612   def LRET   : I   <0xCB, RawFrm, (outs), (ins),
613                     "lret", []>;
614   def LRETI  : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
615                     "lret\t$amt", []>;
616 }
617
618 // Unconditional branches.
619 let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
620   def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
621                         "jmp\t$dst", [(br bb:$dst)]>;
622   def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
623                        "jmp\t$dst", []>;
624 }
625
626 // Conditional Branches.
627 let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
628   multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
629     def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, []>;
630     def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
631                        [(X86brcond bb:$dst, Cond, EFLAGS)]>, TB;
632   }
633 }
634
635 defm JO  : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
636 defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
637 defm JB  : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
638 defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
639 defm JE  : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
640 defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
641 defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
642 defm JA  : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
643 defm JS  : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
644 defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
645 defm JP  : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
646 defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
647 defm JL  : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
648 defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
649 defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
650 defm JG  : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
651
652 // FIXME: What about the CX/RCX versions of this instruction?
653 let Uses = [ECX], isBranch = 1, isTerminator = 1 in
654   def JCXZ8 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
655                        "jcxz\t$dst", []>;
656
657
658 // Indirect branches
659 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
660   def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
661                      [(brind GR32:$dst)]>, Requires<[In32BitMode]>;
662   def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
663                      [(brind (loadi32 addr:$dst))]>, Requires<[In32BitMode]>;
664                      
665   def FARJMP16i  : Iseg16<0xEA, RawFrm, (outs), 
666                           (ins i16imm:$seg, i16imm:$off),
667                           "ljmp{w}\t$seg, $off", []>, OpSize;
668   def FARJMP32i  : Iseg32<0xEA, RawFrm, (outs),
669                           (ins i16imm:$seg, i32imm:$off),
670                           "ljmp{l}\t$seg, $off", []>;                     
671
672   def FARJMP16m  : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst), 
673                      "ljmp{w}\t{*}$dst", []>, OpSize;
674   def FARJMP32m  : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
675                      "ljmp{l}\t{*}$dst", []>;
676 }
677
678
679 // Loop instructions
680
681 def LOOP   : I<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
682 def LOOPE  : I<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
683 def LOOPNE : I<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
684
685 //===----------------------------------------------------------------------===//
686 //  Call Instructions...
687 //
688 let isCall = 1 in
689   // All calls clobber the non-callee saved registers. ESP is marked as
690   // a use to prevent stack-pointer assignments that appear immediately
691   // before calls from potentially appearing dead. Uses for argument
692   // registers are added manually.
693   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
694               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
695               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
696               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
697       Uses = [ESP] in {
698     def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
699                            (outs), (ins i32imm_pcrel:$dst,variable_ops),
700                            "call\t$dst", []>;
701     def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
702                         "call\t{*}$dst", [(X86call GR32:$dst)]>;
703     def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
704                         "call\t{*}$dst", [(X86call (loadi32 addr:$dst))]>;
705   
706     def FARCALL16i  : Iseg16<0x9A, RawFrm, (outs), 
707                              (ins i16imm:$seg, i16imm:$off),
708                              "lcall{w}\t$seg, $off", []>, OpSize;
709     def FARCALL32i  : Iseg32<0x9A, RawFrm, (outs),
710                              (ins i16imm:$seg, i32imm:$off),
711                              "lcall{l}\t$seg, $off", []>;
712                              
713     def FARCALL16m  : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
714                         "lcall{w}\t{*}$dst", []>, OpSize;
715     def FARCALL32m  : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
716                         "lcall{l}\t{*}$dst", []>;
717
718     // callw for 16 bit code for the assembler.
719     let isAsmParserOnly = 1 in
720       def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
721                        (outs), (ins i16imm_pcrel:$dst, variable_ops),
722                        "callw\t$dst", []>, OpSize;
723   }
724
725 // Constructing a stack frame.
726
727 def ENTER : I<0xC8, RawFrm, (outs), (ins i16imm:$len, i8imm:$lvl),
728               "enter\t$len, $lvl", []>;
729
730 // Tail call stuff.
731
732 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
733     isCodeGenOnly = 1 in
734   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
735               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
736               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
737               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
738       Uses = [ESP] in {
739   def TCRETURNdi : I<0, Pseudo, (outs), 
740                      (ins i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
741                    "#TC_RETURN $dst $offset", []>;
742   def TCRETURNri : I<0, Pseudo, (outs), 
743                      (ins GR32_TC:$dst, i32imm:$offset, variable_ops),
744                      "#TC_RETURN $dst $offset", []>;
745   let mayLoad = 1 in
746   def TCRETURNmi : I<0, Pseudo, (outs), 
747                      (ins i32mem_TC:$dst, i32imm:$offset, variable_ops),
748                      "#TC_RETURN $dst $offset", []>;
749
750   // FIXME: The should be pseudo instructions that are lowered when going to
751   // mcinst.
752   def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
753                            (ins i32imm_pcrel:$dst, variable_ops),
754                  "jmp\t$dst  # TAILCALL",
755                  []>;
756   def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32_TC:$dst, variable_ops), 
757                    "", []>;  // FIXME: Remove encoding when JIT is dead.
758   let mayLoad = 1 in
759   def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst, variable_ops),
760                    "jmp{l}\t{*}$dst  # TAILCALL", []>;
761 }
762
763 //===----------------------------------------------------------------------===//
764 //  Miscellaneous Instructions...
765 //
766 let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
767 def LEAVE    : I<0xC9, RawFrm,
768                  (outs), (ins), "leave", []>, Requires<[In32BitMode]>;
769
770 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
771                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
772 let mayLoad = 1 in
773 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
774                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
775 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
776                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
777 let mayLoad = 1 in
778 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
779                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
780
781 let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
782 let mayLoad = 1 in {
783 def POP16r  : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
784   OpSize;
785 def POP32r  : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
786 def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
787   OpSize;
788 def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
789   OpSize;
790 def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
791 def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
792 }
793
794 let mayStore = 1 in {
795 def PUSH16r  : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
796   OpSize;
797 def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
798 def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
799   OpSize;
800 def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
801   OpSize;
802 def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
803 def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
804 }
805 }
806
807 let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
808 def PUSHi8   : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 
809                       "push{l}\t$imm", []>;
810 def PUSHi16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
811                       "push{w}\t$imm", []>, OpSize;
812 def PUSHi32  : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 
813                       "push{l}\t$imm", []>;
814 }
815
816 let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
817 def POPF16   : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
818 def POPF32   : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
819                Requires<[In32BitMode]>;
820 }
821 let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
822 def PUSHF16  : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
823 def PUSHF32  : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
824                Requires<[In32BitMode]>;
825 }
826
827 let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
828     mayLoad=1, neverHasSideEffects=1 in {
829 def POPA32   : I<0x61, RawFrm, (outs), (ins), "popa{l}", []>,
830                Requires<[In32BitMode]>;
831 }
832 let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
833     mayStore=1, neverHasSideEffects=1 in {
834 def PUSHA32  : I<0x60, RawFrm, (outs), (ins), "pusha{l}", []>,
835                Requires<[In32BitMode]>;
836 }
837
838 let Uses = [EFLAGS], Constraints = "$src = $dst" in     // GR32 = bswap GR32
839   def BSWAP32r : I<0xC8, AddRegFrm,
840                    (outs GR32:$dst), (ins GR32:$src),
841                    "bswap{l}\t$dst", 
842                    [(set GR32:$dst, (bswap GR32:$src))]>, TB;
843
844
845 // Bit scan instructions.
846 let Defs = [EFLAGS] in {
847 def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
848                  "bsf{w}\t{$src, $dst|$dst, $src}",
849                  [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
850 def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
851                  "bsf{w}\t{$src, $dst|$dst, $src}",
852                  [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
853                  OpSize;
854 def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
855                  "bsf{l}\t{$src, $dst|$dst, $src}",
856                  [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
857 def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
858                  "bsf{l}\t{$src, $dst|$dst, $src}",
859                  [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
860
861 def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
862                  "bsr{w}\t{$src, $dst|$dst, $src}",
863                  [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
864 def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
865                  "bsr{w}\t{$src, $dst|$dst, $src}",
866                  [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
867                  OpSize;
868 def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
869                  "bsr{l}\t{$src, $dst|$dst, $src}",
870                  [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
871 def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
872                  "bsr{l}\t{$src, $dst|$dst, $src}",
873                  [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
874 } // Defs = [EFLAGS]
875
876 let neverHasSideEffects = 1 in
877 def LEA16r   : I<0x8D, MRMSrcMem,
878                  (outs GR16:$dst), (ins i32mem:$src),
879                  "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
880 let isReMaterializable = 1 in
881 def LEA32r   : I<0x8D, MRMSrcMem,
882                  (outs GR32:$dst), (ins i32mem:$src),
883                  "lea{l}\t{$src|$dst}, {$dst|$src}",
884                  [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
885
886 let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in {
887 def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
888                   [(X86rep_movs i8)]>, REP;
889 def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
890                   [(X86rep_movs i16)]>, REP, OpSize;
891 def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
892                   [(X86rep_movs i32)]>, REP;
893 }
894
895 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
896 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
897 def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
898 def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
899 def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
900 }
901
902 let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in
903 def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
904                   [(X86rep_stos i8)]>, REP;
905 let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in
906 def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
907                   [(X86rep_stos i16)]>, REP, OpSize;
908 let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in
909 def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
910                   [(X86rep_stos i32)]>, REP;
911
912 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
913 let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
914 def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
915 let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
916 def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
917 let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
918 def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
919
920 def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
921 def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
922 def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
923
924 def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
925 def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
926 def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
927
928 let Defs = [RAX, RDX] in
929 def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>,
930             TB;
931
932 let Defs = [RAX, RCX, RDX] in
933 def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", []>, TB;
934
935 let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
936 def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
937 }
938
939 def SYSCALL  : I<0x05, RawFrm,
940                  (outs), (ins), "syscall", []>, TB;
941 def SYSRET   : I<0x07, RawFrm,
942                  (outs), (ins), "sysret", []>, TB;
943 def SYSENTER : I<0x34, RawFrm,
944                  (outs), (ins), "sysenter", []>, TB;
945 def SYSEXIT  : I<0x35, RawFrm,
946                  (outs), (ins), "sysexit", []>, TB, Requires<[In32BitMode]>;
947
948 def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
949
950
951 //===----------------------------------------------------------------------===//
952 //  Input/Output Instructions...
953 //
954 let Defs = [AL], Uses = [DX] in
955 def IN8rr  : I<0xEC, RawFrm, (outs), (ins),
956                "in{b}\t{%dx, %al|%AL, %DX}", []>;
957 let Defs = [AX], Uses = [DX] in
958 def IN16rr : I<0xED, RawFrm, (outs), (ins),
959                "in{w}\t{%dx, %ax|%AX, %DX}", []>,  OpSize;
960 let Defs = [EAX], Uses = [DX] in
961 def IN32rr : I<0xED, RawFrm, (outs), (ins),
962                "in{l}\t{%dx, %eax|%EAX, %DX}", []>;
963
964 let Defs = [AL] in
965 def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins i16i8imm:$port),
966                   "in{b}\t{$port, %al|%AL, $port}", []>;
967 let Defs = [AX] in
968 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
969                   "in{w}\t{$port, %ax|%AX, $port}", []>, OpSize;
970 let Defs = [EAX] in
971 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
972                   "in{l}\t{$port, %eax|%EAX, $port}", []>;
973
974 let Uses = [DX, AL] in
975 def OUT8rr  : I<0xEE, RawFrm, (outs), (ins),
976                 "out{b}\t{%al, %dx|%DX, %AL}", []>;
977 let Uses = [DX, AX] in
978 def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
979                 "out{w}\t{%ax, %dx|%DX, %AX}", []>, OpSize;
980 let Uses = [DX, EAX] in
981 def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
982                 "out{l}\t{%eax, %dx|%DX, %EAX}", []>;
983
984 let Uses = [AL] in
985 def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins i16i8imm:$port),
986                    "out{b}\t{%al, $port|$port, %AL}", []>;
987 let Uses = [AX] in
988 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
989                    "out{w}\t{%ax, $port|$port, %AX}", []>, OpSize;
990 let Uses = [EAX] in
991 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
992                    "out{l}\t{%eax, $port|$port, %EAX}", []>;
993
994 def IN8  : I<0x6C, RawFrm, (outs), (ins),
995              "ins{b}", []>;
996 def IN16 : I<0x6D, RawFrm, (outs), (ins),
997              "ins{w}", []>,  OpSize;
998 def IN32 : I<0x6D, RawFrm, (outs), (ins),
999              "ins{l}", []>;
1000
1001 //===----------------------------------------------------------------------===//
1002 //  Move Instructions...
1003 //
1004 let neverHasSideEffects = 1 in {
1005 def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
1006                 "mov{b}\t{$src, $dst|$dst, $src}", []>;
1007 def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
1008                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1009 def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
1010                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1011 }
1012 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
1013 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
1014                    "mov{b}\t{$src, $dst|$dst, $src}",
1015                    [(set GR8:$dst, imm:$src)]>;
1016 def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
1017                    "mov{w}\t{$src, $dst|$dst, $src}",
1018                    [(set GR16:$dst, imm:$src)]>, OpSize;
1019 def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
1020                    "mov{l}\t{$src, $dst|$dst, $src}",
1021                    [(set GR32:$dst, imm:$src)]>;
1022 }
1023
1024 def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
1025                    "mov{b}\t{$src, $dst|$dst, $src}",
1026                    [(store (i8 imm:$src), addr:$dst)]>;
1027 def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
1028                    "mov{w}\t{$src, $dst|$dst, $src}",
1029                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
1030 def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
1031                    "mov{l}\t{$src, $dst|$dst, $src}",
1032                    [(store (i32 imm:$src), addr:$dst)]>;
1033
1034 /// moffs8, moffs16 and moffs32 versions of moves.  The immediate is a
1035 /// 32-bit offset from the PC.  These are only valid in x86-32 mode.
1036 def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
1037                    "mov{b}\t{$src, %al|%al, $src}", []>,
1038                    Requires<[In32BitMode]>;
1039 def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
1040                       "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize,
1041                      Requires<[In32BitMode]>;
1042 def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
1043                       "mov{l}\t{$src, %eax|%eax, $src}", []>,
1044                      Requires<[In32BitMode]>;
1045 def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
1046                    "mov{b}\t{%al, $dst|$dst, %al}", []>,
1047                   Requires<[In32BitMode]>;
1048 def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
1049                       "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize,
1050                      Requires<[In32BitMode]>;
1051 def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
1052                       "mov{l}\t{%eax, $dst|$dst, %eax}", []>,
1053                      Requires<[In32BitMode]>;
1054                       
1055 // Moves to and from segment registers
1056 def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
1057                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1058 def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
1059                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1060 def MOV16ms : I<0x8C, MRMDestMem, (outs i16mem:$dst), (ins SEGMENT_REG:$src),
1061                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1062 def MOV32ms : I<0x8C, MRMDestMem, (outs i32mem:$dst), (ins SEGMENT_REG:$src),
1063                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1064 def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
1065                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1066 def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
1067                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1068 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
1069                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1070 def MOV32sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i32mem:$src),
1071                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1072
1073 let isCodeGenOnly = 1 in {
1074 def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
1075                    "mov{b}\t{$src, $dst|$dst, $src}", []>;
1076 def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
1077                     "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1078 def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
1079                     "mov{l}\t{$src, $dst|$dst, $src}", []>;
1080 }
1081
1082 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1083 def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
1084                 "mov{b}\t{$src, $dst|$dst, $src}",
1085                 [(set GR8:$dst, (loadi8 addr:$src))]>;
1086 def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
1087                 "mov{w}\t{$src, $dst|$dst, $src}",
1088                 [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
1089 def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
1090                 "mov{l}\t{$src, $dst|$dst, $src}",
1091                 [(set GR32:$dst, (loadi32 addr:$src))]>;
1092 }
1093
1094 def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
1095                 "mov{b}\t{$src, $dst|$dst, $src}",
1096                 [(store GR8:$src, addr:$dst)]>;
1097 def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
1098                 "mov{w}\t{$src, $dst|$dst, $src}",
1099                 [(store GR16:$src, addr:$dst)]>, OpSize;
1100 def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1101                 "mov{l}\t{$src, $dst|$dst, $src}",
1102                 [(store GR32:$src, addr:$dst)]>;
1103
1104 /// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
1105 let isCodeGenOnly = 1 in {
1106 let neverHasSideEffects = 1 in
1107 def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
1108                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1109
1110 let mayLoad = 1,
1111     canFoldAsLoad = 1, isReMaterializable = 1 in
1112 def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
1113                 "mov{l}\t{$src, $dst|$dst, $src}",
1114                 []>;
1115
1116 let mayStore = 1 in
1117 def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
1118                 "mov{l}\t{$src, $dst|$dst, $src}",
1119                 []>;
1120 }
1121
1122 // Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
1123 // that they can be used for copying and storing h registers, which can't be
1124 // encoded when a REX prefix is present.
1125 let isCodeGenOnly = 1 in {
1126 let neverHasSideEffects = 1 in
1127 def MOV8rr_NOREX : I<0x88, MRMDestReg,
1128                      (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
1129                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1130 let mayStore = 1 in
1131 def MOV8mr_NOREX : I<0x88, MRMDestMem,
1132                      (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
1133                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1134 let mayLoad = 1,
1135     canFoldAsLoad = 1, isReMaterializable = 1 in
1136 def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
1137                      (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
1138                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1139 }
1140
1141 // Moves to and from debug registers
1142 def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
1143                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1144 def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
1145                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1146                 
1147 // Moves to and from control registers
1148 def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
1149                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1150 def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
1151                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1152
1153 //===----------------------------------------------------------------------===//
1154 //  Fixed-Register Multiplication and Division Instructions...
1155 //
1156
1157 // Extra precision multiplication
1158
1159 // AL is really implied by AX, by the registers in Defs must match the
1160 // SDNode results (i8, i32).
1161 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1162 def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
1163                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1164                // This probably ought to be moved to a def : Pat<> if the
1165                // syntax can be accepted.
1166                [(set AL, (mul AL, GR8:$src)),
1167                 (implicit EFLAGS)]>;     // AL,AH = AL*GR8
1168
1169 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
1170 def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src),
1171                "mul{w}\t$src", 
1172                []>, OpSize;    // AX,DX = AX*GR16
1173
1174 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
1175 def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src),
1176                "mul{l}\t$src",
1177                []>; // EAX,EDX = EAX*GR32
1178
1179 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1180 def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
1181                "mul{b}\t$src",
1182                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1183                // This probably ought to be moved to a def : Pat<> if the
1184                // syntax can be accepted.
1185                [(set AL, (mul AL, (loadi8 addr:$src))),
1186                 (implicit EFLAGS)]>;   // AL,AH = AL*[mem8]
1187
1188 let mayLoad = 1, neverHasSideEffects = 1 in {
1189 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1190 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
1191                "mul{w}\t$src",
1192                []>, OpSize; // AX,DX = AX*[mem16]
1193
1194 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1195 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
1196               "mul{l}\t$src",
1197               []>;          // EAX,EDX = EAX*[mem32]
1198 }
1199
1200 let neverHasSideEffects = 1 in {
1201 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1202 def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
1203               // AL,AH = AL*GR8
1204 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1205 def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
1206               OpSize;    // AX,DX = AX*GR16
1207 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1208 def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
1209               // EAX,EDX = EAX*GR32
1210 let mayLoad = 1 in {
1211 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1212 def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
1213                 "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
1214 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1215 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
1216                 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
1217 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1218 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
1219                 "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
1220 }
1221 } // neverHasSideEffects
1222
1223 // unsigned division/remainder
1224 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1225 def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
1226                "div{b}\t$src", []>;
1227 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1228 def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
1229                "div{w}\t$src", []>, OpSize;
1230 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1231 def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
1232                "div{l}\t$src", []>;
1233 let mayLoad = 1 in {
1234 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1235 def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
1236                "div{b}\t$src", []>;
1237 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1238 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
1239                "div{w}\t$src", []>, OpSize;
1240 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1241                                                     // EDX:EAX/[mem32] = EAX,EDX
1242 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
1243                "div{l}\t$src", []>;
1244 }
1245
1246 // Signed division/remainder.
1247 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1248 def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
1249                "idiv{b}\t$src", []>;
1250 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1251 def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
1252                "idiv{w}\t$src", []>, OpSize;
1253 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1254 def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
1255                "idiv{l}\t$src", []>;
1256 let mayLoad = 1, mayLoad = 1 in {
1257 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1258 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
1259                "idiv{b}\t$src", []>;
1260 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1261 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
1262                "idiv{w}\t$src", []>, OpSize;
1263 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1264 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src), 
1265                                                     // EDX:EAX/[mem32] = EAX,EDX
1266                "idiv{l}\t$src", []>;
1267 }
1268
1269 //===----------------------------------------------------------------------===//
1270 //  Two address Instructions.
1271 //
1272 let Constraints = "$src1 = $dst" in {
1273
1274 // Conditional moves
1275 let Uses = [EFLAGS] in {
1276
1277 let Predicates = [HasCMov] in {
1278 let isCommutable = 1 in {
1279 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, GR16 = GR16
1280                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1281                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
1282                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1283                                    X86_COND_B, EFLAGS))]>,
1284                   TB, OpSize;
1285 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, GR32 = GR32
1286                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1287                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
1288                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1289                                    X86_COND_B, EFLAGS))]>,
1290                    TB;
1291 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, GR16 = GR16
1292                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1293                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1294                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1295                                    X86_COND_AE, EFLAGS))]>,
1296                    TB, OpSize;
1297 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, GR32 = GR32
1298                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1299                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1300                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1301                                    X86_COND_AE, EFLAGS))]>,
1302                    TB;
1303 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, GR16 = GR16
1304                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1305                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1306                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1307                                    X86_COND_E, EFLAGS))]>,
1308                    TB, OpSize;
1309 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, GR32 = GR32
1310                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1311                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1312                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1313                                    X86_COND_E, EFLAGS))]>,
1314                    TB;
1315 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, GR16 = GR16
1316                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1317                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1318                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1319                                    X86_COND_NE, EFLAGS))]>,
1320                    TB, OpSize;
1321 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, GR32 = GR32
1322                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1323                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1324                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1325                                    X86_COND_NE, EFLAGS))]>,
1326                    TB;
1327 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, GR16 = GR16
1328                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1329                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1330                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1331                                    X86_COND_BE, EFLAGS))]>,
1332                    TB, OpSize;
1333 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, GR32 = GR32
1334                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1335                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1336                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1337                                    X86_COND_BE, EFLAGS))]>,
1338                    TB;
1339 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, GR16 = GR16
1340                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1341                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1342                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1343                                    X86_COND_A, EFLAGS))]>,
1344                    TB, OpSize;
1345 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, GR32 = GR32
1346                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1347                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1348                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1349                                    X86_COND_A, EFLAGS))]>,
1350                    TB;
1351 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, GR16 = GR16
1352                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1353                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1354                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1355                                    X86_COND_L, EFLAGS))]>,
1356                    TB, OpSize;
1357 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, GR32 = GR32
1358                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1359                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1360                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1361                                    X86_COND_L, EFLAGS))]>,
1362                    TB;
1363 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, GR16 = GR16
1364                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1365                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1366                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1367                                    X86_COND_GE, EFLAGS))]>,
1368                    TB, OpSize;
1369 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, GR32 = GR32
1370                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1371                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1372                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1373                                    X86_COND_GE, EFLAGS))]>,
1374                    TB;
1375 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, GR16 = GR16
1376                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1377                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1378                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1379                                    X86_COND_LE, EFLAGS))]>,
1380                    TB, OpSize;
1381 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, GR32 = GR32
1382                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1383                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1384                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1385                                    X86_COND_LE, EFLAGS))]>,
1386                    TB;
1387 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, GR16 = GR16
1388                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1389                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1390                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1391                                    X86_COND_G, EFLAGS))]>,
1392                    TB, OpSize;
1393 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, GR32 = GR32
1394                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1395                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1396                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1397                                    X86_COND_G, EFLAGS))]>,
1398                    TB;
1399 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, GR16 = GR16
1400                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1401                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1402                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1403                                    X86_COND_S, EFLAGS))]>,
1404                   TB, OpSize;
1405 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, GR32 = GR32
1406                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1407                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1408                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1409                                    X86_COND_S, EFLAGS))]>,
1410                   TB;
1411 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, GR16 = GR16
1412                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1413                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1414                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1415                                    X86_COND_NS, EFLAGS))]>,
1416                   TB, OpSize;
1417 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, GR32 = GR32
1418                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1419                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1420                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1421                                    X86_COND_NS, EFLAGS))]>,
1422                   TB;
1423 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, GR16 = GR16
1424                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1425                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1426                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1427                                    X86_COND_P, EFLAGS))]>,
1428                   TB, OpSize;
1429 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, GR32 = GR32
1430                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1431                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1432                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1433                                    X86_COND_P, EFLAGS))]>,
1434                   TB;
1435 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, GR16 = GR16
1436                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1437                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1438                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1439                                     X86_COND_NP, EFLAGS))]>,
1440                   TB, OpSize;
1441 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, GR32 = GR32
1442                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1443                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1444                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1445                                     X86_COND_NP, EFLAGS))]>,
1446                   TB;
1447 def CMOVO16rr : I<0x40, MRMSrcReg,       // if overflow, GR16 = GR16
1448                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1449                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1450                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1451                                    X86_COND_O, EFLAGS))]>,
1452                   TB, OpSize;
1453 def CMOVO32rr : I<0x40, MRMSrcReg,       // if overflow, GR32 = GR32
1454                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1455                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1456                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1457                                    X86_COND_O, EFLAGS))]>,
1458                   TB;
1459 def CMOVNO16rr : I<0x41, MRMSrcReg,       // if !overflow, GR16 = GR16
1460                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1461                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1462                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1463                                     X86_COND_NO, EFLAGS))]>,
1464                   TB, OpSize;
1465 def CMOVNO32rr : I<0x41, MRMSrcReg,       // if !overflow, GR32 = GR32
1466                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1467                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1468                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1469                                     X86_COND_NO, EFLAGS))]>,
1470                   TB;
1471 } // isCommutable = 1
1472
1473 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, GR16 = [mem16]
1474                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1475                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
1476                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1477                                    X86_COND_B, EFLAGS))]>,
1478                   TB, OpSize;
1479 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, GR32 = [mem32]
1480                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1481                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
1482                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1483                                    X86_COND_B, EFLAGS))]>,
1484                    TB;
1485 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, GR16 = [mem16]
1486                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1487                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1488                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1489                                    X86_COND_AE, EFLAGS))]>,
1490                    TB, OpSize;
1491 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, GR32 = [mem32]
1492                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1493                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1494                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1495                                    X86_COND_AE, EFLAGS))]>,
1496                    TB;
1497 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, GR16 = [mem16]
1498                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1499                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1500                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1501                                    X86_COND_E, EFLAGS))]>,
1502                    TB, OpSize;
1503 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, GR32 = [mem32]
1504                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1505                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1506                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1507                                    X86_COND_E, EFLAGS))]>,
1508                    TB;
1509 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, GR16 = [mem16]
1510                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1511                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1512                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1513                                    X86_COND_NE, EFLAGS))]>,
1514                    TB, OpSize;
1515 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, GR32 = [mem32]
1516                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1517                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1518                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1519                                    X86_COND_NE, EFLAGS))]>,
1520                    TB;
1521 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, GR16 = [mem16]
1522                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1523                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1524                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1525                                    X86_COND_BE, EFLAGS))]>,
1526                    TB, OpSize;
1527 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, GR32 = [mem32]
1528                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1529                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1530                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1531                                    X86_COND_BE, EFLAGS))]>,
1532                    TB;
1533 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, GR16 = [mem16]
1534                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1535                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1536                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1537                                    X86_COND_A, EFLAGS))]>,
1538                    TB, OpSize;
1539 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, GR32 = [mem32]
1540                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1541                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1542                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1543                                    X86_COND_A, EFLAGS))]>,
1544                    TB;
1545 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, GR16 = [mem16]
1546                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1547                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1548                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1549                                    X86_COND_L, EFLAGS))]>,
1550                    TB, OpSize;
1551 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, GR32 = [mem32]
1552                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1553                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1554                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1555                                    X86_COND_L, EFLAGS))]>,
1556                    TB;
1557 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, GR16 = [mem16]
1558                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1559                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1560                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1561                                    X86_COND_GE, EFLAGS))]>,
1562                    TB, OpSize;
1563 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, GR32 = [mem32]
1564                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1565                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1566                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1567                                    X86_COND_GE, EFLAGS))]>,
1568                    TB;
1569 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, GR16 = [mem16]
1570                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1571                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1572                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1573                                    X86_COND_LE, EFLAGS))]>,
1574                    TB, OpSize;
1575 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, GR32 = [mem32]
1576                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1577                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1578                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1579                                    X86_COND_LE, EFLAGS))]>,
1580                    TB;
1581 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, GR16 = [mem16]
1582                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1583                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1584                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1585                                    X86_COND_G, EFLAGS))]>,
1586                    TB, OpSize;
1587 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, GR32 = [mem32]
1588                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1589                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1590                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1591                                    X86_COND_G, EFLAGS))]>,
1592                    TB;
1593 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, GR16 = [mem16]
1594                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1595                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1596                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1597                                    X86_COND_S, EFLAGS))]>,
1598                   TB, OpSize;
1599 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, GR32 = [mem32]
1600                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1601                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1602                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1603                                    X86_COND_S, EFLAGS))]>,
1604                   TB;
1605 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, GR16 = [mem16]
1606                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1607                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1608                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1609                                    X86_COND_NS, EFLAGS))]>,
1610                   TB, OpSize;
1611 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, GR32 = [mem32]
1612                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1613                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1614                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1615                                    X86_COND_NS, EFLAGS))]>,
1616                   TB;
1617 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, GR16 = [mem16]
1618                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1619                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1620                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1621                                    X86_COND_P, EFLAGS))]>,
1622                   TB, OpSize;
1623 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, GR32 = [mem32]
1624                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1625                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1626                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1627                                    X86_COND_P, EFLAGS))]>,
1628                   TB;
1629 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, GR16 = [mem16]
1630                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1631                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1632                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1633                                     X86_COND_NP, EFLAGS))]>,
1634                   TB, OpSize;
1635 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, GR32 = [mem32]
1636                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1637                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1638                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1639                                     X86_COND_NP, EFLAGS))]>,
1640                   TB;
1641 def CMOVO16rm : I<0x40, MRMSrcMem,       // if overflow, GR16 = [mem16]
1642                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1643                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1644                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1645                                    X86_COND_O, EFLAGS))]>,
1646                   TB, OpSize;
1647 def CMOVO32rm : I<0x40, MRMSrcMem,       // if overflow, GR32 = [mem32]
1648                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1649                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1650                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1651                                    X86_COND_O, EFLAGS))]>,
1652                   TB;
1653 def CMOVNO16rm : I<0x41, MRMSrcMem,       // if !overflow, GR16 = [mem16]
1654                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1655                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1656                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1657                                     X86_COND_NO, EFLAGS))]>,
1658                   TB, OpSize;
1659 def CMOVNO32rm : I<0x41, MRMSrcMem,       // if !overflow, GR32 = [mem32]
1660                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1661                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1662                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1663                                     X86_COND_NO, EFLAGS))]>,
1664                   TB;
1665 } // Predicates = [HasCMov]
1666
1667 // X86 doesn't have 8-bit conditional moves. Use a customInserter to
1668 // emit control flow. An alternative to this is to mark i8 SELECT as Promote,
1669 // however that requires promoting the operands, and can induce additional
1670 // i8 register pressure. Note that CMOV_GR8 is conservatively considered to
1671 // clobber EFLAGS, because if one of the operands is zero, the expansion
1672 // could involve an xor.
1673 let usesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] in {
1674 def CMOV_GR8 : I<0, Pseudo,
1675                  (outs GR8:$dst), (ins GR8:$src1, GR8:$src2, i8imm:$cond),
1676                  "#CMOV_GR8 PSEUDO!",
1677                  [(set GR8:$dst, (X86cmov GR8:$src1, GR8:$src2,
1678                                           imm:$cond, EFLAGS))]>;
1679
1680 let Predicates = [NoCMov] in {
1681 def CMOV_GR32 : I<0, Pseudo,
1682                     (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$cond),
1683                     "#CMOV_GR32* PSEUDO!",
1684                     [(set GR32:$dst,
1685                       (X86cmov GR32:$src1, GR32:$src2, imm:$cond, EFLAGS))]>;
1686 def CMOV_GR16 : I<0, Pseudo,
1687                     (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cond),
1688                     "#CMOV_GR16* PSEUDO!",
1689                     [(set GR16:$dst,
1690                       (X86cmov GR16:$src1, GR16:$src2, imm:$cond, EFLAGS))]>;
1691 def CMOV_RFP32 : I<0, Pseudo,
1692                     (outs RFP32:$dst),
1693                     (ins RFP32:$src1, RFP32:$src2, i8imm:$cond),
1694                     "#CMOV_RFP32 PSEUDO!",
1695                     [(set RFP32:$dst,
1696                       (X86cmov RFP32:$src1, RFP32:$src2, imm:$cond,
1697                                                   EFLAGS))]>;
1698 def CMOV_RFP64 : I<0, Pseudo,
1699                     (outs RFP64:$dst),
1700                     (ins RFP64:$src1, RFP64:$src2, i8imm:$cond),
1701                     "#CMOV_RFP64 PSEUDO!",
1702                     [(set RFP64:$dst,
1703                       (X86cmov RFP64:$src1, RFP64:$src2, imm:$cond,
1704                                                   EFLAGS))]>;
1705 def CMOV_RFP80 : I<0, Pseudo,
1706                     (outs RFP80:$dst),
1707                     (ins RFP80:$src1, RFP80:$src2, i8imm:$cond),
1708                     "#CMOV_RFP80 PSEUDO!",
1709                     [(set RFP80:$dst,
1710                       (X86cmov RFP80:$src1, RFP80:$src2, imm:$cond,
1711                                                   EFLAGS))]>;
1712 } // Predicates = [NoCMov]
1713 } // UsesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] 
1714 } // Uses = [EFLAGS]
1715
1716
1717 // unary instructions
1718 let CodeSize = 2 in {
1719 let Defs = [EFLAGS] in {
1720 def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
1721                "neg{b}\t$dst",
1722                [(set GR8:$dst, (ineg GR8:$src1)),
1723                 (implicit EFLAGS)]>;
1724 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
1725                "neg{w}\t$dst",
1726                [(set GR16:$dst, (ineg GR16:$src1)),
1727                 (implicit EFLAGS)]>, OpSize;
1728 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
1729                "neg{l}\t$dst",
1730                [(set GR32:$dst, (ineg GR32:$src1)),
1731                 (implicit EFLAGS)]>;
1732                 
1733 let Constraints = "" in {
1734   def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
1735                  "neg{b}\t$dst",
1736                  [(store (ineg (loadi8 addr:$dst)), addr:$dst),
1737                   (implicit EFLAGS)]>;
1738   def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
1739                  "neg{w}\t$dst",
1740                  [(store (ineg (loadi16 addr:$dst)), addr:$dst),
1741                   (implicit EFLAGS)]>, OpSize;
1742   def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
1743                  "neg{l}\t$dst",
1744                  [(store (ineg (loadi32 addr:$dst)), addr:$dst),
1745                   (implicit EFLAGS)]>;
1746 } // Constraints = ""
1747 } // Defs = [EFLAGS]
1748
1749 // Match xor -1 to not. Favors these over a move imm + xor to save code size.
1750 let AddedComplexity = 15 in {
1751 def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
1752                "not{b}\t$dst",
1753                [(set GR8:$dst, (not GR8:$src1))]>;
1754 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
1755                "not{w}\t$dst",
1756                [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
1757 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
1758                "not{l}\t$dst",
1759                [(set GR32:$dst, (not GR32:$src1))]>;
1760 }
1761 let Constraints = "" in {
1762   def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
1763                  "not{b}\t$dst",
1764                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1765   def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
1766                  "not{w}\t$dst",
1767                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1768   def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
1769                  "not{l}\t$dst",
1770                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1771 } // Constraints = ""
1772 } // CodeSize
1773
1774 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1775 let Defs = [EFLAGS] in {
1776 let CodeSize = 2 in
1777 def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1778                "inc{b}\t$dst",
1779                [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
1780
1781 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
1782 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1783                "inc{w}\t$dst",
1784                [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
1785              OpSize, Requires<[In32BitMode]>;
1786 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1787                "inc{l}\t$dst",
1788                [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
1789              Requires<[In32BitMode]>;
1790 }
1791 let Constraints = "", CodeSize = 2 in {
1792   def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
1793                [(store (add (loadi8 addr:$dst), 1), addr:$dst),
1794                 (implicit EFLAGS)]>;
1795   def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
1796                [(store (add (loadi16 addr:$dst), 1), addr:$dst),
1797                 (implicit EFLAGS)]>,
1798                OpSize, Requires<[In32BitMode]>;
1799   def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
1800                [(store (add (loadi32 addr:$dst), 1), addr:$dst),
1801                 (implicit EFLAGS)]>,
1802                Requires<[In32BitMode]>;
1803 } // Constraints = "", CodeSize = 2
1804
1805 let CodeSize = 2 in
1806 def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1807                "dec{b}\t$dst",
1808                [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
1809 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
1810 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1811                "dec{w}\t$dst",
1812                [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
1813              OpSize, Requires<[In32BitMode]>;
1814 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1815                "dec{l}\t$dst",
1816                [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
1817              Requires<[In32BitMode]>;
1818 } // CodeSize = 2
1819
1820 let Constraints = "", CodeSize = 2 in {
1821   def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
1822                [(store (add (loadi8 addr:$dst), -1), addr:$dst),
1823                 (implicit EFLAGS)]>;
1824   def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
1825                [(store (add (loadi16 addr:$dst), -1), addr:$dst),
1826                 (implicit EFLAGS)]>,
1827                OpSize, Requires<[In32BitMode]>;
1828   def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
1829                [(store (add (loadi32 addr:$dst), -1), addr:$dst),
1830                 (implicit EFLAGS)]>,
1831                Requires<[In32BitMode]>;
1832 } // Constraints = "", CodeSize = 2
1833 } // Defs = [EFLAGS]
1834
1835 // Logical operators...
1836 let Defs = [EFLAGS] in {
1837 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1838 def AND8rr  : I<0x20, MRMDestReg,
1839                (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1840                "and{b}\t{$src2, $dst|$dst, $src2}",
1841                [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
1842 def AND16rr : I<0x21, MRMDestReg,
1843                 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1844                 "and{w}\t{$src2, $dst|$dst, $src2}",
1845                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1846                                                       GR16:$src2))]>, OpSize;
1847 def AND32rr : I<0x21, MRMDestReg, 
1848                 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1849                 "and{l}\t{$src2, $dst|$dst, $src2}",
1850                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1851                                                       GR32:$src2))]>;
1852 }
1853
1854 // AND instructions with the destination register in REG and the source register
1855 //   in R/M.  Included for the disassembler.
1856 let isCodeGenOnly = 1 in {
1857 def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1858                   "and{b}\t{$src2, $dst|$dst, $src2}", []>;
1859 def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst), 
1860                     (ins GR16:$src1, GR16:$src2),
1861                    "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1862 def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst), 
1863                     (ins GR32:$src1, GR32:$src2),
1864                    "and{l}\t{$src2, $dst|$dst, $src2}", []>;
1865 }
1866
1867 def AND8rm   : I<0x22, MRMSrcMem, 
1868                  (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1869                  "and{b}\t{$src2, $dst|$dst, $src2}",
1870                 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1871                                                      (loadi8 addr:$src2)))]>;
1872 def AND16rm  : I<0x23, MRMSrcMem, 
1873                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1874                  "and{w}\t{$src2, $dst|$dst, $src2}",
1875                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1876                                                       (loadi16 addr:$src2)))]>,
1877                OpSize;
1878 def AND32rm  : I<0x23, MRMSrcMem,
1879                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1880                  "and{l}\t{$src2, $dst|$dst, $src2}",
1881                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1882                                                       (loadi32 addr:$src2)))]>;
1883
1884 def AND8ri   : Ii8<0x80, MRM4r, 
1885                    (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
1886                    "and{b}\t{$src2, $dst|$dst, $src2}",
1887                    [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1888                                                         imm:$src2))]>;
1889 def AND16ri  : Ii16<0x81, MRM4r, 
1890                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1891                     "and{w}\t{$src2, $dst|$dst, $src2}",
1892                     [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1893                                                           imm:$src2))]>, OpSize;
1894 def AND32ri  : Ii32<0x81, MRM4r, 
1895                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1896                     "and{l}\t{$src2, $dst|$dst, $src2}",
1897                     [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1898                                                           imm:$src2))]>;
1899 def AND16ri8 : Ii8<0x83, MRM4r, 
1900                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1901                    "and{w}\t{$src2, $dst|$dst, $src2}",
1902                    [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1903                                                          i16immSExt8:$src2))]>,
1904                    OpSize;
1905 def AND32ri8 : Ii8<0x83, MRM4r, 
1906                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1907                    "and{l}\t{$src2, $dst|$dst, $src2}",
1908                    [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1909                                                          i32immSExt8:$src2))]>;
1910
1911 let Constraints = "" in {
1912   def AND8mr   : I<0x20, MRMDestMem,
1913                    (outs), (ins i8mem :$dst, GR8 :$src),
1914                    "and{b}\t{$src, $dst|$dst, $src}",
1915                    [(store (and (load addr:$dst), GR8:$src), addr:$dst),
1916                     (implicit EFLAGS)]>;
1917   def AND16mr  : I<0x21, MRMDestMem,
1918                    (outs), (ins i16mem:$dst, GR16:$src),
1919                    "and{w}\t{$src, $dst|$dst, $src}",
1920                    [(store (and (load addr:$dst), GR16:$src), addr:$dst),
1921                     (implicit EFLAGS)]>,
1922                    OpSize;
1923   def AND32mr  : I<0x21, MRMDestMem,
1924                    (outs), (ins i32mem:$dst, GR32:$src),
1925                    "and{l}\t{$src, $dst|$dst, $src}",
1926                    [(store (and (load addr:$dst), GR32:$src), addr:$dst),
1927                     (implicit EFLAGS)]>;
1928   def AND8mi   : Ii8<0x80, MRM4m,
1929                      (outs), (ins i8mem :$dst, i8imm :$src),
1930                      "and{b}\t{$src, $dst|$dst, $src}",
1931                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
1932                        (implicit EFLAGS)]>;
1933   def AND16mi  : Ii16<0x81, MRM4m,
1934                       (outs), (ins i16mem:$dst, i16imm:$src),
1935                       "and{w}\t{$src, $dst|$dst, $src}",
1936                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
1937                        (implicit EFLAGS)]>,
1938                       OpSize;
1939   def AND32mi  : Ii32<0x81, MRM4m,
1940                       (outs), (ins i32mem:$dst, i32imm:$src),
1941                       "and{l}\t{$src, $dst|$dst, $src}",
1942                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
1943                        (implicit EFLAGS)]>;
1944   def AND16mi8 : Ii8<0x83, MRM4m,
1945                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1946                      "and{w}\t{$src, $dst|$dst, $src}",
1947                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
1948                  (implicit EFLAGS)]>,
1949                      OpSize;
1950   def AND32mi8 : Ii8<0x83, MRM4m,
1951                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1952                      "and{l}\t{$src, $dst|$dst, $src}",
1953                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
1954                  (implicit EFLAGS)]>;
1955
1956   def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
1957                    "and{b}\t{$src, %al|%al, $src}", []>;
1958   def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
1959                       "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1960   def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
1961                       "and{l}\t{$src, %eax|%eax, $src}", []>;
1962
1963 } // Constraints = ""
1964
1965
1966 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1967 def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), 
1968                  (ins GR8 :$src1, GR8 :$src2),
1969                  "or{b}\t{$src2, $dst|$dst, $src2}",
1970                  [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
1971 def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), 
1972                  (ins GR16:$src1, GR16:$src2),
1973                  "or{w}\t{$src2, $dst|$dst, $src2}",
1974                  [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
1975                OpSize;
1976 def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), 
1977                  (ins GR32:$src1, GR32:$src2),
1978                  "or{l}\t{$src2, $dst|$dst, $src2}",
1979                  [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
1980 }
1981
1982 // OR instructions with the destination register in REG and the source register
1983 //   in R/M.  Included for the disassembler.
1984 let isCodeGenOnly = 1 in {
1985 def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1986                   "or{b}\t{$src2, $dst|$dst, $src2}", []>;
1987 def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
1988                    (ins GR16:$src1, GR16:$src2),
1989                    "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1990 def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst), 
1991                    (ins GR32:$src1, GR32:$src2),
1992                    "or{l}\t{$src2, $dst|$dst, $src2}", []>;
1993 }
1994                   
1995 def OR8rm    : I<0x0A, MRMSrcMem, (outs GR8 :$dst), 
1996                  (ins GR8 :$src1, i8mem :$src2),
1997                  "or{b}\t{$src2, $dst|$dst, $src2}",
1998                 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
1999                                                     (load addr:$src2)))]>;
2000 def OR16rm   : I<0x0B, MRMSrcMem, (outs GR16:$dst), 
2001                  (ins GR16:$src1, i16mem:$src2),
2002                  "or{w}\t{$src2, $dst|$dst, $src2}",
2003                 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
2004                                                      (load addr:$src2)))]>,
2005                OpSize;
2006 def OR32rm   : I<0x0B, MRMSrcMem, (outs GR32:$dst), 
2007                  (ins GR32:$src1, i32mem:$src2),
2008                  "or{l}\t{$src2, $dst|$dst, $src2}",
2009                 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
2010                                                      (load addr:$src2)))]>;
2011
2012 def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), 
2013                     (ins GR8 :$src1, i8imm:$src2),
2014                     "or{b}\t{$src2, $dst|$dst, $src2}",
2015                     [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
2016 def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), 
2017                     (ins GR16:$src1, i16imm:$src2),
2018                     "or{w}\t{$src2, $dst|$dst, $src2}", 
2019                     [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
2020                                                         imm:$src2))]>, OpSize;
2021 def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), 
2022                     (ins GR32:$src1, i32imm:$src2),
2023                     "or{l}\t{$src2, $dst|$dst, $src2}",
2024                     [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
2025                                                          imm:$src2))]>;
2026
2027 def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), 
2028                    (ins GR16:$src1, i16i8imm:$src2),
2029                    "or{w}\t{$src2, $dst|$dst, $src2}",
2030                    [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
2031                                                 i16immSExt8:$src2))]>, OpSize;
2032 def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), 
2033                    (ins GR32:$src1, i32i8imm:$src2),
2034                    "or{l}\t{$src2, $dst|$dst, $src2}",
2035                    [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
2036                                                         i32immSExt8:$src2))]>;
2037 let Constraints = "" in {
2038   def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
2039                  "or{b}\t{$src, $dst|$dst, $src}",
2040                  [(store (or (load addr:$dst), GR8:$src), addr:$dst),
2041                   (implicit EFLAGS)]>;
2042   def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
2043                  "or{w}\t{$src, $dst|$dst, $src}",
2044                  [(store (or (load addr:$dst), GR16:$src), addr:$dst),
2045                   (implicit EFLAGS)]>, OpSize;
2046   def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2047                  "or{l}\t{$src, $dst|$dst, $src}",
2048                  [(store (or (load addr:$dst), GR32:$src), addr:$dst),
2049                   (implicit EFLAGS)]>;
2050   def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2051                  "or{b}\t{$src, $dst|$dst, $src}",
2052                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
2053                   (implicit EFLAGS)]>;
2054   def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
2055                  "or{w}\t{$src, $dst|$dst, $src}",
2056                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
2057                   (implicit EFLAGS)]>,
2058                  OpSize;
2059   def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
2060                  "or{l}\t{$src, $dst|$dst, $src}",
2061                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
2062                   (implicit EFLAGS)]>;
2063   def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
2064                  "or{w}\t{$src, $dst|$dst, $src}",
2065                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
2066                   (implicit EFLAGS)]>,
2067                      OpSize;
2068   def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
2069                  "or{l}\t{$src, $dst|$dst, $src}",
2070                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
2071                   (implicit EFLAGS)]>;
2072                   
2073   def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
2074                    "or{b}\t{$src, %al|%al, $src}", []>;
2075   def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
2076                       "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2077   def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
2078                       "or{l}\t{$src, %eax|%eax, $src}", []>;
2079 } // Constraints = ""
2080
2081
2082 let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
2083   def XOR8rr   : I<0x30, MRMDestReg,
2084                    (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
2085                    "xor{b}\t{$src2, $dst|$dst, $src2}",
2086                    [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2087                                                         GR8:$src2))]>;
2088   def XOR16rr  : I<0x31, MRMDestReg, 
2089                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
2090                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2091                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2092                                                          GR16:$src2))]>, OpSize;
2093   def XOR32rr  : I<0x31, MRMDestReg, 
2094                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
2095                    "xor{l}\t{$src2, $dst|$dst, $src2}",
2096                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2097                                                          GR32:$src2))]>;
2098 } // isCommutable = 1
2099
2100 // XOR instructions with the destination register in REG and the source register
2101 //   in R/M.  Included for the disassembler.
2102 let isCodeGenOnly = 1 in {
2103 def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2104                   "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
2105 def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst), 
2106                     (ins GR16:$src1, GR16:$src2),
2107                    "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2108 def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst), 
2109                     (ins GR32:$src1, GR32:$src2),
2110                    "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
2111 }
2112
2113 def XOR8rm   : I<0x32, MRMSrcMem, 
2114                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
2115                  "xor{b}\t{$src2, $dst|$dst, $src2}",
2116                  [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2117                                                       (load addr:$src2)))]>;
2118 def XOR16rm  : I<0x33, MRMSrcMem, 
2119                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
2120                  "xor{w}\t{$src2, $dst|$dst, $src2}",
2121                  [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2122                                                        (load addr:$src2)))]>,
2123                  OpSize;
2124 def XOR32rm  : I<0x33, MRMSrcMem, 
2125                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
2126                  "xor{l}\t{$src2, $dst|$dst, $src2}",
2127                  [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2128                                                        (load addr:$src2)))]>;
2129
2130 def XOR8ri  : Ii8<0x80, MRM6r, 
2131                   (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
2132                   "xor{b}\t{$src2, $dst|$dst, $src2}",
2133                   [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
2134 def XOR16ri : Ii16<0x81, MRM6r, 
2135                    (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
2136                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2137                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2138                                                          imm:$src2))]>, OpSize;
2139 def XOR32ri  : Ii32<0x81, MRM6r, 
2140                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
2141                     "xor{l}\t{$src2, $dst|$dst, $src2}",
2142                     [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2143                                                           imm:$src2))]>;
2144 def XOR16ri8 : Ii8<0x83, MRM6r, 
2145                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2146                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2147                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2148                                                          i16immSExt8:$src2))]>,
2149                    OpSize;
2150 def XOR32ri8 : Ii8<0x83, MRM6r, 
2151                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2152                    "xor{l}\t{$src2, $dst|$dst, $src2}",
2153                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2154                                                          i32immSExt8:$src2))]>;
2155
2156 let Constraints = "" in {
2157   def XOR8mr   : I<0x30, MRMDestMem,
2158                    (outs), (ins i8mem :$dst, GR8 :$src),
2159                    "xor{b}\t{$src, $dst|$dst, $src}",
2160                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
2161                     (implicit EFLAGS)]>;
2162   def XOR16mr  : I<0x31, MRMDestMem,
2163                    (outs), (ins i16mem:$dst, GR16:$src),
2164                    "xor{w}\t{$src, $dst|$dst, $src}",
2165                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
2166                     (implicit EFLAGS)]>,
2167                    OpSize;
2168   def XOR32mr  : I<0x31, MRMDestMem,
2169                    (outs), (ins i32mem:$dst, GR32:$src),
2170                    "xor{l}\t{$src, $dst|$dst, $src}",
2171                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
2172                     (implicit EFLAGS)]>;
2173   def XOR8mi   : Ii8<0x80, MRM6m,
2174                      (outs), (ins i8mem :$dst, i8imm :$src),
2175                      "xor{b}\t{$src, $dst|$dst, $src}",
2176                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
2177                      (implicit EFLAGS)]>;
2178   def XOR16mi  : Ii16<0x81, MRM6m,
2179                       (outs), (ins i16mem:$dst, i16imm:$src),
2180                       "xor{w}\t{$src, $dst|$dst, $src}",
2181                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
2182                     (implicit EFLAGS)]>,
2183                       OpSize;
2184   def XOR32mi  : Ii32<0x81, MRM6m,
2185                       (outs), (ins i32mem:$dst, i32imm:$src),
2186                       "xor{l}\t{$src, $dst|$dst, $src}",
2187                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
2188                     (implicit EFLAGS)]>;
2189   def XOR16mi8 : Ii8<0x83, MRM6m,
2190                      (outs), (ins i16mem:$dst, i16i8imm :$src),
2191                      "xor{w}\t{$src, $dst|$dst, $src}",
2192                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
2193                   (implicit EFLAGS)]>,
2194                      OpSize;
2195   def XOR32mi8 : Ii8<0x83, MRM6m,
2196                      (outs), (ins i32mem:$dst, i32i8imm :$src),
2197                      "xor{l}\t{$src, $dst|$dst, $src}",
2198                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
2199                   (implicit EFLAGS)]>;
2200                   
2201   def XOR8i8   : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
2202                       "xor{b}\t{$src, %al|%al, $src}", []>;
2203   def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
2204                       "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2205   def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
2206                       "xor{l}\t{$src, %eax|%eax, $src}", []>;
2207 } // Constraints = ""
2208 } // Defs = [EFLAGS]
2209
2210 // Shift instructions
2211 let Defs = [EFLAGS] in {
2212 let Uses = [CL] in {
2213 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
2214                  "shl{b}\t{%cl, $dst|$dst, CL}",
2215                  [(set GR8:$dst, (shl GR8:$src1, CL))]>;
2216 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
2217                  "shl{w}\t{%cl, $dst|$dst, CL}",
2218                  [(set GR16:$dst, (shl GR16:$src1, CL))]>, OpSize;
2219 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
2220                  "shl{l}\t{%cl, $dst|$dst, CL}",
2221                  [(set GR32:$dst, (shl GR32:$src1, CL))]>;
2222 } // Uses = [CL]
2223
2224 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2225                    "shl{b}\t{$src2, $dst|$dst, $src2}",
2226                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
2227                    
2228 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2229 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2230                    "shl{w}\t{$src2, $dst|$dst, $src2}",
2231                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2232 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2233                    "shl{l}\t{$src2, $dst|$dst, $src2}",
2234                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
2235
2236 // NOTE: We don't include patterns for shifts of a register by one, because
2237 // 'add reg,reg' is cheaper.
2238
2239 def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
2240                  "shl{b}\t$dst", []>;
2241 def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
2242                  "shl{w}\t$dst", []>, OpSize;
2243 def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
2244                  "shl{l}\t$dst", []>;
2245
2246 } // isConvertibleToThreeAddress = 1
2247
2248 let Constraints = "" in {
2249   let Uses = [CL] in {
2250   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
2251                    "shl{b}\t{%cl, $dst|$dst, CL}",
2252                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
2253   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
2254                    "shl{w}\t{%cl, $dst|$dst, CL}",
2255                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2256   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
2257                    "shl{l}\t{%cl, $dst|$dst, CL}",
2258                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
2259   }
2260   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
2261                      "shl{b}\t{$src, $dst|$dst, $src}",
2262                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2263   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
2264                      "shl{w}\t{$src, $dst|$dst, $src}",
2265                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2266                      OpSize;
2267   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
2268                      "shl{l}\t{$src, $dst|$dst, $src}",
2269                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2270
2271   // Shift by 1
2272   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
2273                    "shl{b}\t$dst",
2274                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2275   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
2276                    "shl{w}\t$dst",
2277                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2278                      OpSize;
2279   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
2280                    "shl{l}\t$dst",
2281                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2282 } // Constraints = ""
2283
2284 let Uses = [CL] in {
2285 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
2286                  "shr{b}\t{%cl, $dst|$dst, CL}",
2287                  [(set GR8:$dst, (srl GR8:$src1, CL))]>;
2288 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
2289                  "shr{w}\t{%cl, $dst|$dst, CL}",
2290                  [(set GR16:$dst, (srl GR16:$src1, CL))]>, OpSize;
2291 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2292                  "shr{l}\t{%cl, $dst|$dst, CL}",
2293                  [(set GR32:$dst, (srl GR32:$src1, CL))]>;
2294 }
2295
2296 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2297                    "shr{b}\t{$src2, $dst|$dst, $src2}",
2298                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
2299 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2300                    "shr{w}\t{$src2, $dst|$dst, $src2}",
2301                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2302 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2303                    "shr{l}\t{$src2, $dst|$dst, $src2}",
2304                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
2305
2306 // Shift by 1
2307 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
2308                  "shr{b}\t$dst",
2309                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
2310 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
2311                  "shr{w}\t$dst",
2312                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
2313 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2314                  "shr{l}\t$dst",
2315                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
2316
2317 let Constraints = "" in {
2318   let Uses = [CL] in {
2319   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
2320                    "shr{b}\t{%cl, $dst|$dst, CL}",
2321                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
2322   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
2323                    "shr{w}\t{%cl, $dst|$dst, CL}",
2324                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
2325                    OpSize;
2326   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
2327                    "shr{l}\t{%cl, $dst|$dst, CL}",
2328                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
2329   }
2330   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
2331                      "shr{b}\t{$src, $dst|$dst, $src}",
2332                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2333   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
2334                      "shr{w}\t{$src, $dst|$dst, $src}",
2335                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2336                      OpSize;
2337   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
2338                      "shr{l}\t{$src, $dst|$dst, $src}",
2339                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2340
2341   // Shift by 1
2342   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
2343                    "shr{b}\t$dst",
2344                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2345   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
2346                    "shr{w}\t$dst",
2347                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
2348   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
2349                    "shr{l}\t$dst",
2350                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2351 } // Constraints = ""
2352
2353 let Uses = [CL] in {
2354 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2355                  "sar{b}\t{%cl, $dst|$dst, CL}",
2356                  [(set GR8:$dst, (sra GR8:$src1, CL))]>;
2357 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2358                  "sar{w}\t{%cl, $dst|$dst, CL}",
2359                  [(set GR16:$dst, (sra GR16:$src1, CL))]>, OpSize;
2360 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2361                  "sar{l}\t{%cl, $dst|$dst, CL}",
2362                  [(set GR32:$dst, (sra GR32:$src1, CL))]>;
2363 }
2364
2365 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2366                    "sar{b}\t{$src2, $dst|$dst, $src2}",
2367                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
2368 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2369                    "sar{w}\t{$src2, $dst|$dst, $src2}",
2370                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
2371                    OpSize;
2372 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2373                    "sar{l}\t{$src2, $dst|$dst, $src2}",
2374                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
2375
2376 // Shift by 1
2377 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2378                  "sar{b}\t$dst",
2379                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
2380 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2381                  "sar{w}\t$dst",
2382                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
2383 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2384                  "sar{l}\t$dst",
2385                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
2386
2387 let Constraints = "" in {
2388   let Uses = [CL] in {
2389   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
2390                    "sar{b}\t{%cl, $dst|$dst, CL}",
2391                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
2392   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
2393                    "sar{w}\t{%cl, $dst|$dst, CL}",
2394                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2395   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
2396                    "sar{l}\t{%cl, $dst|$dst, CL}",
2397                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
2398   }
2399   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
2400                      "sar{b}\t{$src, $dst|$dst, $src}",
2401                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2402   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
2403                      "sar{w}\t{$src, $dst|$dst, $src}",
2404                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2405                      OpSize;
2406   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
2407                      "sar{l}\t{$src, $dst|$dst, $src}",
2408                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2409
2410   // Shift by 1
2411   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
2412                    "sar{b}\t$dst",
2413                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2414   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
2415                    "sar{w}\t$dst",
2416                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2417                      OpSize;
2418   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
2419                    "sar{l}\t$dst",
2420                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2421 } // Constraints = ""
2422
2423 // Rotate instructions
2424
2425 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2426                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2427 let Uses = [CL] in {
2428 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2429                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2430 }
2431 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2432                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2433   
2434 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2435                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2436 let Uses = [CL] in {
2437 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2438                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2439 }
2440 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2441                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2442
2443 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2444                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2445 let Uses = [CL] in {
2446 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2447                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2448 }
2449 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2450                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2451                   
2452 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2453                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2454 let Uses = [CL] in {
2455 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2456                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2457 }
2458 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2459                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2460   
2461 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2462                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2463 let Uses = [CL] in {
2464 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2465                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2466 }
2467 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2468                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2469
2470 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2471                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2472 let Uses = [CL] in {
2473 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2474                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2475 }
2476 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2477                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2478
2479 let Constraints = "" in {
2480 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
2481                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2482 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2483                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2484 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
2485                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2486 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2487                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2488 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
2489                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2490 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2491                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2492 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
2493                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2494 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2495                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2496 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
2497                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2498 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2499                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2500 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
2501                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2502 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2503                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2504
2505 let Uses = [CL] in {
2506 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
2507                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2508 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
2509                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2510 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
2511                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2512 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
2513                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2514 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
2515                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2516 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
2517                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2518 }
2519 } // Constraints = ""
2520
2521 // FIXME: provide shorter instructions when imm8 == 1
2522 let Uses = [CL] in {
2523 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2524                  "rol{b}\t{%cl, $dst|$dst, CL}",
2525                  [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
2526 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2527                  "rol{w}\t{%cl, $dst|$dst, CL}",
2528                  [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize;
2529 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2530                  "rol{l}\t{%cl, $dst|$dst, CL}",
2531                  [(set GR32:$dst, (rotl GR32:$src1, CL))]>;
2532 }
2533
2534 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2535                    "rol{b}\t{$src2, $dst|$dst, $src2}",
2536                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
2537 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2538                    "rol{w}\t{$src2, $dst|$dst, $src2}",
2539                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, 
2540                    OpSize;
2541 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2542                    "rol{l}\t{$src2, $dst|$dst, $src2}",
2543                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
2544
2545 // Rotate by 1
2546 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2547                  "rol{b}\t$dst",
2548                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
2549 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2550                  "rol{w}\t$dst",
2551                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
2552 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2553                  "rol{l}\t$dst",
2554                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
2555
2556 let Constraints = "" in {
2557   let Uses = [CL] in {
2558   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
2559                    "rol{b}\t{%cl, $dst|$dst, CL}",
2560                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
2561   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
2562                    "rol{w}\t{%cl, $dst|$dst, CL}",
2563                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2564   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
2565                    "rol{l}\t{%cl, $dst|$dst, CL}",
2566                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
2567   }
2568   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
2569                      "rol{b}\t{$src, $dst|$dst, $src}",
2570                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2571   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
2572                      "rol{w}\t{$src, $dst|$dst, $src}",
2573                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2574                      OpSize;
2575   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
2576                      "rol{l}\t{$src, $dst|$dst, $src}",
2577                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2578
2579   // Rotate by 1
2580   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
2581                    "rol{b}\t$dst",
2582                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2583   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
2584                    "rol{w}\t$dst",
2585                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2586                      OpSize;
2587   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
2588                    "rol{l}\t$dst",
2589                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2590 } // Constraints = ""
2591
2592 let Uses = [CL] in {
2593 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2594                  "ror{b}\t{%cl, $dst|$dst, CL}",
2595                  [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
2596 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2597                  "ror{w}\t{%cl, $dst|$dst, CL}",
2598                  [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize;
2599 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2600                  "ror{l}\t{%cl, $dst|$dst, CL}",
2601                  [(set GR32:$dst, (rotr GR32:$src1, CL))]>;
2602 }
2603
2604 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2605                    "ror{b}\t{$src2, $dst|$dst, $src2}",
2606                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
2607 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2608                    "ror{w}\t{$src2, $dst|$dst, $src2}",
2609                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, 
2610                    OpSize;
2611 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2612                    "ror{l}\t{$src2, $dst|$dst, $src2}",
2613                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
2614
2615 // Rotate by 1
2616 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2617                  "ror{b}\t$dst",
2618                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
2619 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2620                  "ror{w}\t$dst",
2621                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
2622 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2623                  "ror{l}\t$dst",
2624                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
2625
2626 let Constraints = "" in {
2627   let Uses = [CL] in {
2628   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
2629                    "ror{b}\t{%cl, $dst|$dst, CL}",
2630                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
2631   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
2632                    "ror{w}\t{%cl, $dst|$dst, CL}",
2633                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2634   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
2635                    "ror{l}\t{%cl, $dst|$dst, CL}",
2636                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
2637   }
2638   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2639                      "ror{b}\t{$src, $dst|$dst, $src}",
2640                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2641   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
2642                      "ror{w}\t{$src, $dst|$dst, $src}",
2643                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2644                      OpSize;
2645   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
2646                      "ror{l}\t{$src, $dst|$dst, $src}",
2647                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2648
2649   // Rotate by 1
2650   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
2651                    "ror{b}\t$dst",
2652                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2653   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
2654                    "ror{w}\t$dst",
2655                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2656                      OpSize;
2657   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
2658                    "ror{l}\t$dst",
2659                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2660 } // Constraints = ""
2661
2662
2663 // Double shift instructions (generalizations of rotate)
2664 let Uses = [CL] in {
2665 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
2666                    (ins GR32:$src1, GR32:$src2),
2667                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2668                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
2669 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
2670                    (ins GR32:$src1, GR32:$src2),
2671                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2672                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
2673 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
2674                    (ins GR16:$src1, GR16:$src2),
2675                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2676                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
2677                    TB, OpSize;
2678 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
2679                    (ins GR16:$src1, GR16:$src2),
2680                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2681                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
2682                    TB, OpSize;
2683 }
2684
2685 let isCommutable = 1 in {  // These instructions commute to each other.
2686 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
2687                      (outs GR32:$dst), 
2688                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2689                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2690                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
2691                                       (i8 imm:$src3)))]>,
2692                  TB;
2693 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
2694                      (outs GR32:$dst), 
2695                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2696                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2697                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
2698                                       (i8 imm:$src3)))]>,
2699                  TB;
2700 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
2701                      (outs GR16:$dst), 
2702                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2703                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2704                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
2705                                       (i8 imm:$src3)))]>,
2706                      TB, OpSize;
2707 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
2708                      (outs GR16:$dst), 
2709                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2710                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2711                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
2712                                       (i8 imm:$src3)))]>,
2713                      TB, OpSize;
2714 }
2715
2716 let Constraints = "" in {
2717   let Uses = [CL] in {
2718   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2719                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2720                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
2721                        addr:$dst)]>, TB;
2722   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2723                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2724                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
2725                       addr:$dst)]>, TB;
2726   }
2727   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
2728                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2729                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2730                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
2731                                         (i8 imm:$src3)), addr:$dst)]>,
2732                       TB;
2733   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
2734                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2735                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2736                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
2737                                          (i8 imm:$src3)), addr:$dst)]>,
2738                        TB;
2739
2740   let Uses = [CL] in {
2741   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2742                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2743                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
2744                        addr:$dst)]>, TB, OpSize;
2745   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2746                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2747                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
2748                       addr:$dst)]>, TB, OpSize;
2749   }
2750   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
2751                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2752                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2753                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
2754                                         (i8 imm:$src3)), addr:$dst)]>,
2755                       TB, OpSize;
2756   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
2757                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2758                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2759                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
2760                                         (i8 imm:$src3)), addr:$dst)]>,
2761                        TB, OpSize;
2762 } // Constraints = ""
2763 } // Defs = [EFLAGS]
2764
2765
2766 // Arithmetic.
2767 let Defs = [EFLAGS] in {
2768 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
2769 // Register-Register Addition
2770 def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
2771                                     (ins GR8 :$src1, GR8 :$src2),
2772                   "add{b}\t{$src2, $dst|$dst, $src2}",
2773                   [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
2774
2775 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2776 // Register-Register Addition
2777 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
2778                                    (ins GR16:$src1, GR16:$src2),
2779                  "add{w}\t{$src2, $dst|$dst, $src2}",
2780                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2781                                                        GR16:$src2))]>, OpSize;
2782 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
2783                                    (ins GR32:$src1, GR32:$src2),
2784                  "add{l}\t{$src2, $dst|$dst, $src2}",
2785                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2786                                                        GR32:$src2))]>;
2787 } // end isConvertibleToThreeAddress
2788 } // end isCommutable
2789
2790 // These are alternate spellings for use by the disassembler, we mark them as
2791 // code gen only to ensure they aren't matched by the assembler.
2792 let isCodeGenOnly = 1 in {
2793   def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2794                    "add{b}\t{$src2, $dst|$dst, $src2}", []>;
2795   def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
2796                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2797   def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
2798                     "add{l}\t{$src2, $dst|$dst, $src2}", []>;
2799 }
2800
2801 // Register-Memory Addition
2802 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2803                                   (ins GR8 :$src1, i8mem :$src2),
2804                  "add{b}\t{$src2, $dst|$dst, $src2}",
2805                  [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
2806                                                       (load addr:$src2)))]>;
2807 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
2808                                   (ins GR16:$src1, i16mem:$src2),
2809                  "add{w}\t{$src2, $dst|$dst, $src2}",
2810                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2811                                                   (load addr:$src2)))]>, OpSize;
2812 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
2813                                   (ins GR32:$src1, i32mem:$src2),
2814                  "add{l}\t{$src2, $dst|$dst, $src2}",
2815                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2816                                                        (load addr:$src2)))]>;
2817                   
2818 // Register-Integer Addition
2819 def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2820                     "add{b}\t{$src2, $dst|$dst, $src2}",
2821                     [(set GR8:$dst, EFLAGS,
2822                           (X86add_flag GR8:$src1, imm:$src2))]>;
2823
2824 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2825 // Register-Integer Addition
2826 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
2827                                  (ins GR16:$src1, i16imm:$src2),
2828                     "add{w}\t{$src2, $dst|$dst, $src2}",
2829                     [(set GR16:$dst, EFLAGS,
2830                           (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
2831 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
2832                                  (ins GR32:$src1, i32imm:$src2),
2833                     "add{l}\t{$src2, $dst|$dst, $src2}",
2834                     [(set GR32:$dst, EFLAGS, 
2835                           (X86add_flag GR32:$src1, imm:$src2))]>;
2836 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2837                                 (ins GR16:$src1, i16i8imm:$src2),
2838                    "add{w}\t{$src2, $dst|$dst, $src2}",
2839                    [(set GR16:$dst, EFLAGS,
2840                          (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2841 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2842                                 (ins GR32:$src1, i32i8imm:$src2),
2843                    "add{l}\t{$src2, $dst|$dst, $src2}",
2844                    [(set GR32:$dst, EFLAGS,
2845                          (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
2846 }
2847
2848 let Constraints = "" in {
2849   // Memory-Register Addition
2850   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2851                    "add{b}\t{$src2, $dst|$dst, $src2}",
2852                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2853                     (implicit EFLAGS)]>;
2854   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2855                    "add{w}\t{$src2, $dst|$dst, $src2}",
2856                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2857                     (implicit EFLAGS)]>, OpSize;
2858   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2859                    "add{l}\t{$src2, $dst|$dst, $src2}",
2860                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2861                     (implicit EFLAGS)]>;
2862   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
2863                      "add{b}\t{$src2, $dst|$dst, $src2}",
2864                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2865                     (implicit EFLAGS)]>;
2866   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
2867                       "add{w}\t{$src2, $dst|$dst, $src2}",
2868                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2869                    (implicit EFLAGS)]>, OpSize;
2870   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
2871                       "add{l}\t{$src2, $dst|$dst, $src2}",
2872                       [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2873                        (implicit EFLAGS)]>;
2874   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2875                      "add{w}\t{$src2, $dst|$dst, $src2}",
2876                      [(store (add (load addr:$dst), i16immSExt8:$src2),
2877                                   addr:$dst),
2878                       (implicit EFLAGS)]>, OpSize;
2879   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2880                      "add{l}\t{$src2, $dst|$dst, $src2}",
2881                   [(store (add (load addr:$dst), i32immSExt8:$src2),
2882                                addr:$dst),
2883                    (implicit EFLAGS)]>;
2884
2885   // addition to rAX
2886   def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
2887                    "add{b}\t{$src, %al|%al, $src}", []>;
2888   def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
2889                       "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2890   def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
2891                       "add{l}\t{$src, %eax|%eax, $src}", []>;
2892 } // Constraints = ""
2893
2894 let Uses = [EFLAGS] in {
2895 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
2896 def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2897                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2898                  [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
2899 def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
2900                                    (ins GR16:$src1, GR16:$src2),
2901                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2902                  [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
2903 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
2904                                    (ins GR32:$src1, GR32:$src2),
2905                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2906                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
2907 }
2908
2909 let isCodeGenOnly = 1 in {
2910 def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2911                  "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
2912 def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst), 
2913                     (ins GR16:$src1, GR16:$src2),
2914                     "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2915 def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst), 
2916                     (ins GR32:$src1, GR32:$src2),
2917                     "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
2918 }
2919
2920 def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
2921                                    (ins GR8:$src1, i8mem:$src2),
2922                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2923                  [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
2924 def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
2925                                    (ins GR16:$src1, i16mem:$src2),
2926                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2927                  [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
2928                  OpSize;
2929 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
2930                                    (ins GR32:$src1, i32mem:$src2),
2931                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2932                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2933 def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2934                     "adc{b}\t{$src2, $dst|$dst, $src2}",
2935                  [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
2936 def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
2937                                  (ins GR16:$src1, i16imm:$src2),
2938                     "adc{w}\t{$src2, $dst|$dst, $src2}",
2939                  [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
2940 def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2941                                 (ins GR16:$src1, i16i8imm:$src2),
2942                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2943                  [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2944                  OpSize;
2945 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
2946                                  (ins GR32:$src1, i32imm:$src2),
2947                     "adc{l}\t{$src2, $dst|$dst, $src2}",
2948                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
2949 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2950                                 (ins GR32:$src1, i32i8imm:$src2),
2951                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2952                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
2953
2954 let Constraints = "" in {
2955   def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2956                    "adc{b}\t{$src2, $dst|$dst, $src2}",
2957                    [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2958   def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2959                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2960                    [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2961                    OpSize;
2962   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2963                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2964                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2965   def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
2966                       "adc{b}\t{$src2, $dst|$dst, $src2}",
2967                   [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2968   def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
2969                       "adc{w}\t{$src2, $dst|$dst, $src2}",
2970                   [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2971                   OpSize;
2972   def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2973                      "adc{w}\t{$src2, $dst|$dst, $src2}",
2974                [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2975                OpSize;
2976   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
2977                       "adc{l}\t{$src2, $dst|$dst, $src2}",
2978                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2979   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2980                      "adc{l}\t{$src2, $dst|$dst, $src2}",
2981                [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2982
2983   def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
2984                    "adc{b}\t{$src, %al|%al, $src}", []>;
2985   def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
2986                       "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2987   def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
2988                       "adc{l}\t{$src, %eax|%eax, $src}", []>;
2989 } // Constraints = ""
2990 } // Uses = [EFLAGS]
2991
2992 // Register-Register Subtraction
2993 def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2994                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2995                 [(set GR8:$dst, EFLAGS,
2996                       (X86sub_flag GR8:$src1, GR8:$src2))]>;
2997 def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2998                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2999                 [(set GR16:$dst, EFLAGS,
3000                       (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
3001 def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
3002                 "sub{l}\t{$src2, $dst|$dst, $src2}",
3003                 [(set GR32:$dst, EFLAGS,
3004                       (X86sub_flag GR32:$src1, GR32:$src2))]>;
3005
3006 let isCodeGenOnly = 1 in {
3007 def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
3008                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
3009 def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst), 
3010                     (ins GR16:$src1, GR16:$src2),
3011                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
3012 def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst), 
3013                     (ins GR32:$src1, GR32:$src2),
3014                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
3015 }
3016
3017 // Register-Memory Subtraction
3018 def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
3019                                  (ins GR8 :$src1, i8mem :$src2),
3020                 "sub{b}\t{$src2, $dst|$dst, $src2}",
3021                 [(set GR8:$dst, EFLAGS,
3022                       (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
3023 def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
3024                                  (ins GR16:$src1, i16mem:$src2),
3025                 "sub{w}\t{$src2, $dst|$dst, $src2}",
3026                 [(set GR16:$dst, EFLAGS,
3027                       (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
3028 def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
3029                                  (ins GR32:$src1, i32mem:$src2),
3030                 "sub{l}\t{$src2, $dst|$dst, $src2}",
3031                 [(set GR32:$dst, EFLAGS,
3032                       (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
3033
3034 // Register-Integer Subtraction
3035 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
3036                                  (ins GR8:$src1, i8imm:$src2),
3037                     "sub{b}\t{$src2, $dst|$dst, $src2}",
3038                     [(set GR8:$dst, EFLAGS,
3039                           (X86sub_flag GR8:$src1, imm:$src2))]>;
3040 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
3041                                  (ins GR16:$src1, i16imm:$src2),
3042                     "sub{w}\t{$src2, $dst|$dst, $src2}",
3043                     [(set GR16:$dst, EFLAGS,
3044                           (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
3045 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
3046                                  (ins GR32:$src1, i32imm:$src2),
3047                     "sub{l}\t{$src2, $dst|$dst, $src2}",
3048                     [(set GR32:$dst, EFLAGS,
3049                           (X86sub_flag GR32:$src1, imm:$src2))]>;
3050 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
3051                                 (ins GR16:$src1, i16i8imm:$src2),
3052                    "sub{w}\t{$src2, $dst|$dst, $src2}",
3053                    [(set GR16:$dst, EFLAGS,
3054                          (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
3055 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
3056                                 (ins GR32:$src1, i32i8imm:$src2),
3057                    "sub{l}\t{$src2, $dst|$dst, $src2}",
3058                    [(set GR32:$dst, EFLAGS,
3059                          (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
3060
3061 let Constraints = "" in {
3062   // Memory-Register Subtraction
3063   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
3064                    "sub{b}\t{$src2, $dst|$dst, $src2}",
3065                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
3066                     (implicit EFLAGS)]>;
3067   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3068                    "sub{w}\t{$src2, $dst|$dst, $src2}",
3069                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
3070                     (implicit EFLAGS)]>, OpSize;
3071   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3072                    "sub{l}\t{$src2, $dst|$dst, $src2}",
3073                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
3074                     (implicit EFLAGS)]>;
3075
3076   // Memory-Integer Subtraction
3077   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
3078                      "sub{b}\t{$src2, $dst|$dst, $src2}",
3079                      [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
3080                       (implicit EFLAGS)]>;
3081   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3082                       "sub{w}\t{$src2, $dst|$dst, $src2}",
3083                       [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
3084                        (implicit EFLAGS)]>, OpSize;
3085   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3086                       "sub{l}\t{$src2, $dst|$dst, $src2}",
3087                       [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
3088                        (implicit EFLAGS)]>;
3089   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
3090                      "sub{w}\t{$src2, $dst|$dst, $src2}",
3091                      [(store (sub (load addr:$dst), i16immSExt8:$src2),
3092                              addr:$dst),
3093                       (implicit EFLAGS)]>, OpSize;
3094   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3095                      "sub{l}\t{$src2, $dst|$dst, $src2}",
3096                      [(store (sub (load addr:$dst), i32immSExt8:$src2),
3097                              addr:$dst),
3098                       (implicit EFLAGS)]>;
3099                       
3100   def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
3101                    "sub{b}\t{$src, %al|%al, $src}", []>;
3102   def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
3103                       "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3104   def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
3105                       "sub{l}\t{$src, %eax|%eax, $src}", []>;
3106 } // Constraints = ""
3107
3108 let Uses = [EFLAGS] in {
3109 def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
3110                                      (ins GR8:$src1, GR8:$src2),
3111                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
3112                  [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
3113 def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
3114                                      (ins GR16:$src1, GR16:$src2),
3115                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
3116                  [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
3117 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
3118                                       (ins GR32:$src1, GR32:$src2),
3119                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
3120                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
3121
3122 let Constraints = "" in {
3123   def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
3124                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
3125                    [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
3126   def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
3127                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
3128                    [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
3129                    OpSize;
3130   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3131                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
3132                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
3133   def SBB8mi  : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
3134                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3135                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
3136   def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3137                       "sbb{w}\t{$src2, $dst|$dst, $src2}",
3138                   [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
3139                   OpSize;
3140   def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
3141                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
3142                [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
3143                OpSize;
3144   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3145                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
3146                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
3147   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
3148                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
3149                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
3150                
3151   def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
3152                    "sbb{b}\t{$src, %al|%al, $src}", []>;
3153   def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
3154                       "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3155   def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
3156                       "sbb{l}\t{$src, %eax|%eax, $src}", []>;
3157 } // Constraints = ""
3158
3159 let isCodeGenOnly = 1 in {
3160 def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
3161                    "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
3162 def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst), 
3163                     (ins GR16:$src1, GR16:$src2),
3164                     "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
3165 def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst), 
3166                     (ins GR32:$src1, GR32:$src2),
3167                     "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
3168 }
3169
3170 def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
3171                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3172                     [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
3173 def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
3174                                   (ins GR16:$src1, i16mem:$src2),
3175                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
3176                     [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
3177                     OpSize;
3178 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
3179                                   (ins GR32:$src1, i32mem:$src2),
3180                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
3181                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
3182 def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
3183                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3184                     [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
3185 def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
3186                                  (ins GR16:$src1, i16imm:$src2),
3187                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
3188                     [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
3189 def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
3190                                 (ins GR16:$src1, i16i8imm:$src2),
3191                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
3192                    [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
3193                    OpSize;
3194 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
3195                                  (ins GR32:$src1, i32imm:$src2),
3196                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
3197                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
3198 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
3199                                 (ins GR32:$src1, i32i8imm:$src2),
3200                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
3201                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
3202 } // Uses = [EFLAGS]
3203 } // Defs = [EFLAGS]
3204
3205 let Defs = [EFLAGS] in {
3206 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
3207 // Register-Register Signed Integer Multiply
3208 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
3209                  "imul{w}\t{$src2, $dst|$dst, $src2}",
3210                  [(set GR16:$dst, EFLAGS,
3211                        (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
3212 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
3213                  "imul{l}\t{$src2, $dst|$dst, $src2}",
3214                  [(set GR32:$dst, EFLAGS,
3215                        (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
3216 }
3217
3218 // Register-Memory Signed Integer Multiply
3219 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
3220                                   (ins GR16:$src1, i16mem:$src2),
3221                  "imul{w}\t{$src2, $dst|$dst, $src2}",
3222                  [(set GR16:$dst, EFLAGS,
3223                        (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
3224                TB, OpSize;
3225 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), 
3226                  (ins GR32:$src1, i32mem:$src2),
3227                  "imul{l}\t{$src2, $dst|$dst, $src2}",
3228                  [(set GR32:$dst, EFLAGS,
3229                        (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
3230 } // Defs = [EFLAGS]
3231 } // end Two Address instructions
3232
3233 // Suprisingly enough, these are not two address instructions!
3234 let Defs = [EFLAGS] in {
3235 // Register-Integer Signed Integer Multiply
3236 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
3237                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
3238                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3239                       [(set GR16:$dst, EFLAGS, 
3240                             (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
3241 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
3242                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
3243                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3244                       [(set GR32:$dst, EFLAGS,
3245                             (X86smul_flag GR32:$src1, imm:$src2))]>;
3246 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
3247                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
3248                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3249                      [(set GR16:$dst, EFLAGS,
3250                            (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
3251                  OpSize;
3252 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
3253                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
3254                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3255                      [(set GR32:$dst, EFLAGS,
3256                            (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
3257
3258 // Memory-Integer Signed Integer Multiply
3259 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                     // GR16 = [mem16]*I16
3260                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
3261                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3262                       [(set GR16:$dst, EFLAGS,
3263                             (X86smul_flag (load addr:$src1), imm:$src2))]>,
3264                  OpSize;
3265 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                     // GR32 = [mem32]*I32
3266                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
3267                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3268                       [(set GR32:$dst, EFLAGS,
3269                             (X86smul_flag (load addr:$src1), imm:$src2))]>;
3270 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
3271                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
3272                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3273                      [(set GR16:$dst, EFLAGS,
3274                            (X86smul_flag (load addr:$src1),
3275                                          i16immSExt8:$src2))]>, OpSize;
3276 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
3277                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
3278                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3279                      [(set GR32:$dst, EFLAGS,
3280                            (X86smul_flag (load addr:$src1),
3281                                          i32immSExt8:$src2))]>;
3282 } // Defs = [EFLAGS]
3283
3284 //===----------------------------------------------------------------------===//
3285 // Test instructions are just like AND, except they don't generate a result.
3286 //
3287 let Defs = [EFLAGS] in {
3288 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
3289 def TEST8rr  : I<0x84, MRMSrcReg, (outs),  (ins GR8:$src1, GR8:$src2),
3290                      "test{b}\t{$src2, $src1|$src1, $src2}",
3291                      [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
3292 def TEST16rr : I<0x85, MRMSrcReg, (outs),  (ins GR16:$src1, GR16:$src2),
3293                      "test{w}\t{$src2, $src1|$src1, $src2}",
3294                      [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
3295                       0))]>,
3296                  OpSize;
3297 def TEST32rr : I<0x85, MRMSrcReg, (outs),  (ins GR32:$src1, GR32:$src2),
3298                      "test{l}\t{$src2, $src1|$src1, $src2}",
3299                      [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
3300                       0))]>;
3301 }
3302
3303 def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
3304                    "test{b}\t{$src, %al|%al, $src}", []>;
3305 def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
3306                      "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3307 def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
3308                      "test{l}\t{$src, %eax|%eax, $src}", []>;
3309
3310 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
3311                      "test{b}\t{$src2, $src1|$src1, $src2}",
3312                      [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
3313                        0))]>;
3314 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
3315                      "test{w}\t{$src2, $src1|$src1, $src2}",
3316                      [(set EFLAGS, (X86cmp (and GR16:$src1,
3317                                          (loadi16 addr:$src2)), 0))]>, OpSize;
3318 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
3319                      "test{l}\t{$src2, $src1|$src1, $src2}",
3320                      [(set EFLAGS, (X86cmp (and GR32:$src1,
3321                                                 (loadi32 addr:$src2)), 0))]>;
3322
3323 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
3324                     (outs),  (ins GR8:$src1, i8imm:$src2),
3325                     "test{b}\t{$src2, $src1|$src1, $src2}",
3326                     [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
3327 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
3328                     (outs),  (ins GR16:$src1, i16imm:$src2),
3329                     "test{w}\t{$src2, $src1|$src1, $src2}",
3330                     [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
3331                     OpSize;
3332 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
3333                     (outs),  (ins GR32:$src1, i32imm:$src2),
3334                     "test{l}\t{$src2, $src1|$src1, $src2}",
3335                     [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
3336
3337 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
3338                     (outs), (ins i8mem:$src1, i8imm:$src2),
3339                     "test{b}\t{$src2, $src1|$src1, $src2}",
3340                     [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
3341                      0))]>;
3342 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
3343                     (outs), (ins i16mem:$src1, i16imm:$src2),
3344                     "test{w}\t{$src2, $src1|$src1, $src2}",
3345                     [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
3346                      0))]>, OpSize;
3347 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
3348                     (outs), (ins i32mem:$src1, i32imm:$src2),
3349                     "test{l}\t{$src2, $src1|$src1, $src2}",
3350                     [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
3351                      0))]>;
3352 } // Defs = [EFLAGS]
3353
3354
3355 // Condition code ops, incl. set if equal/not equal/...
3356 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
3357 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
3358 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
3359 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
3360
3361 let Uses = [EFLAGS] in {
3362 // Use sbb to materialize carry bit.
3363 let Defs = [EFLAGS], isCodeGenOnly = 1 in {
3364 // FIXME: These are pseudo ops that should be replaced with Pat<> patterns.
3365 // However, Pat<> can't replicate the destination reg into the inputs of the
3366 // result.
3367 // FIXME: Change these to have encoding Pseudo when X86MCCodeEmitter replaces
3368 // X86CodeEmitter.
3369 def SETB_C8r : I<0x18, MRMInitReg, (outs GR8:$dst), (ins), "",
3370                  [(set GR8:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3371 def SETB_C16r : I<0x19, MRMInitReg, (outs GR16:$dst), (ins), "",
3372                  [(set GR16:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>,
3373                 OpSize;
3374 def SETB_C32r : I<0x19, MRMInitReg, (outs GR32:$dst), (ins), "",
3375                  [(set GR32:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3376 } // isCodeGenOnly
3377
3378 def SETEr    : I<0x94, MRM0r, 
3379                  (outs GR8   :$dst), (ins),
3380                  "sete\t$dst",
3381                  [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
3382                TB;                        // GR8 = ==
3383 def SETEm    : I<0x94, MRM0m, 
3384                  (outs), (ins i8mem:$dst),
3385                  "sete\t$dst",
3386                  [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
3387                TB;                        // [mem8] = ==
3388
3389 def SETNEr   : I<0x95, MRM0r, 
3390                  (outs GR8   :$dst), (ins),
3391                  "setne\t$dst",
3392                  [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
3393                TB;                        // GR8 = !=
3394 def SETNEm   : I<0x95, MRM0m, 
3395                  (outs), (ins i8mem:$dst),
3396                  "setne\t$dst",
3397                  [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
3398                TB;                        // [mem8] = !=
3399
3400 def SETLr    : I<0x9C, MRM0r, 
3401                  (outs GR8   :$dst), (ins),
3402                  "setl\t$dst",
3403                  [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
3404                TB;                        // GR8 = <  signed
3405 def SETLm    : I<0x9C, MRM0m, 
3406                  (outs), (ins i8mem:$dst),
3407                  "setl\t$dst",
3408                  [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
3409                TB;                        // [mem8] = <  signed
3410
3411 def SETGEr   : I<0x9D, MRM0r, 
3412                  (outs GR8   :$dst), (ins),
3413                  "setge\t$dst",
3414                  [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
3415                TB;                        // GR8 = >= signed
3416 def SETGEm   : I<0x9D, MRM0m, 
3417                  (outs), (ins i8mem:$dst),
3418                  "setge\t$dst",
3419                  [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
3420                TB;                        // [mem8] = >= signed
3421
3422 def SETLEr   : I<0x9E, MRM0r, 
3423                  (outs GR8   :$dst), (ins),
3424                  "setle\t$dst",
3425                  [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
3426                TB;                        // GR8 = <= signed
3427 def SETLEm   : I<0x9E, MRM0m, 
3428                  (outs), (ins i8mem:$dst),
3429                  "setle\t$dst",
3430                  [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
3431                TB;                        // [mem8] = <= signed
3432
3433 def SETGr    : I<0x9F, MRM0r, 
3434                  (outs GR8   :$dst), (ins),
3435                  "setg\t$dst",
3436                  [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
3437                TB;                        // GR8 = >  signed
3438 def SETGm    : I<0x9F, MRM0m, 
3439                  (outs), (ins i8mem:$dst),
3440                  "setg\t$dst",
3441                  [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
3442                TB;                        // [mem8] = >  signed
3443
3444 def SETBr    : I<0x92, MRM0r,
3445                  (outs GR8   :$dst), (ins),
3446                  "setb\t$dst",
3447                  [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
3448                TB;                        // GR8 = <  unsign
3449 def SETBm    : I<0x92, MRM0m,
3450                  (outs), (ins i8mem:$dst),
3451                  "setb\t$dst",
3452                  [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
3453                TB;                        // [mem8] = <  unsign
3454
3455 def SETAEr   : I<0x93, MRM0r, 
3456                  (outs GR8   :$dst), (ins),
3457                  "setae\t$dst",
3458                  [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
3459                TB;                        // GR8 = >= unsign
3460 def SETAEm   : I<0x93, MRM0m, 
3461                  (outs), (ins i8mem:$dst),
3462                  "setae\t$dst",
3463                  [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
3464                TB;                        // [mem8] = >= unsign
3465
3466 def SETBEr   : I<0x96, MRM0r, 
3467                  (outs GR8   :$dst), (ins),
3468                  "setbe\t$dst",
3469                  [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
3470                TB;                        // GR8 = <= unsign
3471 def SETBEm   : I<0x96, MRM0m, 
3472                  (outs), (ins i8mem:$dst),
3473                  "setbe\t$dst",
3474                  [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
3475                TB;                        // [mem8] = <= unsign
3476
3477 def SETAr    : I<0x97, MRM0r, 
3478                  (outs GR8   :$dst), (ins),
3479                  "seta\t$dst",
3480                  [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
3481                TB;                        // GR8 = >  signed
3482 def SETAm    : I<0x97, MRM0m, 
3483                  (outs), (ins i8mem:$dst),
3484                  "seta\t$dst",
3485                  [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
3486                TB;                        // [mem8] = >  signed
3487
3488 def SETSr    : I<0x98, MRM0r, 
3489                  (outs GR8   :$dst), (ins),
3490                  "sets\t$dst",
3491                  [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
3492                TB;                        // GR8 = <sign bit>
3493 def SETSm    : I<0x98, MRM0m, 
3494                  (outs), (ins i8mem:$dst),
3495                  "sets\t$dst",
3496                  [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
3497                TB;                        // [mem8] = <sign bit>
3498 def SETNSr   : I<0x99, MRM0r, 
3499                  (outs GR8   :$dst), (ins),
3500                  "setns\t$dst",
3501                  [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
3502                TB;                        // GR8 = !<sign bit>
3503 def SETNSm   : I<0x99, MRM0m, 
3504                  (outs), (ins i8mem:$dst),
3505                  "setns\t$dst",
3506                  [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
3507                TB;                        // [mem8] = !<sign bit>
3508
3509 def SETPr    : I<0x9A, MRM0r, 
3510                  (outs GR8   :$dst), (ins),
3511                  "setp\t$dst",
3512                  [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
3513                TB;                        // GR8 = parity
3514 def SETPm    : I<0x9A, MRM0m, 
3515                  (outs), (ins i8mem:$dst),
3516                  "setp\t$dst",
3517                  [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
3518                TB;                        // [mem8] = parity
3519 def SETNPr   : I<0x9B, MRM0r, 
3520                  (outs GR8   :$dst), (ins),
3521                  "setnp\t$dst",
3522                  [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
3523                TB;                        // GR8 = not parity
3524 def SETNPm   : I<0x9B, MRM0m, 
3525                  (outs), (ins i8mem:$dst),
3526                  "setnp\t$dst",
3527                  [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
3528                TB;                        // [mem8] = not parity
3529
3530 def SETOr    : I<0x90, MRM0r, 
3531                  (outs GR8   :$dst), (ins),
3532                  "seto\t$dst",
3533                  [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
3534                TB;                        // GR8 = overflow
3535 def SETOm    : I<0x90, MRM0m, 
3536                  (outs), (ins i8mem:$dst),
3537                  "seto\t$dst",
3538                  [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
3539                TB;                        // [mem8] = overflow
3540 def SETNOr   : I<0x91, MRM0r, 
3541                  (outs GR8   :$dst), (ins),
3542                  "setno\t$dst",
3543                  [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
3544                TB;                        // GR8 = not overflow
3545 def SETNOm   : I<0x91, MRM0m, 
3546                  (outs), (ins i8mem:$dst),
3547                  "setno\t$dst",
3548                  [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
3549                TB;                        // [mem8] = not overflow
3550 } // Uses = [EFLAGS]
3551
3552
3553 // Integer comparisons
3554 let Defs = [EFLAGS] in {
3555 def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
3556                  "cmp{b}\t{$src, %al|%al, $src}", []>;
3557 def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
3558                     "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3559 def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
3560                     "cmp{l}\t{$src, %eax|%eax, $src}", []>;
3561
3562 def CMP8rr  : I<0x38, MRMDestReg,
3563                 (outs), (ins GR8 :$src1, GR8 :$src2),
3564                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3565                 [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
3566 def CMP16rr : I<0x39, MRMDestReg,
3567                 (outs), (ins GR16:$src1, GR16:$src2),
3568                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3569                 [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
3570 def CMP32rr : I<0x39, MRMDestReg,
3571                 (outs), (ins GR32:$src1, GR32:$src2),
3572                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3573                 [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
3574 def CMP8mr  : I<0x38, MRMDestMem,
3575                 (outs), (ins i8mem :$src1, GR8 :$src2),
3576                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3577                 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
3578 def CMP16mr : I<0x39, MRMDestMem,
3579                 (outs), (ins i16mem:$src1, GR16:$src2),
3580                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3581                 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
3582                  OpSize;
3583 def CMP32mr : I<0x39, MRMDestMem,
3584                 (outs), (ins i32mem:$src1, GR32:$src2),
3585                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3586                 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
3587 def CMP8rm  : I<0x3A, MRMSrcMem,
3588                 (outs), (ins GR8 :$src1, i8mem :$src2),
3589                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3590                 [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
3591 def CMP16rm : I<0x3B, MRMSrcMem,
3592                 (outs), (ins GR16:$src1, i16mem:$src2),
3593                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3594                 [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
3595                  OpSize;
3596 def CMP32rm : I<0x3B, MRMSrcMem,
3597                 (outs), (ins GR32:$src1, i32mem:$src2),
3598                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3599                 [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
3600
3601 // These are alternate spellings for use by the disassembler, we mark them as
3602 // code gen only to ensure they aren't matched by the assembler.
3603 let isCodeGenOnly = 1 in {
3604   def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
3605                     "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
3606   def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
3607                      "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
3608   def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
3609                      "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
3610 }
3611
3612 def CMP8ri  : Ii8<0x80, MRM7r,
3613                   (outs), (ins GR8:$src1, i8imm:$src2),
3614                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
3615                   [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
3616 def CMP16ri : Ii16<0x81, MRM7r,
3617                    (outs), (ins GR16:$src1, i16imm:$src2),
3618                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3619                    [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
3620 def CMP32ri : Ii32<0x81, MRM7r,
3621                    (outs), (ins GR32:$src1, i32imm:$src2),
3622                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3623                    [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
3624 def CMP8mi  : Ii8 <0x80, MRM7m,
3625                    (outs), (ins i8mem :$src1, i8imm :$src2),
3626                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
3627                    [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
3628 def CMP16mi : Ii16<0x81, MRM7m,
3629                    (outs), (ins i16mem:$src1, i16imm:$src2),
3630                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3631                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
3632                    OpSize;
3633 def CMP32mi : Ii32<0x81, MRM7m,
3634                    (outs), (ins i32mem:$src1, i32imm:$src2),
3635                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3636                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
3637 def CMP16ri8 : Ii8<0x83, MRM7r,
3638                    (outs), (ins GR16:$src1, i16i8imm:$src2),
3639                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3640                    [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
3641                     OpSize;
3642 def CMP16mi8 : Ii8<0x83, MRM7m,
3643                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
3644                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3645                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
3646                                          i16immSExt8:$src2))]>, OpSize;
3647 def CMP32mi8 : Ii8<0x83, MRM7m,
3648                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
3649                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3650                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
3651                                          i32immSExt8:$src2))]>;
3652 def CMP32ri8 : Ii8<0x83, MRM7r,
3653                    (outs), (ins GR32:$src1, i32i8imm:$src2),
3654                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3655                    [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
3656 } // Defs = [EFLAGS]
3657
3658 // Bit tests.
3659 // TODO: BTC, BTR, and BTS
3660 let Defs = [EFLAGS] in {
3661 def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3662                "bt{w}\t{$src2, $src1|$src1, $src2}",
3663                [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
3664 def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3665                "bt{l}\t{$src2, $src1|$src1, $src2}",
3666                [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
3667
3668 // Unlike with the register+register form, the memory+register form of the
3669 // bt instruction does not ignore the high bits of the index. From ISel's
3670 // perspective, this is pretty bizarre. Make these instructions disassembly
3671 // only for now.
3672
3673 def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3674                "bt{w}\t{$src2, $src1|$src1, $src2}", 
3675 //               [(X86bt (loadi16 addr:$src1), GR16:$src2),
3676 //                (implicit EFLAGS)]
3677                []
3678                >, OpSize, TB, Requires<[FastBTMem]>;
3679 def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3680                "bt{l}\t{$src2, $src1|$src1, $src2}", 
3681 //               [(X86bt (loadi32 addr:$src1), GR32:$src2),
3682 //                (implicit EFLAGS)]
3683                []
3684                >, TB, Requires<[FastBTMem]>;
3685
3686 def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3687                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3688                 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
3689                 OpSize, TB;
3690 def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3691                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3692                 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
3693 // Note that these instructions don't need FastBTMem because that
3694 // only applies when the other operand is in a register. When it's
3695 // an immediate, bt is still fast.
3696 def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3697                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3698                 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
3699                  ]>, OpSize, TB;
3700 def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3701                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3702                 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
3703                  ]>, TB;
3704
3705 def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3706                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3707 def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3708                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3709 def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3710                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3711 def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3712                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3713 def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3714                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3715 def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3716                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3717 def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3718                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3719 def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3720                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3721
3722 def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3723                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3724 def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3725                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3726 def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3727                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3728 def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3729                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3730 def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3731                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3732 def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3733                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3734 def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3735                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3736 def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3737                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3738
3739 def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3740                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3741 def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3742                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3743 def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3744                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3745 def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3746                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3747 def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3748                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3749 def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3750                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3751 def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3752                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3753 def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3754                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3755 } // Defs = [EFLAGS]
3756
3757 // Sign/Zero extenders
3758 // Use movsbl intead of movsbw; we don't care about the high 16 bits
3759 // of the register here. This has a smaller encoding and avoids a
3760 // partial-register update.  Actual movsbw included for the disassembler.
3761 def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3762                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3763 def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3764                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3765 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3766                    "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
3767 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3768                    "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
3769 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3770                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3771                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
3772 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3773                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3774                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
3775 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3776                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3777                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
3778 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3779                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3780                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
3781
3782 // Use movzbl intead of movzbw; we don't care about the high 16 bits
3783 // of the register here. This has a smaller encoding and avoids a
3784 // partial-register update.  Actual movzbw included for the disassembler.
3785 def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3786                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3787 def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3788                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;  
3789 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3790                    "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
3791 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3792                    "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
3793 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3794                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3795                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
3796 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3797                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3798                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
3799 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3800                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3801                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
3802 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3803                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3804                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
3805
3806 // These are the same as the regular MOVZX32rr8 and MOVZX32rm8
3807 // except that they use GR32_NOREX for the output operand register class
3808 // instead of GR32. This allows them to operate on h registers on x86-64.
3809 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
3810                          (outs GR32_NOREX:$dst), (ins GR8:$src),
3811                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3812                          []>, TB;
3813 let mayLoad = 1 in
3814 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
3815                          (outs GR32_NOREX:$dst), (ins i8mem:$src),
3816                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3817                          []>, TB;
3818
3819 let neverHasSideEffects = 1 in {
3820   let Defs = [AX], Uses = [AL] in
3821   def CBW : I<0x98, RawFrm, (outs), (ins),
3822               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
3823   let Defs = [EAX], Uses = [AX] in
3824   def CWDE : I<0x98, RawFrm, (outs), (ins),
3825               "{cwtl|cwde}", []>;   // EAX = signext(AX)
3826
3827   let Defs = [AX,DX], Uses = [AX] in
3828   def CWD : I<0x99, RawFrm, (outs), (ins),
3829               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
3830   let Defs = [EAX,EDX], Uses = [EAX] in
3831   def CDQ : I<0x99, RawFrm, (outs), (ins),
3832               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
3833 }
3834
3835 //===----------------------------------------------------------------------===//
3836 // Alias Instructions
3837 //===----------------------------------------------------------------------===//
3838
3839 // Alias instructions that map movr0 to xor.
3840 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
3841 // FIXME: Set encoding to pseudo.
3842 let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
3843     isCodeGenOnly = 1 in {
3844 def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "",
3845                  [(set GR8:$dst, 0)]>;
3846
3847 // We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller
3848 // encoding and avoids a partial-register update sometimes, but doing so
3849 // at isel time interferes with rematerialization in the current register
3850 // allocator. For now, this is rewritten when the instruction is lowered
3851 // to an MCInst.
3852 def MOV16r0   : I<0x31, MRMInitReg, (outs GR16:$dst), (ins),
3853                  "",
3854                  [(set GR16:$dst, 0)]>, OpSize;
3855                  
3856 // FIXME: Set encoding to pseudo.
3857 def MOV32r0  : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "",
3858                  [(set GR32:$dst, 0)]>;
3859 }
3860
3861 //===----------------------------------------------------------------------===//
3862 // Thread Local Storage Instructions
3863 //
3864
3865 // ELF TLS Support
3866 // All calls clobber the non-callee saved registers. ESP is marked as
3867 // a use to prevent stack-pointer assignments that appear immediately
3868 // before calls from potentially appearing dead.
3869 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3870             MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3871             XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3872             XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
3873     Uses = [ESP] in
3874 def TLS_addr32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3875                   "leal\t$sym, %eax; "
3876                   "call\t___tls_get_addr@PLT",
3877                   [(X86tlsaddr tls32addr:$sym)]>,
3878                   Requires<[In32BitMode]>;
3879
3880 // Darwin TLS Support
3881 // For i386, the address of the thunk is passed on the stack, on return the 
3882 // address of the variable is in %eax.  %ecx is trashed during the function 
3883 // call.  All other registers are preserved.
3884 let Defs = [EAX, ECX],
3885     Uses = [ESP],
3886     usesCustomInserter = 1 in
3887 def TLSCall_32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3888                 "# TLSCall_32",
3889                 [(X86TLSCall addr:$sym)]>,
3890                 Requires<[In32BitMode]>;
3891                 
3892 let AddedComplexity = 5, isCodeGenOnly = 1 in
3893 def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3894                    "movl\t%gs:$src, $dst",
3895                    [(set GR32:$dst, (gsload addr:$src))]>, SegGS;
3896
3897 let AddedComplexity = 5, isCodeGenOnly = 1 in
3898 def FS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3899                    "movl\t%fs:$src, $dst",
3900                    [(set GR32:$dst, (fsload addr:$src))]>, SegFS;
3901
3902 //===----------------------------------------------------------------------===//
3903 // EH Pseudo Instructions
3904 //
3905 let isTerminator = 1, isReturn = 1, isBarrier = 1,
3906     hasCtrlDep = 1, isCodeGenOnly = 1 in {
3907 def EH_RETURN   : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
3908                     "ret\t#eh_return, addr: $addr",
3909                     [(X86ehret GR32:$addr)]>;
3910
3911 }
3912
3913 //===----------------------------------------------------------------------===//
3914 // Atomic support
3915 //
3916
3917 // Memory barriers
3918 let hasSideEffects = 1 in {
3919 def Int_MemBarrier : I<0, Pseudo, (outs), (ins),
3920                      "#MEMBARRIER",
3921                      [(X86MemBarrier)]>, Requires<[HasSSE2]>;
3922                
3923 let Uses = [ESP], isCodeGenOnly = 1 in
3924 def Int_MemBarrierNoSSE  : I<0x0B, Pseudo, (outs), (ins GR32:$zero),
3925                            "lock\n\t"
3926                            "or{l}\t{$zero, (%esp)|(%esp), $zero}",
3927                            [(X86MemBarrierNoSSE GR32:$zero)]>, LOCK;
3928 }
3929
3930 // Atomic swap. These are just normal xchg instructions. But since a memory
3931 // operand is referenced, the atomicity is ensured.
3932 let Constraints = "$val = $dst" in {
3933 def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), 
3934                  (ins GR32:$val, i32mem:$ptr),
3935                "xchg{l}\t{$val, $ptr|$ptr, $val}", 
3936                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
3937 def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), 
3938                  (ins GR16:$val, i16mem:$ptr),
3939                "xchg{w}\t{$val, $ptr|$ptr, $val}", 
3940                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
3941                 OpSize;
3942 def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3943                "xchg{b}\t{$val, $ptr|$ptr, $val}", 
3944                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
3945
3946 def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
3947                  "xchg{l}\t{$val, $src|$src, $val}", []>;
3948 def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
3949                  "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
3950 def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
3951                 "xchg{b}\t{$val, $src|$src, $val}", []>;
3952 }
3953
3954 def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
3955                   "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3956 def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
3957                   "xchg{l}\t{$src, %eax|%eax, $src}", []>;
3958
3959 // Atomic compare and swap.
3960 let Defs = [EAX, EFLAGS], Uses = [EAX] in {
3961 def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
3962                "lock\n\t"
3963                "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
3964                [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
3965 }
3966 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
3967 def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr),
3968                "lock\n\t"
3969                "cmpxchg8b\t$ptr",
3970                [(X86cas8 addr:$ptr)]>, TB, LOCK;
3971 }
3972
3973 let Defs = [AX, EFLAGS], Uses = [AX] in {
3974 def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
3975                "lock\n\t"
3976                "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
3977                [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
3978 }
3979 let Defs = [AL, EFLAGS], Uses = [AL] in {
3980 def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
3981                "lock\n\t"
3982                "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
3983                [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
3984 }
3985
3986 // Atomic exchange and add
3987 let Constraints = "$val = $dst", Defs = [EFLAGS] in {
3988 def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr),
3989                "lock\n\t"
3990                "xadd{l}\t{$val, $ptr|$ptr, $val}",
3991                [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
3992                 TB, LOCK;
3993 def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr),
3994                "lock\n\t"
3995                "xadd{w}\t{$val, $ptr|$ptr, $val}",
3996                [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
3997                 TB, OpSize, LOCK;
3998 def LXADD8  : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3999                "lock\n\t"
4000                "xadd{b}\t{$val, $ptr|$ptr, $val}",
4001                [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
4002                 TB, LOCK;
4003 }
4004
4005 def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
4006                 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
4007 def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
4008                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4009 def XADD32rr  : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4010                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
4011
4012 let mayLoad = 1, mayStore = 1 in {
4013 def XADD8rm   : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
4014                  "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
4015 def XADD16rm  : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
4016                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4017 def XADD32rm  : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
4018                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
4019 }
4020
4021 def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
4022                    "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
4023 def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
4024                     "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4025 def CMPXCHG32rr  : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4026                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
4027
4028 let mayLoad = 1, mayStore = 1 in {
4029 def CMPXCHG8rm   : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
4030                      "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
4031 def CMPXCHG16rm  : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
4032                      "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4033 def CMPXCHG32rm  : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
4034                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
4035 }
4036
4037 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
4038 def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
4039                   "cmpxchg8b\t$dst", []>, TB;
4040
4041 // Optimized codegen when the non-memory output is not used.
4042 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
4043 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
4044 def LOCK_ADD8mr  : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
4045                     "lock\n\t"
4046                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4047 def LOCK_ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
4048                     "lock\n\t"
4049                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4050 def LOCK_ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
4051                     "lock\n\t"
4052                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4053 def LOCK_ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
4054                     "lock\n\t"
4055                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4056 def LOCK_ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
4057                     "lock\n\t"
4058                      "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4059 def LOCK_ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
4060                     "lock\n\t"
4061                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4062 def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
4063                     "lock\n\t"
4064                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4065 def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4066                     "lock\n\t"
4067                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4068
4069 def LOCK_INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
4070                     "lock\n\t"
4071                     "inc{b}\t$dst", []>, LOCK;
4072 def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
4073                     "lock\n\t"
4074                     "inc{w}\t$dst", []>, OpSize, LOCK;
4075 def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
4076                     "lock\n\t"
4077                     "inc{l}\t$dst", []>, LOCK;
4078
4079 def LOCK_SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
4080                     "lock\n\t"
4081                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4082 def LOCK_SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
4083                     "lock\n\t"
4084                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4085 def LOCK_SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
4086                     "lock\n\t"
4087                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4088 def LOCK_SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
4089                     "lock\n\t"
4090                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4091 def LOCK_SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
4092                     "lock\n\t"
4093                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4094 def LOCK_SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
4095                     "lock\n\t"
4096                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4097 def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
4098                     "lock\n\t"
4099                      "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4100 def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4101                     "lock\n\t"
4102                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4103
4104 def LOCK_DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
4105                     "lock\n\t"
4106                     "dec{b}\t$dst", []>, LOCK;
4107 def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
4108                     "lock\n\t"
4109                     "dec{w}\t$dst", []>, OpSize, LOCK;
4110 def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
4111                     "lock\n\t"
4112                     "dec{l}\t$dst", []>, LOCK;
4113 }
4114
4115 // Atomic exchange, and, or, xor
4116 let Constraints = "$val = $dst", Defs = [EFLAGS],
4117                   usesCustomInserter = 1 in {
4118 def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4119                "#ATOMAND32 PSEUDO!", 
4120                [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
4121 def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4122                "#ATOMOR32 PSEUDO!", 
4123                [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
4124 def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4125                "#ATOMXOR32 PSEUDO!", 
4126                [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
4127 def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4128                "#ATOMNAND32 PSEUDO!", 
4129                [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
4130 def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
4131                "#ATOMMIN32 PSEUDO!", 
4132                [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
4133 def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4134                "#ATOMMAX32 PSEUDO!", 
4135                [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
4136 def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4137                "#ATOMUMIN32 PSEUDO!", 
4138                [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
4139 def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4140                "#ATOMUMAX32 PSEUDO!", 
4141                [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
4142
4143 def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4144                "#ATOMAND16 PSEUDO!", 
4145                [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
4146 def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4147                "#ATOMOR16 PSEUDO!", 
4148                [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
4149 def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4150                "#ATOMXOR16 PSEUDO!", 
4151                [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
4152 def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4153                "#ATOMNAND16 PSEUDO!", 
4154                [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
4155 def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
4156                "#ATOMMIN16 PSEUDO!", 
4157                [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
4158 def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4159                "#ATOMMAX16 PSEUDO!", 
4160                [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
4161 def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4162                "#ATOMUMIN16 PSEUDO!", 
4163                [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
4164 def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4165                "#ATOMUMAX16 PSEUDO!", 
4166                [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
4167
4168 def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4169                "#ATOMAND8 PSEUDO!", 
4170                [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
4171 def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4172                "#ATOMOR8 PSEUDO!", 
4173                [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
4174 def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4175                "#ATOMXOR8 PSEUDO!", 
4176                [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
4177 def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4178                "#ATOMNAND8 PSEUDO!", 
4179                [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
4180 }
4181
4182 let Constraints = "$val1 = $dst1, $val2 = $dst2", 
4183                   Defs = [EFLAGS, EAX, EBX, ECX, EDX],
4184                   Uses = [EAX, EBX, ECX, EDX],
4185                   mayLoad = 1, mayStore = 1,
4186                   usesCustomInserter = 1 in {
4187 def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4188                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4189                "#ATOMAND6432 PSEUDO!", []>;
4190 def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4191                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4192                "#ATOMOR6432 PSEUDO!", []>;
4193 def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4194                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4195                "#ATOMXOR6432 PSEUDO!", []>;
4196 def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4197                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4198                "#ATOMNAND6432 PSEUDO!", []>;
4199 def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4200                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4201                "#ATOMADD6432 PSEUDO!", []>;
4202 def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4203                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4204                "#ATOMSUB6432 PSEUDO!", []>;
4205 def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4206                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4207                "#ATOMSWAP6432 PSEUDO!", []>;
4208 }
4209
4210 // Segmentation support instructions.
4211
4212 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 
4213                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4214 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4215                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4216
4217 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
4218 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src), 
4219                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
4220 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4221                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
4222
4223 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
4224                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize; 
4225 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4226                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4227 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4228                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB; 
4229 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4230                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB;
4231                 
4232 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
4233
4234 def STRr : I<0x00, MRM1r, (outs GR16:$dst), (ins),
4235              "str{w}\t{$dst}", []>, TB;
4236 def STRm : I<0x00, MRM1m, (outs i16mem:$dst), (ins),
4237              "str{w}\t{$dst}", []>, TB;
4238 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src),
4239              "ltr{w}\t{$src}", []>, TB;
4240 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src),
4241              "ltr{w}\t{$src}", []>, TB;
4242              
4243 def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins),
4244                  "push{w}\t%fs", []>, OpSize, TB;
4245 def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins),
4246                  "push{l}\t%fs", []>, TB;
4247 def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins),
4248                  "push{w}\t%gs", []>, OpSize, TB;
4249 def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins),
4250                  "push{l}\t%gs", []>, TB;
4251
4252 def POPFS16 : I<0xa1, RawFrm, (outs), (ins),
4253                 "pop{w}\t%fs", []>, OpSize, TB;
4254 def POPFS32 : I<0xa1, RawFrm, (outs), (ins),
4255                 "pop{l}\t%fs", []>, TB;
4256 def POPGS16 : I<0xa9, RawFrm, (outs), (ins),
4257                 "pop{w}\t%gs", []>, OpSize, TB;
4258 def POPGS32 : I<0xa9, RawFrm, (outs), (ins),
4259                 "pop{l}\t%gs", []>, TB;
4260
4261 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4262                 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4263 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4264                 "lds{l}\t{$src, $dst|$dst, $src}", []>;
4265 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4266                 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4267 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4268                 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB;
4269 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4270                 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4271 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4272                 "les{l}\t{$src, $dst|$dst, $src}", []>;
4273 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4274                 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4275 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4276                 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4277 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4278                 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4279 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4280                 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4281
4282 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg),
4283               "verr\t$seg", []>, TB;
4284 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg),
4285               "verr\t$seg", []>, TB;
4286 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg),
4287               "verw\t$seg", []>, TB;
4288 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg),
4289               "verw\t$seg", []>, TB;
4290
4291 // Descriptor-table support instructions
4292
4293 def SGDTm : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
4294               "sgdt\t$dst", []>, TB;
4295 def SIDTm : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
4296               "sidt\t$dst", []>, TB;
4297 def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
4298                 "sldt{w}\t$dst", []>, TB;
4299 def SLDT16m : I<0x00, MRM0m, (outs i16mem:$dst), (ins),
4300                 "sldt{w}\t$dst", []>, TB;
4301 def LGDTm : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
4302               "lgdt\t$src", []>, TB;
4303 def LIDTm : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
4304               "lidt\t$src", []>, TB;
4305 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
4306                 "lldt{w}\t$src", []>, TB;
4307 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
4308                 "lldt{w}\t$src", []>, TB;
4309                 
4310 // Lock instruction prefix
4311 def LOCK_PREFIX : I<0xF0, RawFrm, (outs),  (ins), "lock", []>;
4312
4313 // Repeat string operation instruction prefixes
4314 // These uses the DF flag in the EFLAGS register to inc or dec ECX
4315 let Defs = [ECX], Uses = [ECX,EFLAGS] in {
4316 // Repeat (used with INS, OUTS, MOVS, LODS and STOS)
4317 def REP_PREFIX : I<0xF3, RawFrm, (outs),  (ins), "rep", []>;
4318 // Repeat while not equal (used with CMPS and SCAS)
4319 def REPNE_PREFIX : I<0xF2, RawFrm, (outs),  (ins), "repne", []>;
4320 }
4321
4322 // Segment override instruction prefixes
4323 def CS_PREFIX : I<0x2E, RawFrm, (outs),  (ins), "cs", []>;
4324 def SS_PREFIX : I<0x36, RawFrm, (outs),  (ins), "ss", []>;
4325 def DS_PREFIX : I<0x3E, RawFrm, (outs),  (ins), "ds", []>;
4326 def ES_PREFIX : I<0x26, RawFrm, (outs),  (ins), "es", []>;
4327 def FS_PREFIX : I<0x64, RawFrm, (outs),  (ins), "fs", []>;
4328 def GS_PREFIX : I<0x65, RawFrm, (outs),  (ins), "gs", []>;
4329
4330 // String manipulation instructions
4331
4332 def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
4333 def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
4334 def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
4335
4336 def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
4337 def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
4338 def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
4339
4340 // CPU flow control instructions
4341
4342 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
4343 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
4344
4345 // FPU control instructions
4346
4347 def FNINIT : I<0xE3, RawFrm, (outs), (ins), "fninit", []>, DB;
4348
4349 // Flag instructions
4350
4351 def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
4352 def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
4353 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
4354 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
4355 def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
4356 def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
4357 def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
4358
4359 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
4360
4361 // Table lookup instructions
4362
4363 def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
4364
4365 // Specialized register support
4366
4367 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
4368 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
4369 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
4370
4371 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins), 
4372                 "smsw{w}\t$dst", []>, OpSize, TB;
4373 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins), 
4374                 "smsw{l}\t$dst", []>, TB;
4375 // For memory operands, there is only a 16-bit form
4376 def SMSW16m : I<0x01, MRM4m, (outs i16mem:$dst), (ins),
4377                 "smsw{w}\t$dst", []>, TB;
4378
4379 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
4380                 "lmsw{w}\t$src", []>, TB;
4381 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
4382                 "lmsw{w}\t$src", []>, TB;
4383                 
4384 def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
4385
4386 // Cache instructions
4387
4388 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
4389 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", []>, TB;
4390
4391 // VMX instructions
4392
4393 // 66 0F 38 80
4394 def INVEPT : I<0x80, RawFrm, (outs), (ins), "invept", []>, OpSize, T8;
4395 // 66 0F 38 81
4396 def INVVPID : I<0x81, RawFrm, (outs), (ins), "invvpid", []>, OpSize, T8;
4397 // 0F 01 C1
4398 def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
4399 def VMCLEARm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4400   "vmclear\t$vmcs", []>, OpSize, TB;
4401 // 0F 01 C2
4402 def VMLAUNCH : I<0x01, MRM_C2, (outs), (ins), "vmlaunch", []>, TB;
4403 // 0F 01 C3
4404 def VMRESUME : I<0x01, MRM_C3, (outs), (ins), "vmresume", []>, TB;
4405 def VMPTRLDm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4406   "vmptrld\t$vmcs", []>, TB;
4407 def VMPTRSTm : I<0xC7, MRM7m, (outs i64mem:$vmcs), (ins),
4408   "vmptrst\t$vmcs", []>, TB;
4409 def VMREAD64rm : I<0x78, MRMDestMem, (outs i64mem:$dst), (ins GR64:$src),
4410   "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4411 def VMREAD64rr : I<0x78, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
4412   "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4413 def VMREAD32rm : I<0x78, MRMDestMem, (outs i32mem:$dst), (ins GR32:$src),
4414   "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4415 def VMREAD32rr : I<0x78, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4416   "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4417 def VMWRITE64rm : I<0x79, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
4418   "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4419 def VMWRITE64rr : I<0x79, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
4420   "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4421 def VMWRITE32rm : I<0x79, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4422   "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4423 def VMWRITE32rr : I<0x79, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4424   "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4425 // 0F 01 C4
4426 def VMXOFF : I<0x01, MRM_C4, (outs), (ins), "vmxoff", []>, TB;
4427 def VMXON : I<0xC7, MRM6m, (outs), (ins i64mem:$vmxon),
4428   "vmxon\t{$vmxon}", []>, XS;
4429
4430 //===----------------------------------------------------------------------===//
4431 // Non-Instruction Patterns
4432 //===----------------------------------------------------------------------===//
4433
4434 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
4435 def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
4436 def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
4437 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
4438 def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
4439 def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
4440 def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>;
4441
4442 def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
4443           (ADD32ri GR32:$src1, tconstpool:$src2)>;
4444 def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
4445           (ADD32ri GR32:$src1, tjumptable:$src2)>;
4446 def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
4447           (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
4448 def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
4449           (ADD32ri GR32:$src1, texternalsym:$src2)>;
4450 def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)),
4451           (ADD32ri GR32:$src1, tblockaddress:$src2)>;
4452
4453 def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
4454           (MOV32mi addr:$dst, tglobaladdr:$src)>;
4455 def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
4456           (MOV32mi addr:$dst, texternalsym:$src)>;
4457 def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst),
4458           (MOV32mi addr:$dst, tblockaddress:$src)>;
4459
4460 // Calls
4461 // tailcall stuff
4462 def : Pat<(X86tcret GR32_TC:$dst, imm:$off),
4463           (TCRETURNri GR32_TC:$dst, imm:$off)>,
4464           Requires<[In32BitMode]>;
4465
4466 // FIXME: This is disabled for 32-bit PIC mode because the global base
4467 // register which is part of the address mode may be assigned a 
4468 // callee-saved register.
4469 def : Pat<(X86tcret (load addr:$dst), imm:$off),
4470           (TCRETURNmi addr:$dst, imm:$off)>,
4471           Requires<[In32BitMode, IsNotPIC]>;
4472
4473 def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
4474           (TCRETURNdi texternalsym:$dst, imm:$off)>,
4475           Requires<[In32BitMode]>;
4476
4477 def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
4478           (TCRETURNdi texternalsym:$dst, imm:$off)>,
4479           Requires<[In32BitMode]>;
4480
4481 // Normal calls, with various flavors of addresses.
4482 def : Pat<(X86call (i32 tglobaladdr:$dst)),
4483           (CALLpcrel32 tglobaladdr:$dst)>;
4484 def : Pat<(X86call (i32 texternalsym:$dst)),
4485           (CALLpcrel32 texternalsym:$dst)>;
4486 def : Pat<(X86call (i32 imm:$dst)),
4487           (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
4488
4489 // X86 specific add which produces a flag.
4490 def : Pat<(addc GR32:$src1, GR32:$src2),
4491           (ADD32rr GR32:$src1, GR32:$src2)>;
4492 def : Pat<(addc GR32:$src1, (load addr:$src2)),
4493           (ADD32rm GR32:$src1, addr:$src2)>;
4494 def : Pat<(addc GR32:$src1, imm:$src2),
4495           (ADD32ri GR32:$src1, imm:$src2)>;
4496 def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
4497           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4498
4499 def : Pat<(subc GR32:$src1, GR32:$src2),
4500           (SUB32rr GR32:$src1, GR32:$src2)>;
4501 def : Pat<(subc GR32:$src1, (load addr:$src2)),
4502           (SUB32rm GR32:$src1, addr:$src2)>;
4503 def : Pat<(subc GR32:$src1, imm:$src2),
4504           (SUB32ri GR32:$src1, imm:$src2)>;
4505 def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
4506           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4507
4508 // Comparisons.
4509
4510 // TEST R,R is smaller than CMP R,0
4511 def : Pat<(X86cmp GR8:$src1, 0),
4512           (TEST8rr GR8:$src1, GR8:$src1)>;
4513 def : Pat<(X86cmp GR16:$src1, 0),
4514           (TEST16rr GR16:$src1, GR16:$src1)>;
4515 def : Pat<(X86cmp GR32:$src1, 0),
4516           (TEST32rr GR32:$src1, GR32:$src1)>;
4517
4518 // Conditional moves with folded loads with operands swapped and conditions
4519 // inverted.
4520 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS),
4521           (CMOVAE16rm GR16:$src2, addr:$src1)>;
4522 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS),
4523           (CMOVAE32rm GR32:$src2, addr:$src1)>;
4524 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS),
4525           (CMOVB16rm GR16:$src2, addr:$src1)>;
4526 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS),
4527           (CMOVB32rm GR32:$src2, addr:$src1)>;
4528 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS),
4529           (CMOVNE16rm GR16:$src2, addr:$src1)>;
4530 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS),
4531           (CMOVNE32rm GR32:$src2, addr:$src1)>;
4532 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS),
4533           (CMOVE16rm GR16:$src2, addr:$src1)>;
4534 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS),
4535           (CMOVE32rm GR32:$src2, addr:$src1)>;
4536 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS),
4537           (CMOVA16rm GR16:$src2, addr:$src1)>;
4538 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS),
4539           (CMOVA32rm GR32:$src2, addr:$src1)>;
4540 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS),
4541           (CMOVBE16rm GR16:$src2, addr:$src1)>;
4542 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS),
4543           (CMOVBE32rm GR32:$src2, addr:$src1)>;
4544 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS),
4545           (CMOVGE16rm GR16:$src2, addr:$src1)>;
4546 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS),
4547           (CMOVGE32rm GR32:$src2, addr:$src1)>;
4548 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS),
4549           (CMOVL16rm GR16:$src2, addr:$src1)>;
4550 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS),
4551           (CMOVL32rm GR32:$src2, addr:$src1)>;
4552 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS),
4553           (CMOVG16rm GR16:$src2, addr:$src1)>;
4554 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS),
4555           (CMOVG32rm GR32:$src2, addr:$src1)>;
4556 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS),
4557           (CMOVLE16rm GR16:$src2, addr:$src1)>;
4558 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS),
4559           (CMOVLE32rm GR32:$src2, addr:$src1)>;
4560 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS),
4561           (CMOVNP16rm GR16:$src2, addr:$src1)>;
4562 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS),
4563           (CMOVNP32rm GR32:$src2, addr:$src1)>;
4564 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS),
4565           (CMOVP16rm GR16:$src2, addr:$src1)>;
4566 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS),
4567           (CMOVP32rm GR32:$src2, addr:$src1)>;
4568 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS),
4569           (CMOVNS16rm GR16:$src2, addr:$src1)>;
4570 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS),
4571           (CMOVNS32rm GR32:$src2, addr:$src1)>;
4572 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS),
4573           (CMOVS16rm GR16:$src2, addr:$src1)>;
4574 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS),
4575           (CMOVS32rm GR32:$src2, addr:$src1)>;
4576 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS),
4577           (CMOVNO16rm GR16:$src2, addr:$src1)>;
4578 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS),
4579           (CMOVNO32rm GR32:$src2, addr:$src1)>;
4580 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS),
4581           (CMOVO16rm GR16:$src2, addr:$src1)>;
4582 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS),
4583           (CMOVO32rm GR32:$src2, addr:$src1)>;
4584
4585 // zextload bool -> zextload byte
4586 def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
4587 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
4588 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
4589
4590 // extload bool -> extload byte
4591 def : Pat<(extloadi8i1 addr:$src),   (MOV8rm      addr:$src)>;
4592 def : Pat<(extloadi16i1 addr:$src),  (MOVZX16rm8  addr:$src)>;
4593 def : Pat<(extloadi32i1 addr:$src),  (MOVZX32rm8  addr:$src)>;
4594 def : Pat<(extloadi16i8 addr:$src),  (MOVZX16rm8  addr:$src)>;
4595 def : Pat<(extloadi32i8 addr:$src),  (MOVZX32rm8  addr:$src)>;
4596 def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
4597
4598 // anyext. Define these to do an explicit zero-extend to
4599 // avoid partial-register updates.
4600 def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8  GR8 :$src)>;
4601 def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8  GR8 :$src)>;
4602
4603 // Except for i16 -> i32 since isel expect i16 ops to be promoted to i32.
4604 def : Pat<(i32 (anyext GR16:$src)),
4605           (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR16:$src, sub_16bit)>;
4606
4607
4608 //===----------------------------------------------------------------------===//
4609 // Some peepholes
4610 //===----------------------------------------------------------------------===//
4611
4612 // Odd encoding trick: -128 fits into an 8-bit immediate field while
4613 // +128 doesn't, so in this special case use a sub instead of an add.
4614 def : Pat<(add GR16:$src1, 128),
4615           (SUB16ri8 GR16:$src1, -128)>;
4616 def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst),
4617           (SUB16mi8 addr:$dst, -128)>;
4618 def : Pat<(add GR32:$src1, 128),
4619           (SUB32ri8 GR32:$src1, -128)>;
4620 def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst),
4621           (SUB32mi8 addr:$dst, -128)>;
4622
4623 // r & (2^16-1) ==> movz
4624 def : Pat<(and GR32:$src1, 0xffff),
4625           (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, sub_16bit))>;
4626 // r & (2^8-1) ==> movz
4627 def : Pat<(and GR32:$src1, 0xff),
4628           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src1, 
4629                                                              GR32_ABCD)),
4630                                       sub_8bit))>,
4631       Requires<[In32BitMode]>;
4632 // r & (2^8-1) ==> movz
4633 def : Pat<(and GR16:$src1, 0xff),
4634           (MOVZX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src1, 
4635                                                              GR16_ABCD)),
4636                                       sub_8bit))>,
4637       Requires<[In32BitMode]>;
4638
4639 // sext_inreg patterns
4640 def : Pat<(sext_inreg GR32:$src, i16),
4641           (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, sub_16bit))>;
4642 def : Pat<(sext_inreg GR32:$src, i8),
4643           (MOVSX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4644                                                              GR32_ABCD)),
4645                                       sub_8bit))>,
4646       Requires<[In32BitMode]>;
4647 def : Pat<(sext_inreg GR16:$src, i8),
4648           (MOVSX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4649                                                              GR16_ABCD)),
4650                                       sub_8bit))>,
4651       Requires<[In32BitMode]>;
4652
4653 // trunc patterns
4654 def : Pat<(i16 (trunc GR32:$src)),
4655           (EXTRACT_SUBREG GR32:$src, sub_16bit)>;
4656 def : Pat<(i8 (trunc GR32:$src)),
4657           (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
4658                           sub_8bit)>,
4659       Requires<[In32BitMode]>;
4660 def : Pat<(i8 (trunc GR16:$src)),
4661           (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4662                           sub_8bit)>,
4663       Requires<[In32BitMode]>;
4664
4665 // h-register tricks
4666 def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))),
4667           (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4668                           sub_8bit_hi)>,
4669       Requires<[In32BitMode]>;
4670 def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))),
4671           (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
4672                           sub_8bit_hi)>,
4673       Requires<[In32BitMode]>;
4674 def : Pat<(srl GR16:$src, (i8 8)),
4675           (EXTRACT_SUBREG
4676             (MOVZX32rr8
4677               (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4678                               sub_8bit_hi)),
4679             sub_16bit)>,
4680       Requires<[In32BitMode]>;
4681 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
4682           (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4683                                                              GR16_ABCD)),
4684                                       sub_8bit_hi))>,
4685       Requires<[In32BitMode]>;
4686 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
4687           (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4688                                                              GR16_ABCD)),
4689                                       sub_8bit_hi))>,
4690       Requires<[In32BitMode]>;
4691 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
4692           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4693                                                              GR32_ABCD)),
4694                                       sub_8bit_hi))>,
4695       Requires<[In32BitMode]>;
4696 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
4697           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4698                                                              GR32_ABCD)),
4699                                       sub_8bit_hi))>,
4700       Requires<[In32BitMode]>;
4701
4702 // (shl x, 1) ==> (add x, x)
4703 def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr  GR8 :$src1, GR8 :$src1)>;
4704 def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
4705 def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
4706
4707 // (shl x (and y, 31)) ==> (shl x, y)
4708 def : Pat<(shl GR8:$src1, (and CL, 31)),
4709           (SHL8rCL GR8:$src1)>;
4710 def : Pat<(shl GR16:$src1, (and CL, 31)),
4711           (SHL16rCL GR16:$src1)>;
4712 def : Pat<(shl GR32:$src1, (and CL, 31)),
4713           (SHL32rCL GR32:$src1)>;
4714 def : Pat<(store (shl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4715           (SHL8mCL addr:$dst)>;
4716 def : Pat<(store (shl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4717           (SHL16mCL addr:$dst)>;
4718 def : Pat<(store (shl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4719           (SHL32mCL addr:$dst)>;
4720
4721 def : Pat<(srl GR8:$src1, (and CL, 31)),
4722           (SHR8rCL GR8:$src1)>;
4723 def : Pat<(srl GR16:$src1, (and CL, 31)),
4724           (SHR16rCL GR16:$src1)>;
4725 def : Pat<(srl GR32:$src1, (and CL, 31)),
4726           (SHR32rCL GR32:$src1)>;
4727 def : Pat<(store (srl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4728           (SHR8mCL addr:$dst)>;
4729 def : Pat<(store (srl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4730           (SHR16mCL addr:$dst)>;
4731 def : Pat<(store (srl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4732           (SHR32mCL addr:$dst)>;
4733
4734 def : Pat<(sra GR8:$src1, (and CL, 31)),
4735           (SAR8rCL GR8:$src1)>;
4736 def : Pat<(sra GR16:$src1, (and CL, 31)),
4737           (SAR16rCL GR16:$src1)>;
4738 def : Pat<(sra GR32:$src1, (and CL, 31)),
4739           (SAR32rCL GR32:$src1)>;
4740 def : Pat<(store (sra (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4741           (SAR8mCL addr:$dst)>;
4742 def : Pat<(store (sra (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4743           (SAR16mCL addr:$dst)>;
4744 def : Pat<(store (sra (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4745           (SAR32mCL addr:$dst)>;
4746
4747 // (anyext (setcc_carry)) -> (setcc_carry)
4748 def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
4749           (SETB_C16r)>;
4750 def : Pat<(i32 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
4751           (SETB_C32r)>;
4752 def : Pat<(i32 (anyext (i16 (X86setcc_c X86_COND_B, EFLAGS)))),
4753           (SETB_C32r)>;
4754
4755 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
4756 let AddedComplexity = 5 in { // Try this before the selecting to OR
4757 def : Pat<(or_is_add GR16:$src1, imm:$src2),
4758           (ADD16ri GR16:$src1, imm:$src2)>;
4759 def : Pat<(or_is_add GR32:$src1, imm:$src2),
4760           (ADD32ri GR32:$src1, imm:$src2)>;
4761 def : Pat<(or_is_add GR16:$src1, i16immSExt8:$src2),
4762           (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
4763 def : Pat<(or_is_add GR32:$src1, i32immSExt8:$src2),
4764           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4765 def : Pat<(or_is_add GR16:$src1, GR16:$src2),
4766           (ADD16rr GR16:$src1, GR16:$src2)>;
4767 def : Pat<(or_is_add GR32:$src1, GR32:$src2),
4768           (ADD32rr GR32:$src1, GR32:$src2)>;
4769 } // AddedComplexity
4770
4771 //===----------------------------------------------------------------------===//
4772 // EFLAGS-defining Patterns
4773 //===----------------------------------------------------------------------===//
4774
4775 // add reg, reg
4776 def : Pat<(add GR8 :$src1, GR8 :$src2), (ADD8rr  GR8 :$src1, GR8 :$src2)>;
4777 def : Pat<(add GR16:$src1, GR16:$src2), (ADD16rr GR16:$src1, GR16:$src2)>;
4778 def : Pat<(add GR32:$src1, GR32:$src2), (ADD32rr GR32:$src1, GR32:$src2)>;
4779
4780 // add reg, mem
4781 def : Pat<(add GR8:$src1, (loadi8 addr:$src2)),
4782           (ADD8rm GR8:$src1, addr:$src2)>;
4783 def : Pat<(add GR16:$src1, (loadi16 addr:$src2)),
4784           (ADD16rm GR16:$src1, addr:$src2)>;
4785 def : Pat<(add GR32:$src1, (loadi32 addr:$src2)),
4786           (ADD32rm GR32:$src1, addr:$src2)>;
4787
4788 // add reg, imm
4789 def : Pat<(add GR8 :$src1, imm:$src2), (ADD8ri  GR8:$src1 , imm:$src2)>;
4790 def : Pat<(add GR16:$src1, imm:$src2), (ADD16ri GR16:$src1, imm:$src2)>;
4791 def : Pat<(add GR32:$src1, imm:$src2), (ADD32ri GR32:$src1, imm:$src2)>;
4792 def : Pat<(add GR16:$src1, i16immSExt8:$src2),
4793           (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
4794 def : Pat<(add GR32:$src1, i32immSExt8:$src2),
4795           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4796
4797 // sub reg, reg
4798 def : Pat<(sub GR8 :$src1, GR8 :$src2), (SUB8rr  GR8 :$src1, GR8 :$src2)>;
4799 def : Pat<(sub GR16:$src1, GR16:$src2), (SUB16rr GR16:$src1, GR16:$src2)>;
4800 def : Pat<(sub GR32:$src1, GR32:$src2), (SUB32rr GR32:$src1, GR32:$src2)>;
4801
4802 // sub reg, mem
4803 def : Pat<(sub GR8:$src1, (loadi8 addr:$src2)),
4804           (SUB8rm GR8:$src1, addr:$src2)>;
4805 def : Pat<(sub GR16:$src1, (loadi16 addr:$src2)),
4806           (SUB16rm GR16:$src1, addr:$src2)>;
4807 def : Pat<(sub GR32:$src1, (loadi32 addr:$src2)),
4808           (SUB32rm GR32:$src1, addr:$src2)>;
4809
4810 // sub reg, imm
4811 def : Pat<(sub GR8:$src1, imm:$src2),
4812           (SUB8ri GR8:$src1, imm:$src2)>;
4813 def : Pat<(sub GR16:$src1, imm:$src2),
4814           (SUB16ri GR16:$src1, imm:$src2)>;
4815 def : Pat<(sub GR32:$src1, imm:$src2),
4816           (SUB32ri GR32:$src1, imm:$src2)>;
4817 def : Pat<(sub GR16:$src1, i16immSExt8:$src2),
4818           (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>;
4819 def : Pat<(sub GR32:$src1, i32immSExt8:$src2),
4820           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4821
4822 // mul reg, reg
4823 def : Pat<(mul GR16:$src1, GR16:$src2),
4824           (IMUL16rr GR16:$src1, GR16:$src2)>;
4825 def : Pat<(mul GR32:$src1, GR32:$src2),
4826           (IMUL32rr GR32:$src1, GR32:$src2)>;
4827
4828 // mul reg, mem
4829 def : Pat<(mul GR16:$src1, (loadi16 addr:$src2)),
4830           (IMUL16rm GR16:$src1, addr:$src2)>;
4831 def : Pat<(mul GR32:$src1, (loadi32 addr:$src2)),
4832           (IMUL32rm GR32:$src1, addr:$src2)>;
4833
4834 // mul reg, imm
4835 def : Pat<(mul GR16:$src1, imm:$src2),
4836           (IMUL16rri GR16:$src1, imm:$src2)>;
4837 def : Pat<(mul GR32:$src1, imm:$src2),
4838           (IMUL32rri GR32:$src1, imm:$src2)>;
4839 def : Pat<(mul GR16:$src1, i16immSExt8:$src2),
4840           (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>;
4841 def : Pat<(mul GR32:$src1, i32immSExt8:$src2),
4842           (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>;
4843
4844 // reg = mul mem, imm
4845 def : Pat<(mul (loadi16 addr:$src1), imm:$src2),
4846           (IMUL16rmi addr:$src1, imm:$src2)>;
4847 def : Pat<(mul (loadi32 addr:$src1), imm:$src2),
4848           (IMUL32rmi addr:$src1, imm:$src2)>;
4849 def : Pat<(mul (loadi16 addr:$src1), i16immSExt8:$src2),
4850           (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>;
4851 def : Pat<(mul (loadi32 addr:$src1), i32immSExt8:$src2),
4852           (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>;
4853
4854 // Optimize multiply by 2 with EFLAGS result.
4855 let AddedComplexity = 2 in {
4856 def : Pat<(X86smul_flag GR16:$src1, 2), (ADD16rr GR16:$src1, GR16:$src1)>;
4857 def : Pat<(X86smul_flag GR32:$src1, 2), (ADD32rr GR32:$src1, GR32:$src1)>;
4858 }
4859
4860 // Patterns for nodes that do not produce flags, for instructions that do.
4861
4862 // Increment reg.
4863 def : Pat<(add GR8:$src1 ,  1), (INC8r  GR8:$src1)>;
4864 def : Pat<(add GR16:$src1,  1), (INC16r GR16:$src1)>, Requires<[In32BitMode]>;
4865 def : Pat<(add GR32:$src1,  1), (INC32r GR32:$src1)>, Requires<[In32BitMode]>;
4866
4867 // Decrement reg.
4868 def : Pat<(add GR8:$src1 , -1), (DEC8r  GR8:$src1)>;
4869 def : Pat<(add GR16:$src1, -1), (DEC16r GR16:$src1)>, Requires<[In32BitMode]>;
4870 def : Pat<(add GR32:$src1, -1), (DEC32r GR32:$src1)>, Requires<[In32BitMode]>;
4871
4872 // or reg/reg.
4873 def : Pat<(or GR8 :$src1, GR8 :$src2), (OR8rr  GR8 :$src1, GR8 :$src2)>;
4874 def : Pat<(or GR16:$src1, GR16:$src2), (OR16rr GR16:$src1, GR16:$src2)>;
4875 def : Pat<(or GR32:$src1, GR32:$src2), (OR32rr GR32:$src1, GR32:$src2)>;
4876
4877 // or reg/mem
4878 def : Pat<(or GR8:$src1, (loadi8 addr:$src2)),
4879           (OR8rm GR8:$src1, addr:$src2)>;
4880 def : Pat<(or GR16:$src1, (loadi16 addr:$src2)),
4881           (OR16rm GR16:$src1, addr:$src2)>;
4882 def : Pat<(or GR32:$src1, (loadi32 addr:$src2)),
4883           (OR32rm GR32:$src1, addr:$src2)>;
4884
4885 // or reg/imm
4886 def : Pat<(or GR8:$src1 , imm:$src2), (OR8ri  GR8 :$src1, imm:$src2)>;
4887 def : Pat<(or GR16:$src1, imm:$src2), (OR16ri GR16:$src1, imm:$src2)>;
4888 def : Pat<(or GR32:$src1, imm:$src2), (OR32ri GR32:$src1, imm:$src2)>;
4889 def : Pat<(or GR16:$src1, i16immSExt8:$src2),
4890           (OR16ri8 GR16:$src1, i16immSExt8:$src2)>;
4891 def : Pat<(or GR32:$src1, i32immSExt8:$src2),
4892           (OR32ri8 GR32:$src1, i32immSExt8:$src2)>;
4893
4894 // xor reg/reg
4895 def : Pat<(xor GR8 :$src1, GR8 :$src2), (XOR8rr  GR8 :$src1, GR8 :$src2)>;
4896 def : Pat<(xor GR16:$src1, GR16:$src2), (XOR16rr GR16:$src1, GR16:$src2)>;
4897 def : Pat<(xor GR32:$src1, GR32:$src2), (XOR32rr GR32:$src1, GR32:$src2)>;
4898
4899 // xor reg/mem
4900 def : Pat<(xor GR8:$src1, (loadi8 addr:$src2)),
4901           (XOR8rm GR8:$src1, addr:$src2)>;
4902 def : Pat<(xor GR16:$src1, (loadi16 addr:$src2)),
4903           (XOR16rm GR16:$src1, addr:$src2)>;
4904 def : Pat<(xor GR32:$src1, (loadi32 addr:$src2)),
4905           (XOR32rm GR32:$src1, addr:$src2)>;
4906
4907 // xor reg/imm
4908 def : Pat<(xor GR8:$src1, imm:$src2),
4909           (XOR8ri GR8:$src1, imm:$src2)>;
4910 def : Pat<(xor GR16:$src1, imm:$src2),
4911           (XOR16ri GR16:$src1, imm:$src2)>;
4912 def : Pat<(xor GR32:$src1, imm:$src2),
4913           (XOR32ri GR32:$src1, imm:$src2)>;
4914 def : Pat<(xor GR16:$src1, i16immSExt8:$src2),
4915           (XOR16ri8 GR16:$src1, i16immSExt8:$src2)>;
4916 def : Pat<(xor GR32:$src1, i32immSExt8:$src2),
4917           (XOR32ri8 GR32:$src1, i32immSExt8:$src2)>;
4918
4919 // and reg/reg
4920 def : Pat<(and GR8 :$src1, GR8 :$src2), (AND8rr  GR8 :$src1, GR8 :$src2)>;
4921 def : Pat<(and GR16:$src1, GR16:$src2), (AND16rr GR16:$src1, GR16:$src2)>;
4922 def : Pat<(and GR32:$src1, GR32:$src2), (AND32rr GR32:$src1, GR32:$src2)>;
4923
4924 // and reg/mem
4925 def : Pat<(and GR8:$src1, (loadi8 addr:$src2)),
4926           (AND8rm GR8:$src1, addr:$src2)>;
4927 def : Pat<(and GR16:$src1, (loadi16 addr:$src2)),
4928           (AND16rm GR16:$src1, addr:$src2)>;
4929 def : Pat<(and GR32:$src1, (loadi32 addr:$src2)),
4930           (AND32rm GR32:$src1, addr:$src2)>;
4931
4932 // and reg/imm
4933 def : Pat<(and GR8:$src1, imm:$src2),
4934           (AND8ri GR8:$src1, imm:$src2)>;
4935 def : Pat<(and GR16:$src1, imm:$src2),
4936           (AND16ri GR16:$src1, imm:$src2)>;
4937 def : Pat<(and GR32:$src1, imm:$src2),
4938           (AND32ri GR32:$src1, imm:$src2)>;
4939 def : Pat<(and GR16:$src1, i16immSExt8:$src2),
4940           (AND16ri8 GR16:$src1, i16immSExt8:$src2)>;
4941 def : Pat<(and GR32:$src1, i32immSExt8:$src2),
4942           (AND32ri8 GR32:$src1, i32immSExt8:$src2)>;
4943
4944 //===----------------------------------------------------------------------===//
4945 // Floating Point Stack Support
4946 //===----------------------------------------------------------------------===//
4947
4948 include "X86InstrFPStack.td"
4949
4950 //===----------------------------------------------------------------------===//
4951 // X86-64 Support
4952 //===----------------------------------------------------------------------===//
4953
4954 include "X86Instr64bit.td"
4955
4956 //===----------------------------------------------------------------------===//
4957 // SIMD support (SSE, MMX and AVX)
4958 //===----------------------------------------------------------------------===//
4959
4960 include "X86InstrFragmentsSIMD.td"
4961
4962 //===----------------------------------------------------------------------===//
4963 // XMM Floating point support (requires SSE / SSE2)
4964 //===----------------------------------------------------------------------===//
4965
4966 include "X86InstrSSE.td"
4967
4968 //===----------------------------------------------------------------------===//
4969 // MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
4970 //===----------------------------------------------------------------------===//
4971
4972 include "X86InstrMMX.td"