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