split conditional moves and setcc's out to their own file.
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===- X86InstrInfo.td - Main X86 Instruction Definition ---*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the X86 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 // X86 specific DAG Nodes.
18 //
19
20 def SDTIntShiftDOp: SDTypeProfile<1, 3,
21                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22                                    SDTCisInt<0>, SDTCisInt<3>]>;
23
24 def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
29
30 // Unary and binary operator instructions that set EFLAGS as a side-effect.
31 def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
32                                            [SDTCisInt<0>, SDTCisVT<1, i32>]>;
33
34 def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
35                                             [SDTCisSameAs<0, 2>,
36                                              SDTCisSameAs<0, 3>,
37                                              SDTCisInt<0>, SDTCisVT<1, i32>]>;
38 def SDTX86BrCond  : SDTypeProfile<0, 3,
39                                   [SDTCisVT<0, OtherVT>,
40                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
41
42 def SDTX86SetCC   : SDTypeProfile<1, 2,
43                                   [SDTCisVT<0, i8>,
44                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
45 def SDTX86SetCC_C : SDTypeProfile<1, 2,
46                                   [SDTCisInt<0>,
47                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
48
49 def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 
50                                      SDTCisVT<2, i8>]>;
51 def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
52
53 def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
54                                 SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
55 def SDTX86Ret     : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
56
57 def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
58 def SDT_X86CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>,
59                                         SDTCisVT<1, i32>]>;
60
61 def SDT_X86Call   : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
62
63 def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
64                                                          SDTCisVT<1, iPTR>,
65                                                          SDTCisVT<2, iPTR>]>;
66
67 def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
68
69 def SDTX86Void    : SDTypeProfile<0, 0, []>;
70
71 def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
72
73 def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
74
75 def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
76
77 def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
78
79 def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
80
81 def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>;
82 def SDT_X86MEMBARRIERNoSSE : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
83
84 def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER,
85                             [SDNPHasChain]>;
86 def X86MemBarrierNoSSE : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIERNoSSE,
87                                 [SDNPHasChain]>;
88 def X86MFence : SDNode<"X86ISD::MFENCE", SDT_X86MEMBARRIER,
89                         [SDNPHasChain]>;
90 def X86SFence : SDNode<"X86ISD::SFENCE", SDT_X86MEMBARRIER,
91                         [SDNPHasChain]>;
92 def X86LFence : SDNode<"X86ISD::LFENCE", SDT_X86MEMBARRIER,
93                         [SDNPHasChain]>;
94
95
96 def X86bsf     : SDNode<"X86ISD::BSF",      SDTUnaryArithWithFlags>;
97 def X86bsr     : SDNode<"X86ISD::BSR",      SDTUnaryArithWithFlags>;
98 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
99 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
100
101 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
102 def X86bt      : SDNode<"X86ISD::BT",       SDTX86CmpTest>;
103
104 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
105 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
106                         [SDNPHasChain]>;
107 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
108 def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
109
110 def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
111                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
112                          SDNPMayLoad, SDNPMemOperand]>;
113 def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
114                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
115                          SDNPMayLoad, SDNPMemOperand]>;
116 def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
117                         [SDNPHasChain, SDNPMayStore, 
118                          SDNPMayLoad, SDNPMemOperand]>;
119 def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
120                         [SDNPHasChain, SDNPMayStore, 
121                          SDNPMayLoad, SDNPMemOperand]>;
122 def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
123                         [SDNPHasChain, SDNPMayStore, 
124                          SDNPMayLoad, SDNPMemOperand]>;
125 def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
126                         [SDNPHasChain, SDNPMayStore, 
127                          SDNPMayLoad, SDNPMemOperand]>;
128 def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
129                         [SDNPHasChain, SDNPMayStore, 
130                          SDNPMayLoad, SDNPMemOperand]>;
131 def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
132                         [SDNPHasChain, SDNPMayStore, 
133                          SDNPMayLoad, SDNPMemOperand]>;
134 def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
135                         [SDNPHasChain, SDNPMayStore, 
136                          SDNPMayLoad, SDNPMemOperand]>;
137 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
138                         [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
139
140 def X86vastart_save_xmm_regs :
141                  SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
142                         SDT_X86VASTART_SAVE_XMM_REGS,
143                         [SDNPHasChain, SDNPVariadic]>;
144
145 def X86callseq_start :
146                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
147                         [SDNPHasChain, SDNPOutFlag]>;
148 def X86callseq_end :
149                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
150                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
151
152 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
153                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
154                          SDNPVariadic]>;
155
156 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
157                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
158 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
159                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
160                          SDNPMayLoad]>;
161
162 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
163                         [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
164
165 def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
166 def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
167
168 def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
169                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
170
171 def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
172                         [SDNPHasChain]>;
173
174 def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
175                         [SDNPHasChain,  SDNPOptInFlag, SDNPVariadic]>;
176
177 def X86add_flag  : SDNode<"X86ISD::ADD",  SDTBinaryArithWithFlags,
178                           [SDNPCommutative]>;
179 def X86sub_flag  : SDNode<"X86ISD::SUB",  SDTBinaryArithWithFlags>;
180 def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
181                           [SDNPCommutative]>;
182 def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
183                           [SDNPCommutative]>;
184                           
185 def X86inc_flag  : SDNode<"X86ISD::INC",  SDTUnaryArithWithFlags>;
186 def X86dec_flag  : SDNode<"X86ISD::DEC",  SDTUnaryArithWithFlags>;
187 def X86or_flag   : SDNode<"X86ISD::OR",   SDTBinaryArithWithFlags,
188                           [SDNPCommutative]>;
189 def X86xor_flag  : SDNode<"X86ISD::XOR",  SDTBinaryArithWithFlags,
190                           [SDNPCommutative]>;
191 def X86and_flag  : SDNode<"X86ISD::AND",  SDTBinaryArithWithFlags,
192                           [SDNPCommutative]>;
193
194 def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
195
196 def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
197                             [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
198                             
199 def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
200                         []>;
201
202 //===----------------------------------------------------------------------===//
203 // X86 Operand Definitions.
204 //
205
206 // A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
207 // the index operand of an address, to conform to x86 encoding restrictions.
208 def ptr_rc_nosp : PointerLikeRegClass<1>;
209
210 // *mem - Operand definitions for the funky X86 addressing mode operands.
211 //
212 def X86MemAsmOperand : AsmOperandClass {
213   let Name = "Mem";
214   let SuperClasses = [];
215 }
216 def X86AbsMemAsmOperand : AsmOperandClass {
217   let Name = "AbsMem";
218   let SuperClasses = [X86MemAsmOperand];
219 }
220 class X86MemOperand<string printMethod> : Operand<iPTR> {
221   let PrintMethod = printMethod;
222   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
223   let ParserMatchClass = X86MemAsmOperand;
224 }
225
226 def opaque32mem : X86MemOperand<"printopaquemem">;
227 def opaque48mem : X86MemOperand<"printopaquemem">;
228 def opaque80mem : X86MemOperand<"printopaquemem">;
229 def opaque512mem : X86MemOperand<"printopaquemem">;
230
231 def i8mem   : X86MemOperand<"printi8mem">;
232 def i16mem  : X86MemOperand<"printi16mem">;
233 def i32mem  : X86MemOperand<"printi32mem">;
234 def i64mem  : X86MemOperand<"printi64mem">;
235 def i128mem : X86MemOperand<"printi128mem">;
236 def i256mem : X86MemOperand<"printi256mem">;
237 def f32mem  : X86MemOperand<"printf32mem">;
238 def f64mem  : X86MemOperand<"printf64mem">;
239 def f80mem  : X86MemOperand<"printf80mem">;
240 def f128mem : X86MemOperand<"printf128mem">;
241 def f256mem : X86MemOperand<"printf256mem">;
242
243 // A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
244 // plain GR64, so that it doesn't potentially require a REX prefix.
245 def i8mem_NOREX : Operand<i64> {
246   let PrintMethod = "printi8mem";
247   let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
248   let ParserMatchClass = X86MemAsmOperand;
249 }
250
251 // Special i32mem for addresses of load folding tail calls. These are not
252 // allowed to use callee-saved registers since they must be scheduled
253 // after callee-saved register are popped.
254 def i32mem_TC : Operand<i32> {
255   let PrintMethod = "printi32mem";
256   let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
257   let ParserMatchClass = X86MemAsmOperand;
258 }
259
260
261 let ParserMatchClass = X86AbsMemAsmOperand,
262     PrintMethod = "print_pcrel_imm" in {
263 def i32imm_pcrel : Operand<i32>;
264 def i16imm_pcrel : Operand<i16>;
265
266 def offset8 : Operand<i64>;
267 def offset16 : Operand<i64>;
268 def offset32 : Operand<i64>;
269 def offset64 : Operand<i64>;
270
271 // Branch targets have OtherVT type and print as pc-relative values.
272 def brtarget : Operand<OtherVT>;
273 def brtarget8 : Operand<OtherVT>;
274
275 }
276
277 def SSECC : Operand<i8> {
278   let PrintMethod = "printSSECC";
279 }
280
281 class ImmSExtAsmOperandClass : AsmOperandClass {
282   let SuperClasses = [ImmAsmOperand];
283   let RenderMethod = "addImmOperands";
284 }
285
286 // Sign-extended immediate classes. We don't need to define the full lattice
287 // here because there is no instruction with an ambiguity between ImmSExti64i32
288 // and ImmSExti32i8.
289 //
290 // The strange ranges come from the fact that the assembler always works with
291 // 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
292 // (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
293
294 // [0, 0x7FFFFFFF]                                            |
295 //   [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
296 def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
297   let Name = "ImmSExti64i32";
298 }
299
300 // [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
301 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
302 def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
303   let Name = "ImmSExti16i8";
304   let SuperClasses = [ImmSExti64i32AsmOperand];
305 }
306
307 // [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
308 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
309 def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
310   let Name = "ImmSExti32i8";
311 }
312
313 // [0, 0x0000007F]                                            |
314 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
315 def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
316   let Name = "ImmSExti64i8";
317   let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
318                       ImmSExti64i32AsmOperand];
319 }
320
321 // A couple of more descriptive operand definitions.
322 // 16-bits but only 8 bits are significant.
323 def i16i8imm  : Operand<i16> {
324   let ParserMatchClass = ImmSExti16i8AsmOperand;
325 }
326 // 32-bits but only 8 bits are significant.
327 def i32i8imm  : Operand<i32> {
328   let ParserMatchClass = ImmSExti32i8AsmOperand;
329 }
330
331 //===----------------------------------------------------------------------===//
332 // X86 Complex Pattern Definitions.
333 //
334
335 // Define X86 specific addressing mode.
336 def addr      : ComplexPattern<iPTR, 5, "SelectAddr", [], [SDNPWantParent]>;
337 def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
338                                [add, sub, mul, X86mul_imm, shl, or, frameindex],
339                                []>;
340 def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
341                                [tglobaltlsaddr], []>;
342
343 //===----------------------------------------------------------------------===//
344 // X86 Instruction Predicate Definitions.
345 def HasCMov      : Predicate<"Subtarget->hasCMov()">;
346 def NoCMov       : Predicate<"!Subtarget->hasCMov()">;
347
348 // FIXME: temporary hack to let codegen assert or generate poor code in case
349 // no AVX version of the desired intructions is present, this is better for
350 // incremental dev (without fallbacks it's easier to spot what's missing)
351 def HasMMX       : Predicate<"Subtarget->hasMMX() && !Subtarget->hasAVX()">;
352 def Has3DNow     : Predicate<"Subtarget->has3DNow()">;
353 def Has3DNowA    : Predicate<"Subtarget->has3DNowA()">;
354 def HasSSE1      : Predicate<"Subtarget->hasSSE1() && !Subtarget->hasAVX()">;
355 def HasSSE2      : Predicate<"Subtarget->hasSSE2() && !Subtarget->hasAVX()">;
356 def HasSSE3      : Predicate<"Subtarget->hasSSE3() && !Subtarget->hasAVX()">;
357 def HasSSSE3     : Predicate<"Subtarget->hasSSSE3() && !Subtarget->hasAVX()">;
358 def HasSSE41     : Predicate<"Subtarget->hasSSE41() && !Subtarget->hasAVX()">;
359 def HasSSE42     : Predicate<"Subtarget->hasSSE42() && !Subtarget->hasAVX()">;
360 def HasSSE4A     : Predicate<"Subtarget->hasSSE4A() && !Subtarget->hasAVX()">;
361
362 def HasAVX       : Predicate<"Subtarget->hasAVX()">;
363 def HasCLMUL     : Predicate<"Subtarget->hasCLMUL()">;
364 def HasFMA3      : Predicate<"Subtarget->hasFMA3()">;
365 def HasFMA4      : Predicate<"Subtarget->hasFMA4()">;
366 def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
367 def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
368 def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
369 def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
370 def IsWin64      : Predicate<"Subtarget->isTargetWin64()">;
371 def NotWin64     : Predicate<"!Subtarget->isTargetWin64()">;
372 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
373 def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
374 def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
375                              "TM.getCodeModel() != CodeModel::Kernel">;
376 def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
377                              "TM.getCodeModel() == CodeModel::Kernel">;
378 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
379 def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
380 def OptForSize   : Predicate<"OptForSize">;
381 def OptForSpeed  : Predicate<"!OptForSize">;
382 def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
383 def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
384 def HasAES       : Predicate<"Subtarget->hasAES()">;
385
386 //===----------------------------------------------------------------------===//
387 // X86 Instruction Format Definitions.
388 //
389
390 include "X86InstrFormats.td"
391
392 //===----------------------------------------------------------------------===//
393 // Pattern fragments...
394 //
395
396 // X86 specific condition code. These correspond to CondCode in
397 // X86InstrInfo.h. They must be kept in synch.
398 def X86_COND_A   : PatLeaf<(i8 0)>;  // alt. COND_NBE
399 def X86_COND_AE  : PatLeaf<(i8 1)>;  // alt. COND_NC
400 def X86_COND_B   : PatLeaf<(i8 2)>;  // alt. COND_C
401 def X86_COND_BE  : PatLeaf<(i8 3)>;  // alt. COND_NA
402 def X86_COND_E   : PatLeaf<(i8 4)>;  // alt. COND_Z
403 def X86_COND_G   : PatLeaf<(i8 5)>;  // alt. COND_NLE
404 def X86_COND_GE  : PatLeaf<(i8 6)>;  // alt. COND_NL
405 def X86_COND_L   : PatLeaf<(i8 7)>;  // alt. COND_NGE
406 def X86_COND_LE  : PatLeaf<(i8 8)>;  // alt. COND_NG
407 def X86_COND_NE  : PatLeaf<(i8 9)>;  // alt. COND_NZ
408 def X86_COND_NO  : PatLeaf<(i8 10)>;
409 def X86_COND_NP  : PatLeaf<(i8 11)>; // alt. COND_PO
410 def X86_COND_NS  : PatLeaf<(i8 12)>;
411 def X86_COND_O   : PatLeaf<(i8 13)>;
412 def X86_COND_P   : PatLeaf<(i8 14)>; // alt. COND_PE
413 def X86_COND_S   : PatLeaf<(i8 15)>;
414
415 def immSext8 : PatLeaf<(imm), [{ return immSext8(N); }]>;
416
417 def i16immSExt8  : PatLeaf<(i16 immSext8)>;
418 def i32immSExt8  : PatLeaf<(i32 immSext8)>;
419
420 // Helper fragments for loads.
421 // It's always safe to treat a anyext i16 load as a i32 load if the i16 is
422 // known to be 32-bit aligned or better. Ditto for i8 to i16.
423 def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
424   LoadSDNode *LD = cast<LoadSDNode>(N);
425   ISD::LoadExtType ExtType = LD->getExtensionType();
426   if (ExtType == ISD::NON_EXTLOAD)
427     return true;
428   if (ExtType == ISD::EXTLOAD)
429     return LD->getAlignment() >= 2 && !LD->isVolatile();
430   return false;
431 }]>;
432
433 def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
434   LoadSDNode *LD = cast<LoadSDNode>(N);
435   ISD::LoadExtType ExtType = LD->getExtensionType();
436   if (ExtType == ISD::EXTLOAD)
437     return LD->getAlignment() >= 2 && !LD->isVolatile();
438   return false;
439 }]>;
440
441 def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
442   LoadSDNode *LD = cast<LoadSDNode>(N);
443   ISD::LoadExtType ExtType = LD->getExtensionType();
444   if (ExtType == ISD::NON_EXTLOAD)
445     return true;
446   if (ExtType == ISD::EXTLOAD)
447     return LD->getAlignment() >= 4 && !LD->isVolatile();
448   return false;
449 }]>;
450
451 def loadi8  : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
452 def loadi64 : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;
453 def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
454 def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
455 def loadf80 : PatFrag<(ops node:$ptr), (f80 (load node:$ptr))>;
456
457 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
458 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
459 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
460
461 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
462 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
463 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
464 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
465 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
466 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
467
468 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
469 def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
470 def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
471 def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
472 def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
473 def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
474
475
476 // An 'and' node with a single use.
477 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
478   return N->hasOneUse();
479 }]>;
480 // An 'srl' node with a single use.
481 def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
482   return N->hasOneUse();
483 }]>;
484 // An 'trunc' node with a single use.
485 def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
486   return N->hasOneUse();
487 }]>;
488
489 // Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
490 def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
491   if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
492     return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
493
494   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
495   APInt Mask = APInt::getAllOnesValue(BitWidth);
496   APInt KnownZero0, KnownOne0;
497   CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
498   APInt KnownZero1, KnownOne1;
499   CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
500   return (~KnownZero0 & ~KnownZero1) == 0;
501 }]>;
502
503 //===----------------------------------------------------------------------===//
504 // Instruction list.
505 //
506
507 // Nop
508 let neverHasSideEffects = 1 in {
509   def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
510   def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
511                 "nop{w}\t$zero", []>, TB, OpSize;
512   def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
513                 "nop{l}\t$zero", []>, TB;
514 }
515
516
517 // Constructing a stack frame.
518 def ENTER : Ii16<0xC8, RawFrmImm8, (outs), (ins i16imm:$len, i8imm:$lvl),
519                  "enter\t$len, $lvl", []>;
520
521 let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
522 def LEAVE    : I<0xC9, RawFrm,
523                  (outs), (ins), "leave", []>, Requires<[In32BitMode]>;
524
525 //===----------------------------------------------------------------------===//
526 //  Miscellaneous Instructions...
527 //
528 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
529                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
530 let mayLoad = 1 in
531 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
532                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
533 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
534                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
535 let mayLoad = 1 in
536 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
537                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
538
539 let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
540 let mayLoad = 1 in {
541 def POP16r  : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
542   OpSize;
543 def POP32r  : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
544 def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
545   OpSize;
546 def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
547   OpSize;
548 def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
549 def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
550 }
551
552 let mayStore = 1 in {
553 def PUSH16r  : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
554   OpSize;
555 def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
556 def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
557   OpSize;
558 def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
559   OpSize;
560 def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
561 def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
562 }
563 }
564
565 let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
566 def PUSHi8   : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 
567                       "push{l}\t$imm", []>;
568 def PUSHi16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
569                       "push{w}\t$imm", []>, OpSize;
570 def PUSHi32  : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 
571                       "push{l}\t$imm", []>;
572 }
573
574 let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
575 def POPF16   : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
576 def POPF32   : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
577                Requires<[In32BitMode]>;
578 }
579 let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
580 def PUSHF16  : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
581 def PUSHF32  : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
582                Requires<[In32BitMode]>;
583 }
584
585 let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
586     mayLoad=1, neverHasSideEffects=1 in {
587 def POPA32   : I<0x61, RawFrm, (outs), (ins), "popa{l}", []>,
588                Requires<[In32BitMode]>;
589 }
590 let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
591     mayStore=1, neverHasSideEffects=1 in {
592 def PUSHA32  : I<0x60, RawFrm, (outs), (ins), "pusha{l}", []>,
593                Requires<[In32BitMode]>;
594 }
595
596 let Uses = [EFLAGS], Constraints = "$src = $dst" in     // GR32 = bswap GR32
597   def BSWAP32r : I<0xC8, AddRegFrm,
598                    (outs GR32:$dst), (ins GR32:$src),
599                    "bswap{l}\t$dst", 
600                    [(set GR32:$dst, (bswap GR32:$src))]>, TB;
601
602
603 // Bit scan instructions.
604 let Defs = [EFLAGS] in {
605 def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
606                  "bsf{w}\t{$src, $dst|$dst, $src}",
607                  [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
608 def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
609                  "bsf{w}\t{$src, $dst|$dst, $src}",
610                  [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
611                  OpSize;
612 def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
613                  "bsf{l}\t{$src, $dst|$dst, $src}",
614                  [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
615 def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
616                  "bsf{l}\t{$src, $dst|$dst, $src}",
617                  [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
618
619 def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
620                  "bsr{w}\t{$src, $dst|$dst, $src}",
621                  [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
622 def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
623                  "bsr{w}\t{$src, $dst|$dst, $src}",
624                  [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
625                  OpSize;
626 def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
627                  "bsr{l}\t{$src, $dst|$dst, $src}",
628                  [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
629 def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
630                  "bsr{l}\t{$src, $dst|$dst, $src}",
631                  [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
632 } // Defs = [EFLAGS]
633
634 let neverHasSideEffects = 1 in
635 def LEA16r   : I<0x8D, MRMSrcMem,
636                  (outs GR16:$dst), (ins i32mem:$src),
637                  "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
638 let isReMaterializable = 1 in
639 def LEA32r   : I<0x8D, MRMSrcMem,
640                  (outs GR32:$dst), (ins i32mem:$src),
641                  "lea{l}\t{$src|$dst}, {$dst|$src}",
642                  [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
643
644
645 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
646 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
647 def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
648 def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
649 def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
650 def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", []>;
651 }
652
653 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
654 let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
655 def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
656 let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
657 def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
658 let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
659 def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
660 let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
661 def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", []>;
662
663 def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
664 def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
665 def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
666 def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", []>;
667
668 def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
669 def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
670 def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
671 def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", []>;
672
673
674 //===----------------------------------------------------------------------===//
675 //  Move Instructions.
676 //
677 let neverHasSideEffects = 1 in {
678 def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
679                 "mov{b}\t{$src, $dst|$dst, $src}", []>;
680 def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
681                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
682 def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
683                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
684 }
685 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
686 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
687                    "mov{b}\t{$src, $dst|$dst, $src}",
688                    [(set GR8:$dst, imm:$src)]>;
689 def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
690                    "mov{w}\t{$src, $dst|$dst, $src}",
691                    [(set GR16:$dst, imm:$src)]>, OpSize;
692 def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
693                    "mov{l}\t{$src, $dst|$dst, $src}",
694                    [(set GR32:$dst, imm:$src)]>;
695 }
696
697 def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
698                    "mov{b}\t{$src, $dst|$dst, $src}",
699                    [(store (i8 imm:$src), addr:$dst)]>;
700 def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
701                    "mov{w}\t{$src, $dst|$dst, $src}",
702                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
703 def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
704                    "mov{l}\t{$src, $dst|$dst, $src}",
705                    [(store (i32 imm:$src), addr:$dst)]>;
706
707 /// moffs8, moffs16 and moffs32 versions of moves.  The immediate is a
708 /// 32-bit offset from the PC.  These are only valid in x86-32 mode.
709 def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
710                    "mov{b}\t{$src, %al|%al, $src}", []>,
711                    Requires<[In32BitMode]>;
712 def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
713                       "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize,
714                      Requires<[In32BitMode]>;
715 def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
716                       "mov{l}\t{$src, %eax|%eax, $src}", []>,
717                      Requires<[In32BitMode]>;
718 def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
719                    "mov{b}\t{%al, $dst|$dst, %al}", []>,
720                   Requires<[In32BitMode]>;
721 def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
722                       "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize,
723                      Requires<[In32BitMode]>;
724 def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
725                       "mov{l}\t{%eax, $dst|$dst, %eax}", []>,
726                      Requires<[In32BitMode]>;
727                       
728
729 let isCodeGenOnly = 1 in {
730 def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
731                    "mov{b}\t{$src, $dst|$dst, $src}", []>;
732 def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
733                     "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
734 def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
735                     "mov{l}\t{$src, $dst|$dst, $src}", []>;
736 }
737
738 let canFoldAsLoad = 1, isReMaterializable = 1 in {
739 def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
740                 "mov{b}\t{$src, $dst|$dst, $src}",
741                 [(set GR8:$dst, (loadi8 addr:$src))]>;
742 def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
743                 "mov{w}\t{$src, $dst|$dst, $src}",
744                 [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
745 def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
746                 "mov{l}\t{$src, $dst|$dst, $src}",
747                 [(set GR32:$dst, (loadi32 addr:$src))]>;
748 }
749
750 def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
751                 "mov{b}\t{$src, $dst|$dst, $src}",
752                 [(store GR8:$src, addr:$dst)]>;
753 def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
754                 "mov{w}\t{$src, $dst|$dst, $src}",
755                 [(store GR16:$src, addr:$dst)]>, OpSize;
756 def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
757                 "mov{l}\t{$src, $dst|$dst, $src}",
758                 [(store GR32:$src, addr:$dst)]>;
759
760 /// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
761 let isCodeGenOnly = 1 in {
762 let neverHasSideEffects = 1 in
763 def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
764                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
765
766 let mayLoad = 1,
767     canFoldAsLoad = 1, isReMaterializable = 1 in
768 def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
769                 "mov{l}\t{$src, $dst|$dst, $src}",
770                 []>;
771
772 let mayStore = 1 in
773 def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
774                 "mov{l}\t{$src, $dst|$dst, $src}",
775                 []>;
776 }
777
778 // Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
779 // that they can be used for copying and storing h registers, which can't be
780 // encoded when a REX prefix is present.
781 let isCodeGenOnly = 1 in {
782 let neverHasSideEffects = 1 in
783 def MOV8rr_NOREX : I<0x88, MRMDestReg,
784                      (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
785                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
786 let mayStore = 1 in
787 def MOV8mr_NOREX : I<0x88, MRMDestMem,
788                      (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
789                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
790 let mayLoad = 1,
791     canFoldAsLoad = 1, isReMaterializable = 1 in
792 def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
793                      (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
794                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
795 }
796
797 //===----------------------------------------------------------------------===//
798 //  Fixed-Register Multiplication and Division Instructions...
799 //
800
801 // Extra precision multiplication
802
803 // AL is really implied by AX, but the registers in Defs must match the
804 // SDNode results (i8, i32).
805 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
806 def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
807                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
808                // This probably ought to be moved to a def : Pat<> if the
809                // syntax can be accepted.
810                [(set AL, (mul AL, GR8:$src)),
811                 (implicit EFLAGS)]>;     // AL,AH = AL*GR8
812
813 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
814 def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src),
815                "mul{w}\t$src", 
816                []>, OpSize;    // AX,DX = AX*GR16
817
818 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
819 def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src),
820                "mul{l}\t$src",
821                []>; // EAX,EDX = EAX*GR32
822
823 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
824 def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
825                "mul{b}\t$src",
826                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
827                // This probably ought to be moved to a def : Pat<> if the
828                // syntax can be accepted.
829                [(set AL, (mul AL, (loadi8 addr:$src))),
830                 (implicit EFLAGS)]>;   // AL,AH = AL*[mem8]
831
832 let mayLoad = 1, neverHasSideEffects = 1 in {
833 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
834 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
835                "mul{w}\t$src",
836                []>, OpSize; // AX,DX = AX*[mem16]
837
838 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
839 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
840               "mul{l}\t$src",
841               []>;          // EAX,EDX = EAX*[mem32]
842 }
843
844 let neverHasSideEffects = 1 in {
845 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
846 def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
847               // AL,AH = AL*GR8
848 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
849 def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
850               OpSize;    // AX,DX = AX*GR16
851 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
852 def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
853               // EAX,EDX = EAX*GR32
854 let mayLoad = 1 in {
855 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
856 def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
857                 "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
858 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
859 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
860                 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
861 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
862 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
863                 "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
864 }
865 } // neverHasSideEffects
866
867 // unsigned division/remainder
868 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
869 def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
870                "div{b}\t$src", []>;
871 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
872 def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
873                "div{w}\t$src", []>, OpSize;
874 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
875 def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
876                "div{l}\t$src", []>;
877 let mayLoad = 1 in {
878 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
879 def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
880                "div{b}\t$src", []>;
881 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
882 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
883                "div{w}\t$src", []>, OpSize;
884 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
885                                                     // EDX:EAX/[mem32] = EAX,EDX
886 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
887                "div{l}\t$src", []>;
888 }
889
890 // Signed division/remainder.
891 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
892 def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
893                "idiv{b}\t$src", []>;
894 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
895 def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
896                "idiv{w}\t$src", []>, OpSize;
897 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
898 def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
899                "idiv{l}\t$src", []>;
900 let mayLoad = 1, mayLoad = 1 in {
901 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
902 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
903                "idiv{b}\t$src", []>;
904 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
905 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
906                "idiv{w}\t$src", []>, OpSize;
907 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
908 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src), 
909                                                     // EDX:EAX/[mem32] = EAX,EDX
910                "idiv{l}\t$src", []>;
911 }
912
913 //===----------------------------------------------------------------------===//
914 //  Two address Instructions.
915 //
916 let Constraints = "$src1 = $dst" in {
917
918 // unary instructions
919 let CodeSize = 2 in {
920 let Defs = [EFLAGS] in {
921 def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
922                "neg{b}\t$dst",
923                [(set GR8:$dst, (ineg GR8:$src1)),
924                 (implicit EFLAGS)]>;
925 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
926                "neg{w}\t$dst",
927                [(set GR16:$dst, (ineg GR16:$src1)),
928                 (implicit EFLAGS)]>, OpSize;
929 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
930                "neg{l}\t$dst",
931                [(set GR32:$dst, (ineg GR32:$src1)),
932                 (implicit EFLAGS)]>;
933                 
934 let Constraints = "" in {
935   def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
936                  "neg{b}\t$dst",
937                  [(store (ineg (loadi8 addr:$dst)), addr:$dst),
938                   (implicit EFLAGS)]>;
939   def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
940                  "neg{w}\t$dst",
941                  [(store (ineg (loadi16 addr:$dst)), addr:$dst),
942                   (implicit EFLAGS)]>, OpSize;
943   def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
944                  "neg{l}\t$dst",
945                  [(store (ineg (loadi32 addr:$dst)), addr:$dst),
946                   (implicit EFLAGS)]>;
947 } // Constraints = ""
948 } // Defs = [EFLAGS]
949
950 // Match xor -1 to not. Favors these over a move imm + xor to save code size.
951 let AddedComplexity = 15 in {
952 def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
953                "not{b}\t$dst",
954                [(set GR8:$dst, (not GR8:$src1))]>;
955 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
956                "not{w}\t$dst",
957                [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
958 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
959                "not{l}\t$dst",
960                [(set GR32:$dst, (not GR32:$src1))]>;
961 }
962 let Constraints = "" in {
963   def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
964                  "not{b}\t$dst",
965                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
966   def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
967                  "not{w}\t$dst",
968                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
969   def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
970                  "not{l}\t$dst",
971                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
972 } // Constraints = ""
973 } // CodeSize
974
975 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
976 let Defs = [EFLAGS] in {
977 let CodeSize = 2 in
978 def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
979                "inc{b}\t$dst",
980                [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
981
982 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
983 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
984                "inc{w}\t$dst",
985                [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
986              OpSize, Requires<[In32BitMode]>;
987 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
988                "inc{l}\t$dst",
989                [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
990              Requires<[In32BitMode]>;
991 }
992 let Constraints = "", CodeSize = 2 in {
993   def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
994                [(store (add (loadi8 addr:$dst), 1), addr:$dst),
995                 (implicit EFLAGS)]>;
996   def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
997                [(store (add (loadi16 addr:$dst), 1), addr:$dst),
998                 (implicit EFLAGS)]>,
999                OpSize, Requires<[In32BitMode]>;
1000   def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
1001                [(store (add (loadi32 addr:$dst), 1), addr:$dst),
1002                 (implicit EFLAGS)]>,
1003                Requires<[In32BitMode]>;
1004 } // Constraints = "", CodeSize = 2
1005
1006 let CodeSize = 2 in
1007 def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1008                "dec{b}\t$dst",
1009                [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
1010 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
1011 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1012                "dec{w}\t$dst",
1013                [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
1014              OpSize, Requires<[In32BitMode]>;
1015 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1016                "dec{l}\t$dst",
1017                [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
1018              Requires<[In32BitMode]>;
1019 } // CodeSize = 2
1020
1021 let Constraints = "", CodeSize = 2 in {
1022   def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
1023                [(store (add (loadi8 addr:$dst), -1), addr:$dst),
1024                 (implicit EFLAGS)]>;
1025   def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
1026                [(store (add (loadi16 addr:$dst), -1), addr:$dst),
1027                 (implicit EFLAGS)]>,
1028                OpSize, Requires<[In32BitMode]>;
1029   def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
1030                [(store (add (loadi32 addr:$dst), -1), addr:$dst),
1031                 (implicit EFLAGS)]>,
1032                Requires<[In32BitMode]>;
1033 } // Constraints = "", CodeSize = 2
1034 } // Defs = [EFLAGS]
1035
1036 // Logical operators...
1037 let Defs = [EFLAGS] in {
1038 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1039 def AND8rr  : I<0x20, MRMDestReg,
1040                (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1041                "and{b}\t{$src2, $dst|$dst, $src2}",
1042                [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
1043 def AND16rr : I<0x21, MRMDestReg,
1044                 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1045                 "and{w}\t{$src2, $dst|$dst, $src2}",
1046                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1047                                                       GR16:$src2))]>, OpSize;
1048 def AND32rr : I<0x21, MRMDestReg, 
1049                 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1050                 "and{l}\t{$src2, $dst|$dst, $src2}",
1051                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1052                                                       GR32:$src2))]>;
1053 }
1054
1055 // AND instructions with the destination register in REG and the source register
1056 //   in R/M.  Included for the disassembler.
1057 let isCodeGenOnly = 1 in {
1058 def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1059                   "and{b}\t{$src2, $dst|$dst, $src2}", []>;
1060 def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst), 
1061                     (ins GR16:$src1, GR16:$src2),
1062                    "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1063 def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst), 
1064                     (ins GR32:$src1, GR32:$src2),
1065                    "and{l}\t{$src2, $dst|$dst, $src2}", []>;
1066 }
1067
1068 def AND8rm   : I<0x22, MRMSrcMem, 
1069                  (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1070                  "and{b}\t{$src2, $dst|$dst, $src2}",
1071                 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1072                                                      (loadi8 addr:$src2)))]>;
1073 def AND16rm  : I<0x23, MRMSrcMem, 
1074                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1075                  "and{w}\t{$src2, $dst|$dst, $src2}",
1076                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1077                                                       (loadi16 addr:$src2)))]>,
1078                OpSize;
1079 def AND32rm  : I<0x23, MRMSrcMem,
1080                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1081                  "and{l}\t{$src2, $dst|$dst, $src2}",
1082                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1083                                                       (loadi32 addr:$src2)))]>;
1084
1085 def AND8ri   : Ii8<0x80, MRM4r, 
1086                    (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
1087                    "and{b}\t{$src2, $dst|$dst, $src2}",
1088                    [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1089                                                         imm:$src2))]>;
1090 def AND16ri  : Ii16<0x81, MRM4r, 
1091                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1092                     "and{w}\t{$src2, $dst|$dst, $src2}",
1093                     [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1094                                                           imm:$src2))]>, OpSize;
1095 def AND32ri  : Ii32<0x81, MRM4r, 
1096                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1097                     "and{l}\t{$src2, $dst|$dst, $src2}",
1098                     [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1099                                                           imm:$src2))]>;
1100 def AND16ri8 : Ii8<0x83, MRM4r, 
1101                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1102                    "and{w}\t{$src2, $dst|$dst, $src2}",
1103                    [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1104                                                          i16immSExt8:$src2))]>,
1105                    OpSize;
1106 def AND32ri8 : Ii8<0x83, MRM4r, 
1107                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1108                    "and{l}\t{$src2, $dst|$dst, $src2}",
1109                    [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1110                                                          i32immSExt8:$src2))]>;
1111
1112 let Constraints = "" in {
1113   def AND8mr   : I<0x20, MRMDestMem,
1114                    (outs), (ins i8mem :$dst, GR8 :$src),
1115                    "and{b}\t{$src, $dst|$dst, $src}",
1116                    [(store (and (load addr:$dst), GR8:$src), addr:$dst),
1117                     (implicit EFLAGS)]>;
1118   def AND16mr  : I<0x21, MRMDestMem,
1119                    (outs), (ins i16mem:$dst, GR16:$src),
1120                    "and{w}\t{$src, $dst|$dst, $src}",
1121                    [(store (and (load addr:$dst), GR16:$src), addr:$dst),
1122                     (implicit EFLAGS)]>,
1123                    OpSize;
1124   def AND32mr  : I<0x21, MRMDestMem,
1125                    (outs), (ins i32mem:$dst, GR32:$src),
1126                    "and{l}\t{$src, $dst|$dst, $src}",
1127                    [(store (and (load addr:$dst), GR32:$src), addr:$dst),
1128                     (implicit EFLAGS)]>;
1129   def AND8mi   : Ii8<0x80, MRM4m,
1130                      (outs), (ins i8mem :$dst, i8imm :$src),
1131                      "and{b}\t{$src, $dst|$dst, $src}",
1132                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
1133                        (implicit EFLAGS)]>;
1134   def AND16mi  : Ii16<0x81, MRM4m,
1135                       (outs), (ins i16mem:$dst, i16imm:$src),
1136                       "and{w}\t{$src, $dst|$dst, $src}",
1137                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
1138                        (implicit EFLAGS)]>,
1139                       OpSize;
1140   def AND32mi  : Ii32<0x81, MRM4m,
1141                       (outs), (ins i32mem:$dst, i32imm:$src),
1142                       "and{l}\t{$src, $dst|$dst, $src}",
1143                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
1144                        (implicit EFLAGS)]>;
1145   def AND16mi8 : Ii8<0x83, MRM4m,
1146                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1147                      "and{w}\t{$src, $dst|$dst, $src}",
1148                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
1149                  (implicit EFLAGS)]>,
1150                      OpSize;
1151   def AND32mi8 : Ii8<0x83, MRM4m,
1152                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1153                      "and{l}\t{$src, $dst|$dst, $src}",
1154                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
1155                  (implicit EFLAGS)]>;
1156
1157   def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
1158                    "and{b}\t{$src, %al|%al, $src}", []>;
1159   def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
1160                       "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1161   def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
1162                       "and{l}\t{$src, %eax|%eax, $src}", []>;
1163
1164 } // Constraints = ""
1165
1166
1167 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1168 def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), 
1169                  (ins GR8 :$src1, GR8 :$src2),
1170                  "or{b}\t{$src2, $dst|$dst, $src2}",
1171                  [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
1172 def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), 
1173                  (ins GR16:$src1, GR16:$src2),
1174                  "or{w}\t{$src2, $dst|$dst, $src2}",
1175                  [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
1176                OpSize;
1177 def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), 
1178                  (ins GR32:$src1, GR32:$src2),
1179                  "or{l}\t{$src2, $dst|$dst, $src2}",
1180                  [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
1181 }
1182
1183 // OR instructions with the destination register in REG and the source register
1184 //   in R/M.  Included for the disassembler.
1185 let isCodeGenOnly = 1 in {
1186 def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1187                   "or{b}\t{$src2, $dst|$dst, $src2}", []>;
1188 def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
1189                    (ins GR16:$src1, GR16:$src2),
1190                    "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1191 def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst), 
1192                    (ins GR32:$src1, GR32:$src2),
1193                    "or{l}\t{$src2, $dst|$dst, $src2}", []>;
1194 }
1195                   
1196 def OR8rm    : I<0x0A, MRMSrcMem, (outs GR8 :$dst), 
1197                  (ins GR8 :$src1, i8mem :$src2),
1198                  "or{b}\t{$src2, $dst|$dst, $src2}",
1199                 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
1200                                                     (load addr:$src2)))]>;
1201 def OR16rm   : I<0x0B, MRMSrcMem, (outs GR16:$dst), 
1202                  (ins GR16:$src1, i16mem:$src2),
1203                  "or{w}\t{$src2, $dst|$dst, $src2}",
1204                 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1205                                                      (load addr:$src2)))]>,
1206                OpSize;
1207 def OR32rm   : I<0x0B, MRMSrcMem, (outs GR32:$dst), 
1208                  (ins GR32:$src1, i32mem:$src2),
1209                  "or{l}\t{$src2, $dst|$dst, $src2}",
1210                 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1211                                                      (load addr:$src2)))]>;
1212
1213 def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), 
1214                     (ins GR8 :$src1, i8imm:$src2),
1215                     "or{b}\t{$src2, $dst|$dst, $src2}",
1216                     [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
1217 def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), 
1218                     (ins GR16:$src1, i16imm:$src2),
1219                     "or{w}\t{$src2, $dst|$dst, $src2}", 
1220                     [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1221                                                         imm:$src2))]>, OpSize;
1222 def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), 
1223                     (ins GR32:$src1, i32imm:$src2),
1224                     "or{l}\t{$src2, $dst|$dst, $src2}",
1225                     [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1226                                                          imm:$src2))]>;
1227
1228 def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), 
1229                    (ins GR16:$src1, i16i8imm:$src2),
1230                    "or{w}\t{$src2, $dst|$dst, $src2}",
1231                    [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1232                                                 i16immSExt8:$src2))]>, OpSize;
1233 def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), 
1234                    (ins GR32:$src1, i32i8imm:$src2),
1235                    "or{l}\t{$src2, $dst|$dst, $src2}",
1236                    [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1237                                                         i32immSExt8:$src2))]>;
1238 let Constraints = "" in {
1239   def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
1240                  "or{b}\t{$src, $dst|$dst, $src}",
1241                  [(store (or (load addr:$dst), GR8:$src), addr:$dst),
1242                   (implicit EFLAGS)]>;
1243   def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
1244                  "or{w}\t{$src, $dst|$dst, $src}",
1245                  [(store (or (load addr:$dst), GR16:$src), addr:$dst),
1246                   (implicit EFLAGS)]>, OpSize;
1247   def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1248                  "or{l}\t{$src, $dst|$dst, $src}",
1249                  [(store (or (load addr:$dst), GR32:$src), addr:$dst),
1250                   (implicit EFLAGS)]>;
1251   def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
1252                  "or{b}\t{$src, $dst|$dst, $src}",
1253                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
1254                   (implicit EFLAGS)]>;
1255   def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
1256                  "or{w}\t{$src, $dst|$dst, $src}",
1257                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
1258                   (implicit EFLAGS)]>,
1259                  OpSize;
1260   def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
1261                  "or{l}\t{$src, $dst|$dst, $src}",
1262                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
1263                   (implicit EFLAGS)]>;
1264   def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
1265                  "or{w}\t{$src, $dst|$dst, $src}",
1266                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
1267                   (implicit EFLAGS)]>,
1268                      OpSize;
1269   def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
1270                  "or{l}\t{$src, $dst|$dst, $src}",
1271                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
1272                   (implicit EFLAGS)]>;
1273                   
1274   def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
1275                    "or{b}\t{$src, %al|%al, $src}", []>;
1276   def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
1277                       "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1278   def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
1279                       "or{l}\t{$src, %eax|%eax, $src}", []>;
1280 } // Constraints = ""
1281
1282
1283 let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
1284   def XOR8rr   : I<0x30, MRMDestReg,
1285                    (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1286                    "xor{b}\t{$src2, $dst|$dst, $src2}",
1287                    [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
1288                                                         GR8:$src2))]>;
1289   def XOR16rr  : I<0x31, MRMDestReg, 
1290                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
1291                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1292                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1293                                                          GR16:$src2))]>, OpSize;
1294   def XOR32rr  : I<0x31, MRMDestReg, 
1295                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
1296                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1297                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1298                                                          GR32:$src2))]>;
1299 } // isCommutable = 1
1300
1301 // XOR instructions with the destination register in REG and the source register
1302 //   in R/M.  Included for the disassembler.
1303 let isCodeGenOnly = 1 in {
1304 def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1305                   "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
1306 def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst), 
1307                     (ins GR16:$src1, GR16:$src2),
1308                    "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1309 def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst), 
1310                     (ins GR32:$src1, GR32:$src2),
1311                    "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
1312 }
1313
1314 def XOR8rm   : I<0x32, MRMSrcMem, 
1315                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
1316                  "xor{b}\t{$src2, $dst|$dst, $src2}",
1317                  [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
1318                                                       (load addr:$src2)))]>;
1319 def XOR16rm  : I<0x33, MRMSrcMem, 
1320                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
1321                  "xor{w}\t{$src2, $dst|$dst, $src2}",
1322                  [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1323                                                        (load addr:$src2)))]>,
1324                  OpSize;
1325 def XOR32rm  : I<0x33, MRMSrcMem, 
1326                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
1327                  "xor{l}\t{$src2, $dst|$dst, $src2}",
1328                  [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1329                                                        (load addr:$src2)))]>;
1330
1331 def XOR8ri  : Ii8<0x80, MRM6r, 
1332                   (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
1333                   "xor{b}\t{$src2, $dst|$dst, $src2}",
1334                   [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
1335 def XOR16ri : Ii16<0x81, MRM6r, 
1336                    (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
1337                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1338                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1339                                                          imm:$src2))]>, OpSize;
1340 def XOR32ri  : Ii32<0x81, MRM6r, 
1341                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
1342                     "xor{l}\t{$src2, $dst|$dst, $src2}",
1343                     [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1344                                                           imm:$src2))]>;
1345 def XOR16ri8 : Ii8<0x83, MRM6r, 
1346                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1347                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1348                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1349                                                          i16immSExt8:$src2))]>,
1350                    OpSize;
1351 def XOR32ri8 : Ii8<0x83, MRM6r, 
1352                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1353                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1354                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1355                                                          i32immSExt8:$src2))]>;
1356
1357 let Constraints = "" in {
1358   def XOR8mr   : I<0x30, MRMDestMem,
1359                    (outs), (ins i8mem :$dst, GR8 :$src),
1360                    "xor{b}\t{$src, $dst|$dst, $src}",
1361                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
1362                     (implicit EFLAGS)]>;
1363   def XOR16mr  : I<0x31, MRMDestMem,
1364                    (outs), (ins i16mem:$dst, GR16:$src),
1365                    "xor{w}\t{$src, $dst|$dst, $src}",
1366                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
1367                     (implicit EFLAGS)]>,
1368                    OpSize;
1369   def XOR32mr  : I<0x31, MRMDestMem,
1370                    (outs), (ins i32mem:$dst, GR32:$src),
1371                    "xor{l}\t{$src, $dst|$dst, $src}",
1372                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
1373                     (implicit EFLAGS)]>;
1374   def XOR8mi   : Ii8<0x80, MRM6m,
1375                      (outs), (ins i8mem :$dst, i8imm :$src),
1376                      "xor{b}\t{$src, $dst|$dst, $src}",
1377                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
1378                      (implicit EFLAGS)]>;
1379   def XOR16mi  : Ii16<0x81, MRM6m,
1380                       (outs), (ins i16mem:$dst, i16imm:$src),
1381                       "xor{w}\t{$src, $dst|$dst, $src}",
1382                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
1383                     (implicit EFLAGS)]>,
1384                       OpSize;
1385   def XOR32mi  : Ii32<0x81, MRM6m,
1386                       (outs), (ins i32mem:$dst, i32imm:$src),
1387                       "xor{l}\t{$src, $dst|$dst, $src}",
1388                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
1389                     (implicit EFLAGS)]>;
1390   def XOR16mi8 : Ii8<0x83, MRM6m,
1391                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1392                      "xor{w}\t{$src, $dst|$dst, $src}",
1393                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
1394                   (implicit EFLAGS)]>,
1395                      OpSize;
1396   def XOR32mi8 : Ii8<0x83, MRM6m,
1397                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1398                      "xor{l}\t{$src, $dst|$dst, $src}",
1399                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
1400                   (implicit EFLAGS)]>;
1401                   
1402   def XOR8i8   : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
1403                       "xor{b}\t{$src, %al|%al, $src}", []>;
1404   def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
1405                       "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1406   def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
1407                       "xor{l}\t{$src, %eax|%eax, $src}", []>;
1408 } // Constraints = ""
1409 } // Defs = [EFLAGS]
1410
1411 // Shift instructions
1412 let Defs = [EFLAGS] in {
1413 let Uses = [CL] in {
1414 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
1415                  "shl{b}\t{%cl, $dst|$dst, CL}",
1416                  [(set GR8:$dst, (shl GR8:$src1, CL))]>;
1417 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
1418                  "shl{w}\t{%cl, $dst|$dst, CL}",
1419                  [(set GR16:$dst, (shl GR16:$src1, CL))]>, OpSize;
1420 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
1421                  "shl{l}\t{%cl, $dst|$dst, CL}",
1422                  [(set GR32:$dst, (shl GR32:$src1, CL))]>;
1423 } // Uses = [CL]
1424
1425 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1426                    "shl{b}\t{$src2, $dst|$dst, $src2}",
1427                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
1428                    
1429 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1430 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1431                    "shl{w}\t{$src2, $dst|$dst, $src2}",
1432                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1433 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1434                    "shl{l}\t{$src2, $dst|$dst, $src2}",
1435                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
1436
1437 // NOTE: We don't include patterns for shifts of a register by one, because
1438 // 'add reg,reg' is cheaper.
1439
1440 def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
1441                  "shl{b}\t$dst", []>;
1442 def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
1443                  "shl{w}\t$dst", []>, OpSize;
1444 def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
1445                  "shl{l}\t$dst", []>;
1446
1447 } // isConvertibleToThreeAddress = 1
1448
1449 let Constraints = "" in {
1450   let Uses = [CL] in {
1451   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
1452                    "shl{b}\t{%cl, $dst|$dst, CL}",
1453                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
1454   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
1455                    "shl{w}\t{%cl, $dst|$dst, CL}",
1456                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1457   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
1458                    "shl{l}\t{%cl, $dst|$dst, CL}",
1459                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
1460   }
1461   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
1462                      "shl{b}\t{$src, $dst|$dst, $src}",
1463                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1464   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
1465                      "shl{w}\t{$src, $dst|$dst, $src}",
1466                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1467                      OpSize;
1468   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
1469                      "shl{l}\t{$src, $dst|$dst, $src}",
1470                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1471
1472   // Shift by 1
1473   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
1474                    "shl{b}\t$dst",
1475                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1476   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
1477                    "shl{w}\t$dst",
1478                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1479                      OpSize;
1480   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
1481                    "shl{l}\t$dst",
1482                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1483 } // Constraints = ""
1484
1485 let Uses = [CL] in {
1486 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
1487                  "shr{b}\t{%cl, $dst|$dst, CL}",
1488                  [(set GR8:$dst, (srl GR8:$src1, CL))]>;
1489 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
1490                  "shr{w}\t{%cl, $dst|$dst, CL}",
1491                  [(set GR16:$dst, (srl GR16:$src1, CL))]>, OpSize;
1492 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
1493                  "shr{l}\t{%cl, $dst|$dst, CL}",
1494                  [(set GR32:$dst, (srl GR32:$src1, CL))]>;
1495 }
1496
1497 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
1498                    "shr{b}\t{$src2, $dst|$dst, $src2}",
1499                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
1500 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1501                    "shr{w}\t{$src2, $dst|$dst, $src2}",
1502                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1503 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1504                    "shr{l}\t{$src2, $dst|$dst, $src2}",
1505                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
1506
1507 // Shift by 1
1508 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
1509                  "shr{b}\t$dst",
1510                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
1511 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
1512                  "shr{w}\t$dst",
1513                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
1514 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
1515                  "shr{l}\t$dst",
1516                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
1517
1518 let Constraints = "" in {
1519   let Uses = [CL] in {
1520   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
1521                    "shr{b}\t{%cl, $dst|$dst, CL}",
1522                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
1523   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
1524                    "shr{w}\t{%cl, $dst|$dst, CL}",
1525                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
1526                    OpSize;
1527   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
1528                    "shr{l}\t{%cl, $dst|$dst, CL}",
1529                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
1530   }
1531   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
1532                      "shr{b}\t{$src, $dst|$dst, $src}",
1533                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1534   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
1535                      "shr{w}\t{$src, $dst|$dst, $src}",
1536                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1537                      OpSize;
1538   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
1539                      "shr{l}\t{$src, $dst|$dst, $src}",
1540                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1541
1542   // Shift by 1
1543   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
1544                    "shr{b}\t$dst",
1545                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1546   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
1547                    "shr{w}\t$dst",
1548                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
1549   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
1550                    "shr{l}\t$dst",
1551                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1552 } // Constraints = ""
1553
1554 let Uses = [CL] in {
1555 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
1556                  "sar{b}\t{%cl, $dst|$dst, CL}",
1557                  [(set GR8:$dst, (sra GR8:$src1, CL))]>;
1558 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
1559                  "sar{w}\t{%cl, $dst|$dst, CL}",
1560                  [(set GR16:$dst, (sra GR16:$src1, CL))]>, OpSize;
1561 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
1562                  "sar{l}\t{%cl, $dst|$dst, CL}",
1563                  [(set GR32:$dst, (sra GR32:$src1, CL))]>;
1564 }
1565
1566 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1567                    "sar{b}\t{$src2, $dst|$dst, $src2}",
1568                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
1569 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1570                    "sar{w}\t{$src2, $dst|$dst, $src2}",
1571                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
1572                    OpSize;
1573 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1574                    "sar{l}\t{$src2, $dst|$dst, $src2}",
1575                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
1576
1577 // Shift by 1
1578 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
1579                  "sar{b}\t$dst",
1580                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
1581 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
1582                  "sar{w}\t$dst",
1583                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
1584 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
1585                  "sar{l}\t$dst",
1586                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
1587
1588 let Constraints = "" in {
1589   let Uses = [CL] in {
1590   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
1591                    "sar{b}\t{%cl, $dst|$dst, CL}",
1592                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
1593   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
1594                    "sar{w}\t{%cl, $dst|$dst, CL}",
1595                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1596   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
1597                    "sar{l}\t{%cl, $dst|$dst, CL}",
1598                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
1599   }
1600   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
1601                      "sar{b}\t{$src, $dst|$dst, $src}",
1602                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1603   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
1604                      "sar{w}\t{$src, $dst|$dst, $src}",
1605                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1606                      OpSize;
1607   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
1608                      "sar{l}\t{$src, $dst|$dst, $src}",
1609                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1610
1611   // Shift by 1
1612   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
1613                    "sar{b}\t$dst",
1614                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1615   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
1616                    "sar{w}\t$dst",
1617                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1618                      OpSize;
1619   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
1620                    "sar{l}\t$dst",
1621                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1622 } // Constraints = ""
1623
1624 // Rotate instructions
1625
1626 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
1627                "rcl{b}\t{1, $dst|$dst, 1}", []>;
1628 let Uses = [CL] in {
1629 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
1630                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
1631 }
1632 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
1633                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
1634   
1635 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
1636                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
1637 let Uses = [CL] in {
1638 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
1639                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
1640 }
1641 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
1642                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
1643
1644 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
1645                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
1646 let Uses = [CL] in {
1647 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
1648                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
1649 }
1650 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
1651                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
1652                   
1653 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
1654                "rcr{b}\t{1, $dst|$dst, 1}", []>;
1655 let Uses = [CL] in {
1656 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
1657                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
1658 }
1659 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
1660                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
1661   
1662 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
1663                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
1664 let Uses = [CL] in {
1665 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
1666                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
1667 }
1668 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
1669                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
1670
1671 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
1672                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
1673 let Uses = [CL] in {
1674 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
1675                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
1676 }
1677 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
1678                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
1679
1680 let Constraints = "" in {
1681 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
1682                "rcl{b}\t{1, $dst|$dst, 1}", []>;
1683 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
1684                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
1685 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
1686                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
1687 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
1688                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
1689 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
1690                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
1691 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
1692                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
1693 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
1694                "rcr{b}\t{1, $dst|$dst, 1}", []>;
1695 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
1696                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
1697 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
1698                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
1699 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
1700                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
1701 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
1702                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
1703 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
1704                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
1705
1706 let Uses = [CL] in {
1707 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
1708                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
1709 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
1710                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
1711 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
1712                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
1713 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
1714                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
1715 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
1716                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
1717 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
1718                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
1719 }
1720 } // Constraints = ""
1721
1722 // FIXME: provide shorter instructions when imm8 == 1
1723 let Uses = [CL] in {
1724 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1725                  "rol{b}\t{%cl, $dst|$dst, CL}",
1726                  [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
1727 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
1728                  "rol{w}\t{%cl, $dst|$dst, CL}",
1729                  [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize;
1730 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
1731                  "rol{l}\t{%cl, $dst|$dst, CL}",
1732                  [(set GR32:$dst, (rotl GR32:$src1, CL))]>;
1733 }
1734
1735 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1736                    "rol{b}\t{$src2, $dst|$dst, $src2}",
1737                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
1738 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1739                    "rol{w}\t{$src2, $dst|$dst, $src2}",
1740                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, 
1741                    OpSize;
1742 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1743                    "rol{l}\t{$src2, $dst|$dst, $src2}",
1744                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
1745
1746 // Rotate by 1
1747 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1748                  "rol{b}\t$dst",
1749                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
1750 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
1751                  "rol{w}\t$dst",
1752                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
1753 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
1754                  "rol{l}\t$dst",
1755                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
1756
1757 let Constraints = "" in {
1758   let Uses = [CL] in {
1759   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
1760                    "rol{b}\t{%cl, $dst|$dst, CL}",
1761                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
1762   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
1763                    "rol{w}\t{%cl, $dst|$dst, CL}",
1764                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1765   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
1766                    "rol{l}\t{%cl, $dst|$dst, CL}",
1767                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
1768   }
1769   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
1770                      "rol{b}\t{$src, $dst|$dst, $src}",
1771                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1772   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
1773                      "rol{w}\t{$src, $dst|$dst, $src}",
1774                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1775                      OpSize;
1776   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
1777                      "rol{l}\t{$src, $dst|$dst, $src}",
1778                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1779
1780   // Rotate by 1
1781   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
1782                    "rol{b}\t$dst",
1783                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1784   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
1785                    "rol{w}\t$dst",
1786                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1787                      OpSize;
1788   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
1789                    "rol{l}\t$dst",
1790                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1791 } // Constraints = ""
1792
1793 let Uses = [CL] in {
1794 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1795                  "ror{b}\t{%cl, $dst|$dst, CL}",
1796                  [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
1797 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
1798                  "ror{w}\t{%cl, $dst|$dst, CL}",
1799                  [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize;
1800 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
1801                  "ror{l}\t{%cl, $dst|$dst, CL}",
1802                  [(set GR32:$dst, (rotr GR32:$src1, CL))]>;
1803 }
1804
1805 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1806                    "ror{b}\t{$src2, $dst|$dst, $src2}",
1807                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
1808 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1809                    "ror{w}\t{$src2, $dst|$dst, $src2}",
1810                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, 
1811                    OpSize;
1812 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1813                    "ror{l}\t{$src2, $dst|$dst, $src2}",
1814                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
1815
1816 // Rotate by 1
1817 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1818                  "ror{b}\t$dst",
1819                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
1820 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
1821                  "ror{w}\t$dst",
1822                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
1823 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
1824                  "ror{l}\t$dst",
1825                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
1826
1827 let Constraints = "" in {
1828   let Uses = [CL] in {
1829   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
1830                    "ror{b}\t{%cl, $dst|$dst, CL}",
1831                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
1832   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
1833                    "ror{w}\t{%cl, $dst|$dst, CL}",
1834                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1835   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
1836                    "ror{l}\t{%cl, $dst|$dst, CL}",
1837                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
1838   }
1839   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
1840                      "ror{b}\t{$src, $dst|$dst, $src}",
1841                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1842   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
1843                      "ror{w}\t{$src, $dst|$dst, $src}",
1844                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1845                      OpSize;
1846   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
1847                      "ror{l}\t{$src, $dst|$dst, $src}",
1848                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1849
1850   // Rotate by 1
1851   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
1852                    "ror{b}\t$dst",
1853                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1854   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
1855                    "ror{w}\t$dst",
1856                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1857                      OpSize;
1858   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
1859                    "ror{l}\t$dst",
1860                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1861 } // Constraints = ""
1862
1863
1864 // Double shift instructions (generalizations of rotate)
1865 let Uses = [CL] in {
1866 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
1867                    (ins GR32:$src1, GR32:$src2),
1868                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1869                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
1870 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
1871                    (ins GR32:$src1, GR32:$src2),
1872                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1873                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
1874 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
1875                    (ins GR16:$src1, GR16:$src2),
1876                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1877                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
1878                    TB, OpSize;
1879 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
1880                    (ins GR16:$src1, GR16:$src2),
1881                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1882                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
1883                    TB, OpSize;
1884 }
1885
1886 let isCommutable = 1 in {  // These instructions commute to each other.
1887 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
1888                      (outs GR32:$dst), 
1889                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
1890                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1891                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
1892                                       (i8 imm:$src3)))]>,
1893                  TB;
1894 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
1895                      (outs GR32:$dst), 
1896                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
1897                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1898                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
1899                                       (i8 imm:$src3)))]>,
1900                  TB;
1901 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
1902                      (outs GR16:$dst), 
1903                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
1904                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1905                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
1906                                       (i8 imm:$src3)))]>,
1907                      TB, OpSize;
1908 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
1909                      (outs GR16:$dst), 
1910                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
1911                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1912                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
1913                                       (i8 imm:$src3)))]>,
1914                      TB, OpSize;
1915 }
1916
1917 let Constraints = "" in {
1918   let Uses = [CL] in {
1919   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1920                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1921                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
1922                        addr:$dst)]>, TB;
1923   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
1924                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1925                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
1926                       addr:$dst)]>, TB;
1927   }
1928   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
1929                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
1930                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1931                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
1932                                         (i8 imm:$src3)), addr:$dst)]>,
1933                       TB;
1934   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
1935                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
1936                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1937                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
1938                                          (i8 imm:$src3)), addr:$dst)]>,
1939                        TB;
1940
1941   let Uses = [CL] in {
1942   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1943                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1944                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
1945                        addr:$dst)]>, TB, OpSize;
1946   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
1947                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
1948                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
1949                       addr:$dst)]>, TB, OpSize;
1950   }
1951   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
1952                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
1953                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1954                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
1955                                         (i8 imm:$src3)), addr:$dst)]>,
1956                       TB, OpSize;
1957   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
1958                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
1959                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1960                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
1961                                         (i8 imm:$src3)), addr:$dst)]>,
1962                        TB, OpSize;
1963 } // Constraints = ""
1964 } // Defs = [EFLAGS]
1965
1966
1967 // Arithmetic.
1968 let Defs = [EFLAGS] in {
1969 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
1970 // Register-Register Addition
1971 def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
1972                                     (ins GR8 :$src1, GR8 :$src2),
1973                   "add{b}\t{$src2, $dst|$dst, $src2}",
1974                   [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
1975
1976 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1977 // Register-Register Addition
1978 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
1979                                    (ins GR16:$src1, GR16:$src2),
1980                  "add{w}\t{$src2, $dst|$dst, $src2}",
1981                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
1982                                                        GR16:$src2))]>, OpSize;
1983 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
1984                                    (ins GR32:$src1, GR32:$src2),
1985                  "add{l}\t{$src2, $dst|$dst, $src2}",
1986                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
1987                                                        GR32:$src2))]>;
1988 } // end isConvertibleToThreeAddress
1989 } // end isCommutable
1990
1991 // These are alternate spellings for use by the disassembler, we mark them as
1992 // code gen only to ensure they aren't matched by the assembler.
1993 let isCodeGenOnly = 1 in {
1994   def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1995                    "add{b}\t{$src2, $dst|$dst, $src2}", []>;
1996   def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
1997                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1998   def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
1999                     "add{l}\t{$src2, $dst|$dst, $src2}", []>;
2000 }
2001
2002 // Register-Memory Addition
2003 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2004                                   (ins GR8 :$src1, i8mem :$src2),
2005                  "add{b}\t{$src2, $dst|$dst, $src2}",
2006                  [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
2007                                                       (load addr:$src2)))]>;
2008 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
2009                                   (ins GR16:$src1, i16mem:$src2),
2010                  "add{w}\t{$src2, $dst|$dst, $src2}",
2011                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2012                                                   (load addr:$src2)))]>, OpSize;
2013 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
2014                                   (ins GR32:$src1, i32mem:$src2),
2015                  "add{l}\t{$src2, $dst|$dst, $src2}",
2016                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2017                                                        (load addr:$src2)))]>;
2018                   
2019 // Register-Integer Addition
2020 def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2021                     "add{b}\t{$src2, $dst|$dst, $src2}",
2022                     [(set GR8:$dst, EFLAGS,
2023                           (X86add_flag GR8:$src1, imm:$src2))]>;
2024
2025 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2026 // Register-Integer Addition
2027 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
2028                                  (ins GR16:$src1, i16imm:$src2),
2029                     "add{w}\t{$src2, $dst|$dst, $src2}",
2030                     [(set GR16:$dst, EFLAGS,
2031                           (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
2032 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
2033                                  (ins GR32:$src1, i32imm:$src2),
2034                     "add{l}\t{$src2, $dst|$dst, $src2}",
2035                     [(set GR32:$dst, EFLAGS, 
2036                           (X86add_flag GR32:$src1, imm:$src2))]>;
2037 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2038                                 (ins GR16:$src1, i16i8imm:$src2),
2039                    "add{w}\t{$src2, $dst|$dst, $src2}",
2040                    [(set GR16:$dst, EFLAGS,
2041                          (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2042 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2043                                 (ins GR32:$src1, i32i8imm:$src2),
2044                    "add{l}\t{$src2, $dst|$dst, $src2}",
2045                    [(set GR32:$dst, EFLAGS,
2046                          (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
2047 }
2048
2049 let Constraints = "" in {
2050   // Memory-Register Addition
2051   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2052                    "add{b}\t{$src2, $dst|$dst, $src2}",
2053                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2054                     (implicit EFLAGS)]>;
2055   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2056                    "add{w}\t{$src2, $dst|$dst, $src2}",
2057                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2058                     (implicit EFLAGS)]>, OpSize;
2059   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2060                    "add{l}\t{$src2, $dst|$dst, $src2}",
2061                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2062                     (implicit EFLAGS)]>;
2063   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
2064                      "add{b}\t{$src2, $dst|$dst, $src2}",
2065                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2066                     (implicit EFLAGS)]>;
2067   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
2068                       "add{w}\t{$src2, $dst|$dst, $src2}",
2069                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2070                    (implicit EFLAGS)]>, OpSize;
2071   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
2072                       "add{l}\t{$src2, $dst|$dst, $src2}",
2073                       [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2074                        (implicit EFLAGS)]>;
2075   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2076                      "add{w}\t{$src2, $dst|$dst, $src2}",
2077                      [(store (add (load addr:$dst), i16immSExt8:$src2),
2078                                   addr:$dst),
2079                       (implicit EFLAGS)]>, OpSize;
2080   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2081                      "add{l}\t{$src2, $dst|$dst, $src2}",
2082                   [(store (add (load addr:$dst), i32immSExt8:$src2),
2083                                addr:$dst),
2084                    (implicit EFLAGS)]>;
2085
2086   // addition to rAX
2087   def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
2088                    "add{b}\t{$src, %al|%al, $src}", []>;
2089   def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
2090                       "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2091   def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
2092                       "add{l}\t{$src, %eax|%eax, $src}", []>;
2093 } // Constraints = ""
2094
2095 let Uses = [EFLAGS] in {
2096 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
2097 def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2098                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2099                  [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
2100 def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
2101                                    (ins GR16:$src1, GR16:$src2),
2102                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2103                  [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
2104 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
2105                                    (ins GR32:$src1, GR32:$src2),
2106                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2107                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
2108 }
2109
2110 let isCodeGenOnly = 1 in {
2111 def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2112                  "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
2113 def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst), 
2114                     (ins GR16:$src1, GR16:$src2),
2115                     "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2116 def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst), 
2117                     (ins GR32:$src1, GR32:$src2),
2118                     "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
2119 }
2120
2121 def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
2122                                    (ins GR8:$src1, i8mem:$src2),
2123                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2124                  [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
2125 def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
2126                                    (ins GR16:$src1, i16mem:$src2),
2127                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2128                  [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
2129                  OpSize;
2130 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
2131                                    (ins GR32:$src1, i32mem:$src2),
2132                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2133                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2134 def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2135                     "adc{b}\t{$src2, $dst|$dst, $src2}",
2136                  [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
2137 def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
2138                                  (ins GR16:$src1, i16imm:$src2),
2139                     "adc{w}\t{$src2, $dst|$dst, $src2}",
2140                  [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
2141 def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2142                                 (ins GR16:$src1, i16i8imm:$src2),
2143                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2144                  [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2145                  OpSize;
2146 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
2147                                  (ins GR32:$src1, i32imm:$src2),
2148                     "adc{l}\t{$src2, $dst|$dst, $src2}",
2149                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
2150 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2151                                 (ins GR32:$src1, i32i8imm:$src2),
2152                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2153                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
2154
2155 let Constraints = "" in {
2156   def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2157                    "adc{b}\t{$src2, $dst|$dst, $src2}",
2158                    [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2159   def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2160                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2161                    [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2162                    OpSize;
2163   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2164                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2165                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2166   def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
2167                       "adc{b}\t{$src2, $dst|$dst, $src2}",
2168                   [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2169   def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
2170                       "adc{w}\t{$src2, $dst|$dst, $src2}",
2171                   [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2172                   OpSize;
2173   def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2174                      "adc{w}\t{$src2, $dst|$dst, $src2}",
2175                [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2176                OpSize;
2177   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
2178                       "adc{l}\t{$src2, $dst|$dst, $src2}",
2179                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2180   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2181                      "adc{l}\t{$src2, $dst|$dst, $src2}",
2182                [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2183
2184   def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
2185                    "adc{b}\t{$src, %al|%al, $src}", []>;
2186   def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
2187                       "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2188   def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
2189                       "adc{l}\t{$src, %eax|%eax, $src}", []>;
2190 } // Constraints = ""
2191 } // Uses = [EFLAGS]
2192
2193 // Register-Register Subtraction
2194 def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2195                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2196                 [(set GR8:$dst, EFLAGS,
2197                       (X86sub_flag GR8:$src1, GR8:$src2))]>;
2198 def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2199                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2200                 [(set GR16:$dst, EFLAGS,
2201                       (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
2202 def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2203                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2204                 [(set GR32:$dst, EFLAGS,
2205                       (X86sub_flag GR32:$src1, GR32:$src2))]>;
2206
2207 let isCodeGenOnly = 1 in {
2208 def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2209                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
2210 def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst), 
2211                     (ins GR16:$src1, GR16:$src2),
2212                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2213 def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst), 
2214                     (ins GR32:$src1, GR32:$src2),
2215                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
2216 }
2217
2218 // Register-Memory Subtraction
2219 def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
2220                                  (ins GR8 :$src1, i8mem :$src2),
2221                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2222                 [(set GR8:$dst, EFLAGS,
2223                       (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
2224 def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
2225                                  (ins GR16:$src1, i16mem:$src2),
2226                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2227                 [(set GR16:$dst, EFLAGS,
2228                       (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
2229 def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
2230                                  (ins GR32:$src1, i32mem:$src2),
2231                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2232                 [(set GR32:$dst, EFLAGS,
2233                       (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
2234
2235 // Register-Integer Subtraction
2236 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
2237                                  (ins GR8:$src1, i8imm:$src2),
2238                     "sub{b}\t{$src2, $dst|$dst, $src2}",
2239                     [(set GR8:$dst, EFLAGS,
2240                           (X86sub_flag GR8:$src1, imm:$src2))]>;
2241 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
2242                                  (ins GR16:$src1, i16imm:$src2),
2243                     "sub{w}\t{$src2, $dst|$dst, $src2}",
2244                     [(set GR16:$dst, EFLAGS,
2245                           (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
2246 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
2247                                  (ins GR32:$src1, i32imm:$src2),
2248                     "sub{l}\t{$src2, $dst|$dst, $src2}",
2249                     [(set GR32:$dst, EFLAGS,
2250                           (X86sub_flag GR32:$src1, imm:$src2))]>;
2251 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
2252                                 (ins GR16:$src1, i16i8imm:$src2),
2253                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2254                    [(set GR16:$dst, EFLAGS,
2255                          (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2256 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
2257                                 (ins GR32:$src1, i32i8imm:$src2),
2258                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2259                    [(set GR32:$dst, EFLAGS,
2260                          (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
2261
2262 let Constraints = "" in {
2263   // Memory-Register Subtraction
2264   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
2265                    "sub{b}\t{$src2, $dst|$dst, $src2}",
2266                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
2267                     (implicit EFLAGS)]>;
2268   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2269                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2270                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
2271                     (implicit EFLAGS)]>, OpSize;
2272   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2273                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2274                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
2275                     (implicit EFLAGS)]>;
2276
2277   // Memory-Integer Subtraction
2278   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
2279                      "sub{b}\t{$src2, $dst|$dst, $src2}",
2280                      [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
2281                       (implicit EFLAGS)]>;
2282   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2283                       "sub{w}\t{$src2, $dst|$dst, $src2}",
2284                       [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
2285                        (implicit EFLAGS)]>, OpSize;
2286   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2287                       "sub{l}\t{$src2, $dst|$dst, $src2}",
2288                       [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
2289                        (implicit EFLAGS)]>;
2290   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2291                      "sub{w}\t{$src2, $dst|$dst, $src2}",
2292                      [(store (sub (load addr:$dst), i16immSExt8:$src2),
2293                              addr:$dst),
2294                       (implicit EFLAGS)]>, OpSize;
2295   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2296                      "sub{l}\t{$src2, $dst|$dst, $src2}",
2297                      [(store (sub (load addr:$dst), i32immSExt8:$src2),
2298                              addr:$dst),
2299                       (implicit EFLAGS)]>;
2300                       
2301   def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
2302                    "sub{b}\t{$src, %al|%al, $src}", []>;
2303   def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
2304                       "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2305   def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
2306                       "sub{l}\t{$src, %eax|%eax, $src}", []>;
2307 } // Constraints = ""
2308
2309 let Uses = [EFLAGS] in {
2310 def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
2311                                      (ins GR8:$src1, GR8:$src2),
2312                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
2313                  [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
2314 def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
2315                                      (ins GR16:$src1, GR16:$src2),
2316                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
2317                  [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
2318 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
2319                                       (ins GR32:$src1, GR32:$src2),
2320                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
2321                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
2322
2323 let Constraints = "" in {
2324   def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
2325                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
2326                    [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
2327   def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
2328                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2329                    [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
2330                    OpSize;
2331   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2332                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2333                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
2334   def SBB8mi  : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
2335                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2336                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2337   def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2338                       "sbb{w}\t{$src2, $dst|$dst, $src2}",
2339                   [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2340                   OpSize;
2341   def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2342                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
2343                [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2344                OpSize;
2345   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2346                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
2347                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2348   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
2349                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
2350                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2351                
2352   def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
2353                    "sbb{b}\t{$src, %al|%al, $src}", []>;
2354   def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
2355                       "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2356   def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
2357                       "sbb{l}\t{$src, %eax|%eax, $src}", []>;
2358 } // Constraints = ""
2359
2360 let isCodeGenOnly = 1 in {
2361 def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2362                    "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
2363 def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst), 
2364                     (ins GR16:$src1, GR16:$src2),
2365                     "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2366 def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst), 
2367                     (ins GR32:$src1, GR32:$src2),
2368                     "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
2369 }
2370
2371 def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
2372                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2373                     [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
2374 def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
2375                                   (ins GR16:$src1, i16mem:$src2),
2376                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2377                     [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
2378                     OpSize;
2379 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
2380                                   (ins GR32:$src1, i32mem:$src2),
2381                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2382                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
2383 def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2384                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2385                     [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
2386 def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
2387                                  (ins GR16:$src1, i16imm:$src2),
2388                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2389                     [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
2390 def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
2391                                 (ins GR16:$src1, i16i8imm:$src2),
2392                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2393                    [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
2394                    OpSize;
2395 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
2396                                  (ins GR32:$src1, i32imm:$src2),
2397                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2398                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
2399 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
2400                                 (ins GR32:$src1, i32i8imm:$src2),
2401                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2402                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
2403 } // Uses = [EFLAGS]
2404 } // Defs = [EFLAGS]
2405
2406 let Defs = [EFLAGS] in {
2407 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
2408 // Register-Register Signed Integer Multiply
2409 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2410                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2411                  [(set GR16:$dst, EFLAGS,
2412                        (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
2413 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2414                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2415                  [(set GR32:$dst, EFLAGS,
2416                        (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
2417 }
2418
2419 // Register-Memory Signed Integer Multiply
2420 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
2421                                   (ins GR16:$src1, i16mem:$src2),
2422                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2423                  [(set GR16:$dst, EFLAGS,
2424                        (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
2425                TB, OpSize;
2426 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), 
2427                  (ins GR32:$src1, i32mem:$src2),
2428                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2429                  [(set GR32:$dst, EFLAGS,
2430                        (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
2431 } // Defs = [EFLAGS]
2432 } // end Two Address instructions
2433
2434 // Suprisingly enough, these are not two address instructions!
2435 let Defs = [EFLAGS] in {
2436 // Register-Integer Signed Integer Multiply
2437 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
2438                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
2439                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2440                       [(set GR16:$dst, EFLAGS, 
2441                             (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
2442 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
2443                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2444                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2445                       [(set GR32:$dst, EFLAGS,
2446                             (X86smul_flag GR32:$src1, imm:$src2))]>;
2447 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
2448                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2449                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2450                      [(set GR16:$dst, EFLAGS,
2451                            (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
2452                  OpSize;
2453 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
2454                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2455                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2456                      [(set GR32:$dst, EFLAGS,
2457                            (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
2458
2459 // Memory-Integer Signed Integer Multiply
2460 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                     // GR16 = [mem16]*I16
2461                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
2462                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2463                       [(set GR16:$dst, EFLAGS,
2464                             (X86smul_flag (load addr:$src1), imm:$src2))]>,
2465                  OpSize;
2466 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                     // GR32 = [mem32]*I32
2467                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
2468                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2469                       [(set GR32:$dst, EFLAGS,
2470                             (X86smul_flag (load addr:$src1), imm:$src2))]>;
2471 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
2472                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
2473                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2474                      [(set GR16:$dst, EFLAGS,
2475                            (X86smul_flag (load addr:$src1),
2476                                          i16immSExt8:$src2))]>, OpSize;
2477 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
2478                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
2479                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2480                      [(set GR32:$dst, EFLAGS,
2481                            (X86smul_flag (load addr:$src1),
2482                                          i32immSExt8:$src2))]>;
2483 } // Defs = [EFLAGS]
2484
2485 //===----------------------------------------------------------------------===//
2486 // Test instructions are just like AND, except they don't generate a result.
2487 //
2488 let Defs = [EFLAGS] in {
2489 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
2490 def TEST8rr  : I<0x84, MRMSrcReg, (outs),  (ins GR8:$src1, GR8:$src2),
2491                      "test{b}\t{$src2, $src1|$src1, $src2}",
2492                      [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
2493 def TEST16rr : I<0x85, MRMSrcReg, (outs),  (ins GR16:$src1, GR16:$src2),
2494                      "test{w}\t{$src2, $src1|$src1, $src2}",
2495                      [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
2496                       0))]>,
2497                  OpSize;
2498 def TEST32rr : I<0x85, MRMSrcReg, (outs),  (ins GR32:$src1, GR32:$src2),
2499                      "test{l}\t{$src2, $src1|$src1, $src2}",
2500                      [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
2501                       0))]>;
2502 }
2503
2504 def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
2505                    "test{b}\t{$src, %al|%al, $src}", []>;
2506 def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
2507                      "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2508 def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
2509                      "test{l}\t{$src, %eax|%eax, $src}", []>;
2510
2511 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
2512                      "test{b}\t{$src2, $src1|$src1, $src2}",
2513                      [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
2514                        0))]>;
2515 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
2516                      "test{w}\t{$src2, $src1|$src1, $src2}",
2517                      [(set EFLAGS, (X86cmp (and GR16:$src1,
2518                                          (loadi16 addr:$src2)), 0))]>, OpSize;
2519 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
2520                      "test{l}\t{$src2, $src1|$src1, $src2}",
2521                      [(set EFLAGS, (X86cmp (and GR32:$src1,
2522                                                 (loadi32 addr:$src2)), 0))]>;
2523
2524 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
2525                     (outs),  (ins GR8:$src1, i8imm:$src2),
2526                     "test{b}\t{$src2, $src1|$src1, $src2}",
2527                     [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
2528 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
2529                     (outs),  (ins GR16:$src1, i16imm:$src2),
2530                     "test{w}\t{$src2, $src1|$src1, $src2}",
2531                     [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
2532                     OpSize;
2533 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
2534                     (outs),  (ins GR32:$src1, i32imm:$src2),
2535                     "test{l}\t{$src2, $src1|$src1, $src2}",
2536                     [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
2537
2538 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
2539                     (outs), (ins i8mem:$src1, i8imm:$src2),
2540                     "test{b}\t{$src2, $src1|$src1, $src2}",
2541                     [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
2542                      0))]>;
2543 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
2544                     (outs), (ins i16mem:$src1, i16imm:$src2),
2545                     "test{w}\t{$src2, $src1|$src1, $src2}",
2546                     [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
2547                      0))]>, OpSize;
2548 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
2549                     (outs), (ins i32mem:$src1, i32imm:$src2),
2550                     "test{l}\t{$src2, $src1|$src1, $src2}",
2551                     [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
2552                      0))]>;
2553 } // Defs = [EFLAGS]
2554
2555
2556 // Condition code ops, incl. set if equal/not equal/...
2557 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
2558 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
2559 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
2560 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
2561
2562 // Integer comparisons
2563 let Defs = [EFLAGS] in {
2564 def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
2565                  "cmp{b}\t{$src, %al|%al, $src}", []>;
2566 def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
2567                     "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2568 def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
2569                     "cmp{l}\t{$src, %eax|%eax, $src}", []>;
2570
2571 def CMP8rr  : I<0x38, MRMDestReg,
2572                 (outs), (ins GR8 :$src1, GR8 :$src2),
2573                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2574                 [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
2575 def CMP16rr : I<0x39, MRMDestReg,
2576                 (outs), (ins GR16:$src1, GR16:$src2),
2577                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2578                 [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
2579 def CMP32rr : I<0x39, MRMDestReg,
2580                 (outs), (ins GR32:$src1, GR32:$src2),
2581                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2582                 [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
2583 def CMP8mr  : I<0x38, MRMDestMem,
2584                 (outs), (ins i8mem :$src1, GR8 :$src2),
2585                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2586                 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
2587 def CMP16mr : I<0x39, MRMDestMem,
2588                 (outs), (ins i16mem:$src1, GR16:$src2),
2589                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2590                 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
2591                  OpSize;
2592 def CMP32mr : I<0x39, MRMDestMem,
2593                 (outs), (ins i32mem:$src1, GR32:$src2),
2594                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2595                 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
2596 def CMP8rm  : I<0x3A, MRMSrcMem,
2597                 (outs), (ins GR8 :$src1, i8mem :$src2),
2598                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
2599                 [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
2600 def CMP16rm : I<0x3B, MRMSrcMem,
2601                 (outs), (ins GR16:$src1, i16mem:$src2),
2602                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
2603                 [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
2604                  OpSize;
2605 def CMP32rm : I<0x3B, MRMSrcMem,
2606                 (outs), (ins GR32:$src1, i32mem:$src2),
2607                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
2608                 [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
2609
2610 // These are alternate spellings for use by the disassembler, we mark them as
2611 // code gen only to ensure they aren't matched by the assembler.
2612 let isCodeGenOnly = 1 in {
2613   def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
2614                     "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
2615   def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
2616                      "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
2617   def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
2618                      "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
2619 }
2620
2621 def CMP8ri  : Ii8<0x80, MRM7r,
2622                   (outs), (ins GR8:$src1, i8imm:$src2),
2623                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
2624                   [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
2625 def CMP16ri : Ii16<0x81, MRM7r,
2626                    (outs), (ins GR16:$src1, i16imm:$src2),
2627                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2628                    [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
2629 def CMP32ri : Ii32<0x81, MRM7r,
2630                    (outs), (ins GR32:$src1, i32imm:$src2),
2631                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2632                    [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
2633 def CMP8mi  : Ii8 <0x80, MRM7m,
2634                    (outs), (ins i8mem :$src1, i8imm :$src2),
2635                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
2636                    [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
2637 def CMP16mi : Ii16<0x81, MRM7m,
2638                    (outs), (ins i16mem:$src1, i16imm:$src2),
2639                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2640                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
2641                    OpSize;
2642 def CMP32mi : Ii32<0x81, MRM7m,
2643                    (outs), (ins i32mem:$src1, i32imm:$src2),
2644                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2645                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
2646 def CMP16ri8 : Ii8<0x83, MRM7r,
2647                    (outs), (ins GR16:$src1, i16i8imm:$src2),
2648                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2649                    [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
2650                     OpSize;
2651 def CMP16mi8 : Ii8<0x83, MRM7m,
2652                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
2653                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
2654                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
2655                                          i16immSExt8:$src2))]>, OpSize;
2656 def CMP32mi8 : Ii8<0x83, MRM7m,
2657                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
2658                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2659                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
2660                                          i32immSExt8:$src2))]>;
2661 def CMP32ri8 : Ii8<0x83, MRM7r,
2662                    (outs), (ins GR32:$src1, i32i8imm:$src2),
2663                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
2664                    [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
2665 } // Defs = [EFLAGS]
2666
2667 // Bit tests.
2668 // TODO: BTC, BTR, and BTS
2669 let Defs = [EFLAGS] in {
2670 def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
2671                "bt{w}\t{$src2, $src1|$src1, $src2}",
2672                [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
2673 def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
2674                "bt{l}\t{$src2, $src1|$src1, $src2}",
2675                [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
2676
2677 // Unlike with the register+register form, the memory+register form of the
2678 // bt instruction does not ignore the high bits of the index. From ISel's
2679 // perspective, this is pretty bizarre. Make these instructions disassembly
2680 // only for now.
2681
2682 def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
2683                "bt{w}\t{$src2, $src1|$src1, $src2}", 
2684 //               [(X86bt (loadi16 addr:$src1), GR16:$src2),
2685 //                (implicit EFLAGS)]
2686                []
2687                >, OpSize, TB, Requires<[FastBTMem]>;
2688 def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
2689                "bt{l}\t{$src2, $src1|$src1, $src2}", 
2690 //               [(X86bt (loadi32 addr:$src1), GR32:$src2),
2691 //                (implicit EFLAGS)]
2692                []
2693                >, TB, Requires<[FastBTMem]>;
2694
2695 def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
2696                 "bt{w}\t{$src2, $src1|$src1, $src2}",
2697                 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
2698                 OpSize, TB;
2699 def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
2700                 "bt{l}\t{$src2, $src1|$src1, $src2}",
2701                 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
2702 // Note that these instructions don't need FastBTMem because that
2703 // only applies when the other operand is in a register. When it's
2704 // an immediate, bt is still fast.
2705 def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
2706                 "bt{w}\t{$src2, $src1|$src1, $src2}",
2707                 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
2708                  ]>, OpSize, TB;
2709 def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
2710                 "bt{l}\t{$src2, $src1|$src1, $src2}",
2711                 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
2712                  ]>, TB;
2713
2714 def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
2715                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2716 def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
2717                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2718 def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
2719                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2720 def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
2721                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2722 def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
2723                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2724 def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
2725                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2726 def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
2727                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2728 def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
2729                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2730
2731 def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
2732                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2733 def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
2734                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2735 def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
2736                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2737 def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
2738                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2739 def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
2740                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2741 def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
2742                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2743 def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
2744                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2745 def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
2746                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2747
2748 def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
2749                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2750 def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
2751                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2752 def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
2753                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2754 def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
2755                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2756 def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
2757                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2758 def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
2759                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2760 def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
2761                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
2762 def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
2763                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
2764 } // Defs = [EFLAGS]
2765
2766 // Sign/Zero extenders
2767 // Use movsbl intead of movsbw; we don't care about the high 16 bits
2768 // of the register here. This has a smaller encoding and avoids a
2769 // partial-register update.  Actual movsbw included for the disassembler.
2770 def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
2771                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2772 def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
2773                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2774 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
2775                    "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
2776 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
2777                    "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
2778 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
2779                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
2780                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
2781 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
2782                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
2783                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
2784 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
2785                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
2786                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
2787 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
2788                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
2789                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
2790
2791 // Use movzbl intead of movzbw; we don't care about the high 16 bits
2792 // of the register here. This has a smaller encoding and avoids a
2793 // partial-register update.  Actual movzbw included for the disassembler.
2794 def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
2795                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2796 def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
2797                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;  
2798 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
2799                    "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
2800 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
2801                    "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
2802 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
2803                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
2804                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
2805 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
2806                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
2807                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
2808 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
2809                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
2810                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
2811 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
2812                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
2813                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
2814
2815 // These are the same as the regular MOVZX32rr8 and MOVZX32rm8
2816 // except that they use GR32_NOREX for the output operand register class
2817 // instead of GR32. This allows them to operate on h registers on x86-64.
2818 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
2819                          (outs GR32_NOREX:$dst), (ins GR8:$src),
2820                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
2821                          []>, TB;
2822 let mayLoad = 1 in
2823 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
2824                          (outs GR32_NOREX:$dst), (ins i8mem:$src),
2825                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
2826                          []>, TB;
2827
2828 let neverHasSideEffects = 1 in {
2829   let Defs = [AX], Uses = [AL] in
2830   def CBW : I<0x98, RawFrm, (outs), (ins),
2831               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
2832   let Defs = [EAX], Uses = [AX] in
2833   def CWDE : I<0x98, RawFrm, (outs), (ins),
2834               "{cwtl|cwde}", []>;   // EAX = signext(AX)
2835
2836   let Defs = [AX,DX], Uses = [AX] in
2837   def CWD : I<0x99, RawFrm, (outs), (ins),
2838               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
2839   let Defs = [EAX,EDX], Uses = [EAX] in
2840   def CDQ : I<0x99, RawFrm, (outs), (ins),
2841               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
2842 }
2843
2844
2845
2846 //===----------------------------------------------------------------------===//
2847 // Atomic support
2848 //
2849
2850
2851 // Atomic swap. These are just normal xchg instructions. But since a memory
2852 // operand is referenced, the atomicity is ensured.
2853 let Constraints = "$val = $dst" in {
2854 def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
2855                "xchg{b}\t{$val, $ptr|$ptr, $val}", 
2856                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
2857 def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), 
2858                  (ins GR16:$val, i16mem:$ptr),
2859                "xchg{w}\t{$val, $ptr|$ptr, $val}", 
2860                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
2861                 OpSize;
2862 def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), 
2863                  (ins GR32:$val, i32mem:$ptr),
2864                "xchg{l}\t{$val, $ptr|$ptr, $val}", 
2865                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
2866 def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), 
2867                   (ins GR64:$val,i64mem:$ptr),
2868                   "xchg{q}\t{$val, $ptr|$ptr, $val}", 
2869                   [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
2870
2871 def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
2872                 "xchg{b}\t{$val, $src|$src, $val}", []>;
2873 def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
2874                  "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
2875 def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
2876                  "xchg{l}\t{$val, $src|$src, $val}", []>;
2877 def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
2878                   "xchg{q}\t{$val, $src|$src, $val}", []>;
2879 }
2880
2881 def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
2882                   "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2883 def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
2884                   "xchg{l}\t{$src, %eax|%eax, $src}", []>;
2885 def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
2886                   "xchg{q}\t{$src, %rax|%rax, $src}", []>;
2887
2888
2889
2890 def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
2891                 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
2892 def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
2893                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2894 def XADD32rr  : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
2895                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
2896 def XADD64rr  : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
2897                    "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
2898
2899 let mayLoad = 1, mayStore = 1 in {
2900 def XADD8rm   : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
2901                  "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
2902 def XADD16rm  : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
2903                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2904 def XADD32rm  : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2905                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
2906 def XADD64rm  : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
2907                    "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
2908
2909 }
2910
2911 def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
2912                    "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
2913 def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
2914                     "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2915 def CMPXCHG32rr  : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
2916                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
2917 def CMPXCHG64rr  : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
2918                       "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
2919
2920 let mayLoad = 1, mayStore = 1 in {
2921 def CMPXCHG8rm   : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
2922                      "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
2923 def CMPXCHG16rm  : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
2924                      "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
2925 def CMPXCHG32rm  : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2926                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
2927 def CMPXCHG64rm  : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
2928                       "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
2929 }
2930
2931 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
2932 def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
2933                   "cmpxchg8b\t$dst", []>, TB;
2934
2935 let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
2936 def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
2937                     "cmpxchg16b\t$dst", []>, TB;
2938
2939
2940
2941 // Lock instruction prefix
2942 def LOCK_PREFIX : I<0xF0, RawFrm, (outs),  (ins), "lock", []>;
2943
2944 // Repeat string operation instruction prefixes
2945 // These uses the DF flag in the EFLAGS register to inc or dec ECX
2946 let Defs = [ECX], Uses = [ECX,EFLAGS] in {
2947 // Repeat (used with INS, OUTS, MOVS, LODS and STOS)
2948 def REP_PREFIX : I<0xF3, RawFrm, (outs),  (ins), "rep", []>;
2949 // Repeat while not equal (used with CMPS and SCAS)
2950 def REPNE_PREFIX : I<0xF2, RawFrm, (outs),  (ins), "repne", []>;
2951 }
2952
2953
2954 // String manipulation instructions
2955
2956 def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
2957 def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
2958 def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
2959 def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
2960
2961 def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
2962 def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
2963 def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
2964
2965
2966 // Flag instructions
2967 def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
2968 def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
2969 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
2970 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
2971 def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
2972 def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
2973 def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
2974
2975 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
2976
2977 // Table lookup instructions
2978 def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
2979
2980
2981
2982 //===----------------------------------------------------------------------===//
2983 // Subsystems.
2984 //===----------------------------------------------------------------------===//
2985
2986 // Floating Point Stack Support
2987 include "X86InstrFPStack.td"
2988
2989 // X86-64 Support
2990 include "X86Instr64bit.td"
2991
2992 include "X86InstrCMovSetCC.td"
2993 include "X86InstrControl.td"
2994
2995 // SIMD support (SSE, MMX and AVX)
2996 include "X86InstrFragmentsSIMD.td"
2997
2998 // FMA - Fused Multiply-Add support (requires FMA)
2999 include "X86InstrFMA.td"
3000
3001 // SSE, MMX and 3DNow! vector support.
3002 include "X86InstrSSE.td"
3003 include "X86InstrMMX.td"
3004 include "X86Instr3DNow.td"
3005
3006 include "X86InstrVMX.td"
3007
3008 // System instructions.
3009 include "X86InstrSystem.td"
3010
3011 // Compiler Pseudo Instructions and Pat Patterns
3012 include "X86InstrCompiler.td"
3013