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