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