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