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