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