Added XOR instructions for rAX and immediates of
[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 } // isTwoAddress = 0
1790
1791
1792 let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
1793   def XOR8rr   : I<0x30, MRMDestReg,
1794                    (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1795                    "xor{b}\t{$src2, $dst|$dst, $src2}",
1796                    [(set GR8:$dst, (xor GR8:$src1, GR8:$src2)),
1797                     (implicit EFLAGS)]>;
1798   def XOR16rr  : I<0x31, MRMDestReg, 
1799                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
1800                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1801                    [(set GR16:$dst, (xor GR16:$src1, GR16:$src2)),
1802                     (implicit EFLAGS)]>, OpSize;
1803   def XOR32rr  : I<0x31, MRMDestReg, 
1804                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
1805                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1806                    [(set GR32:$dst, (xor GR32:$src1, GR32:$src2)),
1807                     (implicit EFLAGS)]>;
1808 } // isCommutable = 1
1809
1810 def XOR8rm   : I<0x32, MRMSrcMem , 
1811                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
1812                  "xor{b}\t{$src2, $dst|$dst, $src2}",
1813                  [(set GR8:$dst, (xor GR8:$src1, (load addr:$src2))),
1814                   (implicit EFLAGS)]>;
1815 def XOR16rm  : I<0x33, MRMSrcMem , 
1816                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
1817                  "xor{w}\t{$src2, $dst|$dst, $src2}",
1818                  [(set GR16:$dst, (xor GR16:$src1, (load addr:$src2))),
1819                   (implicit EFLAGS)]>,
1820                  OpSize;
1821 def XOR32rm  : I<0x33, MRMSrcMem , 
1822                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
1823                  "xor{l}\t{$src2, $dst|$dst, $src2}",
1824                  [(set GR32:$dst, (xor GR32:$src1, (load addr:$src2))),
1825                   (implicit EFLAGS)]>;
1826
1827 def XOR8ri   : Ii8<0x80, MRM6r, 
1828                    (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
1829                    "xor{b}\t{$src2, $dst|$dst, $src2}",
1830                    [(set GR8:$dst, (xor GR8:$src1, imm:$src2)),
1831                     (implicit EFLAGS)]>;
1832 def XOR16ri  : Ii16<0x81, MRM6r, 
1833                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
1834                     "xor{w}\t{$src2, $dst|$dst, $src2}",
1835                     [(set GR16:$dst, (xor GR16:$src1, imm:$src2)),
1836                      (implicit EFLAGS)]>, OpSize;
1837 def XOR32ri  : Ii32<0x81, MRM6r, 
1838                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
1839                     "xor{l}\t{$src2, $dst|$dst, $src2}",
1840                     [(set GR32:$dst, (xor GR32:$src1, imm:$src2)),
1841                      (implicit EFLAGS)]>;
1842 def XOR16ri8 : Ii8<0x83, MRM6r, 
1843                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1844                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1845                    [(set GR16:$dst, (xor GR16:$src1, i16immSExt8:$src2)),
1846                     (implicit EFLAGS)]>,
1847                    OpSize;
1848 def XOR32ri8 : Ii8<0x83, MRM6r, 
1849                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1850                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1851                    [(set GR32:$dst, (xor GR32:$src1, i32immSExt8:$src2)),
1852                     (implicit EFLAGS)]>;
1853
1854 let isTwoAddress = 0 in {
1855   def XOR8mr   : I<0x30, MRMDestMem,
1856                    (outs), (ins i8mem :$dst, GR8 :$src),
1857                    "xor{b}\t{$src, $dst|$dst, $src}",
1858                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
1859                     (implicit EFLAGS)]>;
1860   def XOR16mr  : I<0x31, MRMDestMem,
1861                    (outs), (ins i16mem:$dst, GR16:$src),
1862                    "xor{w}\t{$src, $dst|$dst, $src}",
1863                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
1864                     (implicit EFLAGS)]>,
1865                    OpSize;
1866   def XOR32mr  : I<0x31, MRMDestMem,
1867                    (outs), (ins i32mem:$dst, GR32:$src),
1868                    "xor{l}\t{$src, $dst|$dst, $src}",
1869                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
1870                     (implicit EFLAGS)]>;
1871   def XOR8mi   : Ii8<0x80, MRM6m,
1872                      (outs), (ins i8mem :$dst, i8imm :$src),
1873                      "xor{b}\t{$src, $dst|$dst, $src}",
1874                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
1875                      (implicit EFLAGS)]>;
1876   def XOR16mi  : Ii16<0x81, MRM6m,
1877                       (outs), (ins i16mem:$dst, i16imm:$src),
1878                       "xor{w}\t{$src, $dst|$dst, $src}",
1879                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
1880                     (implicit EFLAGS)]>,
1881                       OpSize;
1882   def XOR32mi  : Ii32<0x81, MRM6m,
1883                       (outs), (ins i32mem:$dst, i32imm:$src),
1884                       "xor{l}\t{$src, $dst|$dst, $src}",
1885                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
1886                     (implicit EFLAGS)]>;
1887   def XOR16mi8 : Ii8<0x83, MRM6m,
1888                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1889                      "xor{w}\t{$src, $dst|$dst, $src}",
1890                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
1891                   (implicit EFLAGS)]>,
1892                      OpSize;
1893   def XOR32mi8 : Ii8<0x83, MRM6m,
1894                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1895                      "xor{l}\t{$src, $dst|$dst, $src}",
1896                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
1897                   (implicit EFLAGS)]>;
1898                   
1899   def XOR8i8 : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
1900                    "xor{b}\t{$src, %al|%al, $src}", []>;
1901   def XOR16i16 : Ii16 <0x35, RawFrm, (outs), (ins i16imm:$src),
1902                         "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1903   def XOR32i32 : Ii32 <0x35, RawFrm, (outs), (ins i32imm:$src),
1904                         "xor{l}\t{$src, %eax|%eax, $src}", []>;
1905 } // isTwoAddress = 0
1906 } // Defs = [EFLAGS]
1907
1908 // Shift instructions
1909 let Defs = [EFLAGS] in {
1910 let Uses = [CL] in {
1911 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src),
1912                  "shl{b}\t{%cl, $dst|$dst, CL}",
1913                  [(set GR8:$dst, (shl GR8:$src, CL))]>;
1914 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src),
1915                  "shl{w}\t{%cl, $dst|$dst, CL}",
1916                  [(set GR16:$dst, (shl GR16:$src, CL))]>, OpSize;
1917 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src),
1918                  "shl{l}\t{%cl, $dst|$dst, CL}",
1919                  [(set GR32:$dst, (shl GR32:$src, CL))]>;
1920 } // Uses = [CL]
1921
1922 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1923                    "shl{b}\t{$src2, $dst|$dst, $src2}",
1924                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
1925 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1926 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1927                    "shl{w}\t{$src2, $dst|$dst, $src2}",
1928                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1929 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1930                    "shl{l}\t{$src2, $dst|$dst, $src2}",
1931                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
1932 // NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
1933 // cheaper.
1934 } // isConvertibleToThreeAddress = 1
1935
1936 let isTwoAddress = 0 in {
1937   let Uses = [CL] in {
1938   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
1939                    "shl{b}\t{%cl, $dst|$dst, CL}",
1940                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
1941   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
1942                    "shl{w}\t{%cl, $dst|$dst, CL}",
1943                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1944   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
1945                    "shl{l}\t{%cl, $dst|$dst, CL}",
1946                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
1947   }
1948   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
1949                      "shl{b}\t{$src, $dst|$dst, $src}",
1950                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1951   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
1952                      "shl{w}\t{$src, $dst|$dst, $src}",
1953                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1954                      OpSize;
1955   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
1956                      "shl{l}\t{$src, $dst|$dst, $src}",
1957                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1958
1959   // Shift by 1
1960   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
1961                    "shl{b}\t$dst",
1962                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1963   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
1964                    "shl{w}\t$dst",
1965                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1966                      OpSize;
1967   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
1968                    "shl{l}\t$dst",
1969                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1970 }
1971
1972 let Uses = [CL] in {
1973 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src),
1974                  "shr{b}\t{%cl, $dst|$dst, CL}",
1975                  [(set GR8:$dst, (srl GR8:$src, CL))]>;
1976 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src),
1977                  "shr{w}\t{%cl, $dst|$dst, CL}",
1978                  [(set GR16:$dst, (srl GR16:$src, CL))]>, OpSize;
1979 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src),
1980                  "shr{l}\t{%cl, $dst|$dst, CL}",
1981                  [(set GR32:$dst, (srl GR32:$src, CL))]>;
1982 }
1983
1984 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
1985                    "shr{b}\t{$src2, $dst|$dst, $src2}",
1986                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
1987 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1988                    "shr{w}\t{$src2, $dst|$dst, $src2}",
1989                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1990 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1991                    "shr{l}\t{$src2, $dst|$dst, $src2}",
1992                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
1993
1994 // Shift by 1
1995 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
1996                  "shr{b}\t$dst",
1997                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
1998 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
1999                  "shr{w}\t$dst",
2000                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
2001 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2002                  "shr{l}\t$dst",
2003                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
2004
2005 let isTwoAddress = 0 in {
2006   let Uses = [CL] in {
2007   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
2008                    "shr{b}\t{%cl, $dst|$dst, CL}",
2009                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
2010   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
2011                    "shr{w}\t{%cl, $dst|$dst, CL}",
2012                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
2013                    OpSize;
2014   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
2015                    "shr{l}\t{%cl, $dst|$dst, CL}",
2016                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
2017   }
2018   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
2019                      "shr{b}\t{$src, $dst|$dst, $src}",
2020                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2021   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
2022                      "shr{w}\t{$src, $dst|$dst, $src}",
2023                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2024                      OpSize;
2025   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
2026                      "shr{l}\t{$src, $dst|$dst, $src}",
2027                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2028
2029   // Shift by 1
2030   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
2031                    "shr{b}\t$dst",
2032                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2033   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
2034                    "shr{w}\t$dst",
2035                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
2036   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
2037                    "shr{l}\t$dst",
2038                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2039 }
2040
2041 let Uses = [CL] in {
2042 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src),
2043                  "sar{b}\t{%cl, $dst|$dst, CL}",
2044                  [(set GR8:$dst, (sra GR8:$src, CL))]>;
2045 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src),
2046                  "sar{w}\t{%cl, $dst|$dst, CL}",
2047                  [(set GR16:$dst, (sra GR16:$src, CL))]>, OpSize;
2048 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src),
2049                  "sar{l}\t{%cl, $dst|$dst, CL}",
2050                  [(set GR32:$dst, (sra GR32:$src, CL))]>;
2051 }
2052
2053 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2054                    "sar{b}\t{$src2, $dst|$dst, $src2}",
2055                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
2056 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2057                    "sar{w}\t{$src2, $dst|$dst, $src2}",
2058                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
2059                    OpSize;
2060 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2061                    "sar{l}\t{$src2, $dst|$dst, $src2}",
2062                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
2063
2064 // Shift by 1
2065 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2066                  "sar{b}\t$dst",
2067                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
2068 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2069                  "sar{w}\t$dst",
2070                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
2071 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2072                  "sar{l}\t$dst",
2073                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
2074
2075 let isTwoAddress = 0 in {
2076   let Uses = [CL] in {
2077   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
2078                    "sar{b}\t{%cl, $dst|$dst, CL}",
2079                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
2080   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
2081                    "sar{w}\t{%cl, $dst|$dst, CL}",
2082                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2083   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
2084                    "sar{l}\t{%cl, $dst|$dst, CL}",
2085                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
2086   }
2087   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
2088                      "sar{b}\t{$src, $dst|$dst, $src}",
2089                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2090   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
2091                      "sar{w}\t{$src, $dst|$dst, $src}",
2092                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2093                      OpSize;
2094   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
2095                      "sar{l}\t{$src, $dst|$dst, $src}",
2096                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2097
2098   // Shift by 1
2099   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
2100                    "sar{b}\t$dst",
2101                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2102   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
2103                    "sar{w}\t$dst",
2104                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2105                      OpSize;
2106   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
2107                    "sar{l}\t$dst",
2108                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2109 }
2110
2111 // Rotate instructions
2112 // FIXME: provide shorter instructions when imm8 == 1
2113 let Uses = [CL] in {
2114 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src),
2115                  "rol{b}\t{%cl, $dst|$dst, CL}",
2116                  [(set GR8:$dst, (rotl GR8:$src, CL))]>;
2117 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src),
2118                  "rol{w}\t{%cl, $dst|$dst, CL}",
2119                  [(set GR16:$dst, (rotl GR16:$src, CL))]>, OpSize;
2120 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src),
2121                  "rol{l}\t{%cl, $dst|$dst, CL}",
2122                  [(set GR32:$dst, (rotl GR32:$src, CL))]>;
2123 }
2124
2125 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2126                    "rol{b}\t{$src2, $dst|$dst, $src2}",
2127                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
2128 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2129                    "rol{w}\t{$src2, $dst|$dst, $src2}",
2130                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2131 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2132                    "rol{l}\t{$src2, $dst|$dst, $src2}",
2133                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
2134
2135 // Rotate by 1
2136 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2137                  "rol{b}\t$dst",
2138                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
2139 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2140                  "rol{w}\t$dst",
2141                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
2142 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2143                  "rol{l}\t$dst",
2144                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
2145
2146 let isTwoAddress = 0 in {
2147   let Uses = [CL] in {
2148   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
2149                    "rol{b}\t{%cl, $dst|$dst, CL}",
2150                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
2151   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
2152                    "rol{w}\t{%cl, $dst|$dst, CL}",
2153                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2154   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
2155                    "rol{l}\t{%cl, $dst|$dst, CL}",
2156                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
2157   }
2158   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
2159                      "rol{b}\t{$src, $dst|$dst, $src}",
2160                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2161   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
2162                      "rol{w}\t{$src, $dst|$dst, $src}",
2163                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2164                      OpSize;
2165   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
2166                      "rol{l}\t{$src, $dst|$dst, $src}",
2167                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2168
2169   // Rotate by 1
2170   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
2171                    "rol{b}\t$dst",
2172                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2173   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
2174                    "rol{w}\t$dst",
2175                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2176                      OpSize;
2177   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
2178                    "rol{l}\t$dst",
2179                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2180 }
2181
2182 let Uses = [CL] in {
2183 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src),
2184                  "ror{b}\t{%cl, $dst|$dst, CL}",
2185                  [(set GR8:$dst, (rotr GR8:$src, CL))]>;
2186 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src),
2187                  "ror{w}\t{%cl, $dst|$dst, CL}",
2188                  [(set GR16:$dst, (rotr GR16:$src, CL))]>, OpSize;
2189 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src),
2190                  "ror{l}\t{%cl, $dst|$dst, CL}",
2191                  [(set GR32:$dst, (rotr GR32:$src, CL))]>;
2192 }
2193
2194 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2195                    "ror{b}\t{$src2, $dst|$dst, $src2}",
2196                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
2197 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2198                    "ror{w}\t{$src2, $dst|$dst, $src2}",
2199                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2200 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2201                    "ror{l}\t{$src2, $dst|$dst, $src2}",
2202                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
2203
2204 // Rotate by 1
2205 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2206                  "ror{b}\t$dst",
2207                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
2208 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2209                  "ror{w}\t$dst",
2210                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
2211 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2212                  "ror{l}\t$dst",
2213                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
2214
2215 let isTwoAddress = 0 in {
2216   let Uses = [CL] in {
2217   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
2218                    "ror{b}\t{%cl, $dst|$dst, CL}",
2219                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
2220   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
2221                    "ror{w}\t{%cl, $dst|$dst, CL}",
2222                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2223   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
2224                    "ror{l}\t{%cl, $dst|$dst, CL}",
2225                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
2226   }
2227   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2228                      "ror{b}\t{$src, $dst|$dst, $src}",
2229                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2230   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
2231                      "ror{w}\t{$src, $dst|$dst, $src}",
2232                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2233                      OpSize;
2234   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
2235                      "ror{l}\t{$src, $dst|$dst, $src}",
2236                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2237
2238   // Rotate by 1
2239   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
2240                    "ror{b}\t$dst",
2241                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2242   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
2243                    "ror{w}\t$dst",
2244                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2245                      OpSize;
2246   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
2247                    "ror{l}\t$dst",
2248                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2249 }
2250
2251
2252
2253 // Double shift instructions (generalizations of rotate)
2254 let Uses = [CL] in {
2255 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
2256                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2257                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
2258 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
2259                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2260                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
2261 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
2262                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2263                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
2264                    TB, OpSize;
2265 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
2266                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2267                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
2268                    TB, OpSize;
2269 }
2270
2271 let isCommutable = 1 in {  // These instructions commute to each other.
2272 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
2273                      (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2274                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2275                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
2276                                       (i8 imm:$src3)))]>,
2277                  TB;
2278 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
2279                      (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2280                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2281                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
2282                                       (i8 imm:$src3)))]>,
2283                  TB;
2284 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
2285                      (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2286                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2287                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
2288                                       (i8 imm:$src3)))]>,
2289                      TB, OpSize;
2290 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
2291                      (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2292                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2293                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
2294                                       (i8 imm:$src3)))]>,
2295                      TB, OpSize;
2296 }
2297
2298 let isTwoAddress = 0 in {
2299   let Uses = [CL] in {
2300   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2301                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2302                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
2303                        addr:$dst)]>, TB;
2304   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2305                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2306                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
2307                       addr:$dst)]>, TB;
2308   }
2309   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
2310                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2311                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2312                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
2313                                         (i8 imm:$src3)), addr:$dst)]>,
2314                       TB;
2315   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
2316                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2317                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2318                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
2319                                          (i8 imm:$src3)), addr:$dst)]>,
2320                        TB;
2321
2322   let Uses = [CL] in {
2323   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2324                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2325                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
2326                        addr:$dst)]>, TB, OpSize;
2327   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2328                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2329                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
2330                       addr:$dst)]>, TB, OpSize;
2331   }
2332   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
2333                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2334                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2335                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
2336                                         (i8 imm:$src3)), addr:$dst)]>,
2337                       TB, OpSize;
2338   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
2339                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2340                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2341                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
2342                                         (i8 imm:$src3)), addr:$dst)]>,
2343                        TB, OpSize;
2344 }
2345 } // Defs = [EFLAGS]
2346
2347
2348 // Arithmetic.
2349 let Defs = [EFLAGS] in {
2350 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
2351 // Register-Register Addition
2352 def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
2353                                     (ins GR8 :$src1, GR8 :$src2),
2354                   "add{b}\t{$src2, $dst|$dst, $src2}",
2355                   [(set GR8:$dst, (add GR8:$src1, GR8:$src2)),
2356                    (implicit EFLAGS)]>;
2357
2358 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2359 // Register-Register Addition
2360 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
2361                                    (ins GR16:$src1, GR16:$src2),
2362                  "add{w}\t{$src2, $dst|$dst, $src2}",
2363                  [(set GR16:$dst, (add GR16:$src1, GR16:$src2)),
2364                   (implicit EFLAGS)]>, OpSize;
2365 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
2366                                    (ins GR32:$src1, GR32:$src2),
2367                  "add{l}\t{$src2, $dst|$dst, $src2}",
2368                  [(set GR32:$dst, (add GR32:$src1, GR32:$src2)),
2369                   (implicit EFLAGS)]>;
2370 } // end isConvertibleToThreeAddress
2371 } // end isCommutable
2372
2373 // Register-Memory Addition
2374 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2375                                   (ins GR8 :$src1, i8mem :$src2),
2376                  "add{b}\t{$src2, $dst|$dst, $src2}",
2377                  [(set GR8:$dst, (add GR8:$src1, (load addr:$src2))),
2378                   (implicit EFLAGS)]>;
2379 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
2380                                   (ins GR16:$src1, i16mem:$src2),
2381                  "add{w}\t{$src2, $dst|$dst, $src2}",
2382                  [(set GR16:$dst, (add GR16:$src1, (load addr:$src2))),
2383                   (implicit EFLAGS)]>, OpSize;
2384 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
2385                                   (ins GR32:$src1, i32mem:$src2),
2386                  "add{l}\t{$src2, $dst|$dst, $src2}",
2387                  [(set GR32:$dst, (add GR32:$src1, (load addr:$src2))),
2388                   (implicit EFLAGS)]>;
2389
2390 // Register-Integer Addition
2391 def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2392                     "add{b}\t{$src2, $dst|$dst, $src2}",
2393                     [(set GR8:$dst, (add GR8:$src1, imm:$src2)),
2394                      (implicit EFLAGS)]>;
2395
2396 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2397 // Register-Integer Addition
2398 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
2399                                  (ins GR16:$src1, i16imm:$src2),
2400                     "add{w}\t{$src2, $dst|$dst, $src2}",
2401                     [(set GR16:$dst, (add GR16:$src1, imm:$src2)),
2402                      (implicit EFLAGS)]>, OpSize;
2403 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
2404                                  (ins GR32:$src1, i32imm:$src2),
2405                     "add{l}\t{$src2, $dst|$dst, $src2}",
2406                     [(set GR32:$dst, (add GR32:$src1, imm:$src2)),
2407                      (implicit EFLAGS)]>;
2408 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2409                                 (ins GR16:$src1, i16i8imm:$src2),
2410                    "add{w}\t{$src2, $dst|$dst, $src2}",
2411                    [(set GR16:$dst, (add GR16:$src1, i16immSExt8:$src2)),
2412                     (implicit EFLAGS)]>, OpSize;
2413 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2414                                 (ins GR32:$src1, i32i8imm:$src2),
2415                    "add{l}\t{$src2, $dst|$dst, $src2}",
2416                    [(set GR32:$dst, (add GR32:$src1, i32immSExt8:$src2)),
2417                     (implicit EFLAGS)]>;
2418 }
2419
2420 let isTwoAddress = 0 in {
2421   // Memory-Register Addition
2422   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2423                    "add{b}\t{$src2, $dst|$dst, $src2}",
2424                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2425                     (implicit EFLAGS)]>;
2426   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2427                    "add{w}\t{$src2, $dst|$dst, $src2}",
2428                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2429                     (implicit EFLAGS)]>, OpSize;
2430   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2431                    "add{l}\t{$src2, $dst|$dst, $src2}",
2432                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2433                     (implicit EFLAGS)]>;
2434   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
2435                      "add{b}\t{$src2, $dst|$dst, $src2}",
2436                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2437                     (implicit EFLAGS)]>;
2438   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
2439                       "add{w}\t{$src2, $dst|$dst, $src2}",
2440                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2441                    (implicit EFLAGS)]>, OpSize;
2442   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
2443                       "add{l}\t{$src2, $dst|$dst, $src2}",
2444                       [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2445                        (implicit EFLAGS)]>;
2446   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2447                      "add{w}\t{$src2, $dst|$dst, $src2}",
2448                      [(store (add (load addr:$dst), i16immSExt8:$src2),
2449                                   addr:$dst),
2450                       (implicit EFLAGS)]>, OpSize;
2451   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2452                      "add{l}\t{$src2, $dst|$dst, $src2}",
2453                   [(store (add (load addr:$dst), i32immSExt8:$src2),
2454                                addr:$dst),
2455                    (implicit EFLAGS)]>;
2456
2457   // addition to rAX
2458   def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
2459                    "add{b}\t{$src, %al|%al, $src}", []>;
2460   def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
2461                       "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2462   def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
2463                       "add{l}\t{$src, %eax|%eax, $src}", []>;
2464 }
2465
2466 let Uses = [EFLAGS] in {
2467 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
2468 def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2469                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2470                  [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
2471 def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
2472                                    (ins GR16:$src1, GR16:$src2),
2473                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2474                  [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
2475 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
2476                                    (ins GR32:$src1, GR32:$src2),
2477                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2478                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
2479 }
2480 def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
2481                                    (ins GR8:$src1, i8mem:$src2),
2482                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2483                  [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
2484 def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
2485                                    (ins GR16:$src1, i16mem:$src2),
2486                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2487                  [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
2488                  OpSize;
2489 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
2490                                    (ins GR32:$src1, i32mem:$src2),
2491                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2492                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2493 def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2494                     "adc{b}\t{$src2, $dst|$dst, $src2}",
2495                  [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
2496 def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
2497                                  (ins GR16:$src1, i16imm:$src2),
2498                     "adc{w}\t{$src2, $dst|$dst, $src2}",
2499                  [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
2500 def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2501                                 (ins GR16:$src1, i16i8imm:$src2),
2502                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2503                  [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2504                  OpSize;
2505 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
2506                                  (ins GR32:$src1, i32imm:$src2),
2507                     "adc{l}\t{$src2, $dst|$dst, $src2}",
2508                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
2509 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2510                                 (ins GR32:$src1, i32i8imm:$src2),
2511                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2512                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
2513
2514 let isTwoAddress = 0 in {
2515   def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2516                    "adc{b}\t{$src2, $dst|$dst, $src2}",
2517                    [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2518   def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2519                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2520                    [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2521                    OpSize;
2522   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2523                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2524                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2525   def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
2526                       "adc{b}\t{$src2, $dst|$dst, $src2}",
2527                   [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2528   def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
2529                       "adc{w}\t{$src2, $dst|$dst, $src2}",
2530                   [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2531                   OpSize;
2532   def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2533                      "adc{w}\t{$src2, $dst|$dst, $src2}",
2534                [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2535                OpSize;
2536   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
2537                       "adc{l}\t{$src2, $dst|$dst, $src2}",
2538                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2539   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2540                      "adc{l}\t{$src2, $dst|$dst, $src2}",
2541                [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2542 }
2543 } // Uses = [EFLAGS]
2544
2545 // Register-Register Subtraction
2546 def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2547                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2548                 [(set GR8:$dst, (sub GR8:$src1, GR8:$src2)),
2549                  (implicit EFLAGS)]>;
2550 def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2551                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2552                 [(set GR16:$dst, (sub GR16:$src1, GR16:$src2)),
2553                  (implicit EFLAGS)]>, OpSize;
2554 def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2555                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2556                 [(set GR32:$dst, (sub GR32:$src1, GR32:$src2)),
2557                  (implicit EFLAGS)]>;
2558
2559 // Register-Memory Subtraction
2560 def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
2561                                  (ins GR8 :$src1, i8mem :$src2),
2562                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2563                 [(set GR8:$dst, (sub GR8:$src1, (load addr:$src2))),
2564                  (implicit EFLAGS)]>;
2565 def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
2566                                  (ins GR16:$src1, i16mem:$src2),
2567                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2568                 [(set GR16:$dst, (sub GR16:$src1, (load addr:$src2))),
2569                  (implicit EFLAGS)]>, OpSize;
2570 def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
2571                                  (ins GR32:$src1, i32mem:$src2),
2572                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2573                 [(set GR32:$dst, (sub GR32:$src1, (load addr:$src2))),
2574                  (implicit EFLAGS)]>;
2575
2576 // Register-Integer Subtraction
2577 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
2578                                  (ins GR8:$src1, i8imm:$src2),
2579                     "sub{b}\t{$src2, $dst|$dst, $src2}",
2580                     [(set GR8:$dst, (sub GR8:$src1, imm:$src2)),
2581                      (implicit EFLAGS)]>;
2582 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
2583                                  (ins GR16:$src1, i16imm:$src2),
2584                     "sub{w}\t{$src2, $dst|$dst, $src2}",
2585                     [(set GR16:$dst, (sub GR16:$src1, imm:$src2)),
2586                      (implicit EFLAGS)]>, OpSize;
2587 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
2588                                  (ins GR32:$src1, i32imm:$src2),
2589                     "sub{l}\t{$src2, $dst|$dst, $src2}",
2590                     [(set GR32:$dst, (sub GR32:$src1, imm:$src2)),
2591                      (implicit EFLAGS)]>;
2592 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
2593                                 (ins GR16:$src1, i16i8imm:$src2),
2594                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2595                    [(set GR16:$dst, (sub GR16:$src1, i16immSExt8:$src2)),
2596                     (implicit EFLAGS)]>, OpSize;
2597 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
2598                                 (ins GR32:$src1, i32i8imm:$src2),
2599                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2600                    [(set GR32:$dst, (sub GR32:$src1, i32immSExt8:$src2)),
2601                     (implicit EFLAGS)]>;
2602
2603 let isTwoAddress = 0 in {
2604   // Memory-Register Subtraction
2605   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
2606                    "sub{b}\t{$src2, $dst|$dst, $src2}",
2607                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
2608                     (implicit EFLAGS)]>;
2609   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2610                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2611                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
2612                     (implicit EFLAGS)]>, OpSize;
2613   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2614                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2615                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
2616                     (implicit EFLAGS)]>;
2617
2618   // Memory-Integer Subtraction
2619   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
2620                      "sub{b}\t{$src2, $dst|$dst, $src2}",
2621                      [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
2622                       (implicit EFLAGS)]>;
2623   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2624                       "sub{w}\t{$src2, $dst|$dst, $src2}",
2625                       [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
2626                        (implicit EFLAGS)]>, OpSize;
2627   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2628                       "sub{l}\t{$src2, $dst|$dst, $src2}",
2629                       [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
2630                        (implicit EFLAGS)]>;
2631   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2632                      "sub{w}\t{$src2, $dst|$dst, $src2}",
2633                      [(store (sub (load addr:$dst), i16immSExt8:$src2),
2634                              addr:$dst),
2635                       (implicit EFLAGS)]>, OpSize;
2636   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2637                      "sub{l}\t{$src2, $dst|$dst, $src2}",
2638                      [(store (sub (load addr:$dst), i32immSExt8:$src2),
2639                              addr:$dst),
2640                       (implicit EFLAGS)]>;
2641 }
2642
2643 let Uses = [EFLAGS] in {
2644 def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
2645                                      (ins GR8:$src1, GR8:$src2),
2646                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
2647                  [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
2648 def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
2649                                      (ins GR16:$src1, GR16:$src2),
2650                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
2651                  [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
2652 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
2653                                       (ins GR32:$src1, GR32:$src2),
2654                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
2655                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
2656
2657 let isTwoAddress = 0 in {
2658   def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
2659                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
2660                    [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
2661   def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
2662                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2663                    [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
2664                    OpSize;
2665   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2666                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2667                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
2668   def SBB8mi  : Ii32<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
2669                       "sbb{b}\t{$src2, $dst|$dst, $src2}",
2670                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2671   def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2672                       "sbb{w}\t{$src2, $dst|$dst, $src2}",
2673                   [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2674                   OpSize;
2675   def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2676                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
2677                [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2678                OpSize;
2679   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2680                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
2681                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2682   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
2683                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
2684                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2685 }
2686 def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
2687                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2688                     [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
2689 def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
2690                                   (ins GR16:$src1, i16mem:$src2),
2691                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2692                     [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
2693                     OpSize;
2694 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
2695                                   (ins GR32:$src1, i32mem:$src2),
2696                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2697                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
2698 def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2699                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2700                     [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
2701 def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
2702                                  (ins GR16:$src1, i16imm:$src2),
2703                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2704                     [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
2705 def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
2706                                 (ins GR16:$src1, i16i8imm:$src2),
2707                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2708                    [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
2709                    OpSize;
2710 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
2711                                  (ins GR32:$src1, i32imm:$src2),
2712                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2713                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
2714 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
2715                                 (ins GR32:$src1, i32i8imm:$src2),
2716                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2717                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
2718 } // Uses = [EFLAGS]
2719 } // Defs = [EFLAGS]
2720
2721 let Defs = [EFLAGS] in {
2722 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
2723 // Register-Register Signed Integer Multiply
2724 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2725                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2726                  [(set GR16:$dst, (mul GR16:$src1, GR16:$src2)),
2727                   (implicit EFLAGS)]>, TB, OpSize;
2728 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2729                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2730                  [(set GR32:$dst, (mul GR32:$src1, GR32:$src2)),
2731                   (implicit EFLAGS)]>, TB;
2732 }
2733
2734 // Register-Memory Signed Integer Multiply
2735 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
2736                                   (ins GR16:$src1, i16mem:$src2),
2737                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2738                  [(set GR16:$dst, (mul GR16:$src1, (load addr:$src2))),
2739                   (implicit EFLAGS)]>, TB, OpSize;
2740 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
2741                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2742                  [(set GR32:$dst, (mul GR32:$src1, (load addr:$src2))),
2743                   (implicit EFLAGS)]>, TB;
2744 } // Defs = [EFLAGS]
2745 } // end Two Address instructions
2746
2747 // Suprisingly enough, these are not two address instructions!
2748 let Defs = [EFLAGS] in {
2749 // Register-Integer Signed Integer Multiply
2750 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
2751                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
2752                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2753                       [(set GR16:$dst, (mul GR16:$src1, imm:$src2)),
2754                        (implicit EFLAGS)]>, OpSize;
2755 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
2756                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2757                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2758                       [(set GR32:$dst, (mul GR32:$src1, imm:$src2)),
2759                        (implicit EFLAGS)]>;
2760 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
2761                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2762                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2763                      [(set GR16:$dst, (mul GR16:$src1, i16immSExt8:$src2)),
2764                       (implicit EFLAGS)]>, OpSize;
2765 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
2766                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2767                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2768                      [(set GR32:$dst, (mul GR32:$src1, i32immSExt8:$src2)),
2769                       (implicit EFLAGS)]>;
2770
2771 // Memory-Integer Signed Integer Multiply
2772 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                      // GR16 = [mem16]*I16
2773                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
2774                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2775                       [(set GR16:$dst, (mul (load addr:$src1), imm:$src2)),
2776                        (implicit EFLAGS)]>, OpSize;
2777 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                      // GR32 = [mem32]*I32
2778                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
2779                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2780                       [(set GR32:$dst, (mul (load addr:$src1), imm:$src2)),
2781                        (implicit EFLAGS)]>;
2782 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
2783                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
2784                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2785                      [(set GR16:$dst, (mul (load addr:$src1),
2786                                        i16immSExt8:$src2)),
2787                       (implicit EFLAGS)]>, OpSize;
2788 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
2789                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
2790                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2791                      [(set GR32:$dst, (mul (load addr:$src1),
2792                                            i32immSExt8:$src2)),
2793                       (implicit EFLAGS)]>;
2794 } // Defs = [EFLAGS]
2795
2796 //===----------------------------------------------------------------------===//
2797 // Test instructions are just like AND, except they don't generate a result.
2798 //
2799 let Defs = [EFLAGS] in {
2800 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
2801 def TEST8rr  : I<0x84, MRMDestReg, (outs),  (ins GR8:$src1, GR8:$src2),
2802                      "test{b}\t{$src2, $src1|$src1, $src2}",
2803                      [(X86cmp (and_su GR8:$src1, GR8:$src2), 0),
2804                       (implicit EFLAGS)]>;
2805 def TEST16rr : I<0x85, MRMDestReg, (outs),  (ins GR16:$src1, GR16:$src2),
2806                      "test{w}\t{$src2, $src1|$src1, $src2}",
2807                      [(X86cmp (and_su GR16:$src1, GR16:$src2), 0),
2808                       (implicit EFLAGS)]>,
2809                  OpSize;
2810 def TEST32rr : I<0x85, MRMDestReg, (outs),  (ins GR32:$src1, GR32:$src2),
2811                      "test{l}\t{$src2, $src1|$src1, $src2}",
2812                      [(X86cmp (and_su GR32:$src1, GR32:$src2), 0),
2813                       (implicit EFLAGS)]>;
2814 }
2815
2816 def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
2817                    "test{b}\t{$src, %al|%al, $src}", []>;
2818 def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
2819                      "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2820 def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
2821                      "test{l}\t{$src, %eax|%eax, $src}", []>;
2822
2823 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
2824                      "test{b}\t{$src2, $src1|$src1, $src2}",
2825                      [(X86cmp (and GR8:$src1, (loadi8 addr:$src2)), 0),
2826                       (implicit EFLAGS)]>;
2827 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
2828                      "test{w}\t{$src2, $src1|$src1, $src2}",
2829                      [(X86cmp (and GR16:$src1, (loadi16 addr:$src2)), 0),
2830                       (implicit EFLAGS)]>, OpSize;
2831 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
2832                      "test{l}\t{$src2, $src1|$src1, $src2}",
2833                      [(X86cmp (and GR32:$src1, (loadi32 addr:$src2)), 0),
2834                       (implicit EFLAGS)]>;
2835
2836 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
2837                     (outs),  (ins GR8:$src1, i8imm:$src2),
2838                     "test{b}\t{$src2, $src1|$src1, $src2}",
2839                     [(X86cmp (and_su GR8:$src1, imm:$src2), 0),
2840                      (implicit EFLAGS)]>;
2841 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
2842                     (outs),  (ins GR16:$src1, i16imm:$src2),
2843                     "test{w}\t{$src2, $src1|$src1, $src2}",
2844                     [(X86cmp (and_su GR16:$src1, imm:$src2), 0),
2845                      (implicit EFLAGS)]>, OpSize;
2846 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
2847                     (outs),  (ins GR32:$src1, i32imm:$src2),
2848                     "test{l}\t{$src2, $src1|$src1, $src2}",
2849                     [(X86cmp (and_su GR32:$src1, imm:$src2), 0),
2850                      (implicit EFLAGS)]>;
2851
2852 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
2853                     (outs), (ins i8mem:$src1, i8imm:$src2),
2854                     "test{b}\t{$src2, $src1|$src1, $src2}",
2855                     [(X86cmp (and (loadi8 addr:$src1), imm:$src2), 0),
2856                      (implicit EFLAGS)]>;
2857 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
2858                     (outs), (ins i16mem:$src1, i16imm:$src2),
2859                     "test{w}\t{$src2, $src1|$src1, $src2}",
2860                     [(X86cmp (and (loadi16 addr:$src1), imm:$src2), 0),
2861                      (implicit EFLAGS)]>, OpSize;
2862 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
2863                     (outs), (ins i32mem:$src1, i32imm:$src2),
2864                     "test{l}\t{$src2, $src1|$src1, $src2}",
2865                     [(X86cmp (and (loadi32 addr:$src1), imm:$src2), 0),
2866                      (implicit EFLAGS)]>;
2867 } // Defs = [EFLAGS]
2868
2869
2870 // Condition code ops, incl. set if equal/not equal/...
2871 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
2872 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
2873 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
2874 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
2875
2876 let Uses = [EFLAGS] in {
2877 def SETEr    : I<0x94, MRM0r, 
2878                  (outs GR8   :$dst), (ins),
2879                  "sete\t$dst",
2880                  [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
2881                TB;                        // GR8 = ==
2882 def SETEm    : I<0x94, MRM0m, 
2883                  (outs), (ins i8mem:$dst),
2884                  "sete\t$dst",
2885                  [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
2886                TB;                        // [mem8] = ==
2887
2888 def SETNEr   : I<0x95, MRM0r, 
2889                  (outs GR8   :$dst), (ins),
2890                  "setne\t$dst",
2891                  [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
2892                TB;                        // GR8 = !=
2893 def SETNEm   : I<0x95, MRM0m, 
2894                  (outs), (ins i8mem:$dst),
2895                  "setne\t$dst",
2896                  [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
2897                TB;                        // [mem8] = !=
2898
2899 def SETLr    : I<0x9C, MRM0r, 
2900                  (outs GR8   :$dst), (ins),
2901                  "setl\t$dst",
2902                  [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
2903                TB;                        // GR8 = <  signed
2904 def SETLm    : I<0x9C, MRM0m, 
2905                  (outs), (ins i8mem:$dst),
2906                  "setl\t$dst",
2907                  [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
2908                TB;                        // [mem8] = <  signed
2909
2910 def SETGEr   : I<0x9D, MRM0r, 
2911                  (outs GR8   :$dst), (ins),
2912                  "setge\t$dst",
2913                  [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
2914                TB;                        // GR8 = >= signed
2915 def SETGEm   : I<0x9D, MRM0m, 
2916                  (outs), (ins i8mem:$dst),
2917                  "setge\t$dst",
2918                  [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
2919                TB;                        // [mem8] = >= signed
2920
2921 def SETLEr   : I<0x9E, MRM0r, 
2922                  (outs GR8   :$dst), (ins),
2923                  "setle\t$dst",
2924                  [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
2925                TB;                        // GR8 = <= signed
2926 def SETLEm   : I<0x9E, MRM0m, 
2927                  (outs), (ins i8mem:$dst),
2928                  "setle\t$dst",
2929                  [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
2930                TB;                        // [mem8] = <= signed
2931
2932 def SETGr    : I<0x9F, MRM0r, 
2933                  (outs GR8   :$dst), (ins),
2934                  "setg\t$dst",
2935                  [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
2936                TB;                        // GR8 = >  signed
2937 def SETGm    : I<0x9F, MRM0m, 
2938                  (outs), (ins i8mem:$dst),
2939                  "setg\t$dst",
2940                  [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
2941                TB;                        // [mem8] = >  signed
2942
2943 def SETBr    : I<0x92, MRM0r,
2944                  (outs GR8   :$dst), (ins),
2945                  "setb\t$dst",
2946                  [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
2947                TB;                        // GR8 = <  unsign
2948 def SETBm    : I<0x92, MRM0m,
2949                  (outs), (ins i8mem:$dst),
2950                  "setb\t$dst",
2951                  [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
2952                TB;                        // [mem8] = <  unsign
2953
2954 def SETAEr   : I<0x93, MRM0r, 
2955                  (outs GR8   :$dst), (ins),
2956                  "setae\t$dst",
2957                  [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
2958                TB;                        // GR8 = >= unsign
2959 def SETAEm   : I<0x93, MRM0m, 
2960                  (outs), (ins i8mem:$dst),
2961                  "setae\t$dst",
2962                  [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
2963                TB;                        // [mem8] = >= unsign
2964
2965 def SETBEr   : I<0x96, MRM0r, 
2966                  (outs GR8   :$dst), (ins),
2967                  "setbe\t$dst",
2968                  [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
2969                TB;                        // GR8 = <= unsign
2970 def SETBEm   : I<0x96, MRM0m, 
2971                  (outs), (ins i8mem:$dst),
2972                  "setbe\t$dst",
2973                  [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
2974                TB;                        // [mem8] = <= unsign
2975
2976 def SETAr    : I<0x97, MRM0r, 
2977                  (outs GR8   :$dst), (ins),
2978                  "seta\t$dst",
2979                  [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
2980                TB;                        // GR8 = >  signed
2981 def SETAm    : I<0x97, MRM0m, 
2982                  (outs), (ins i8mem:$dst),
2983                  "seta\t$dst",
2984                  [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
2985                TB;                        // [mem8] = >  signed
2986
2987 def SETSr    : I<0x98, MRM0r, 
2988                  (outs GR8   :$dst), (ins),
2989                  "sets\t$dst",
2990                  [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
2991                TB;                        // GR8 = <sign bit>
2992 def SETSm    : I<0x98, MRM0m, 
2993                  (outs), (ins i8mem:$dst),
2994                  "sets\t$dst",
2995                  [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
2996                TB;                        // [mem8] = <sign bit>
2997 def SETNSr   : I<0x99, MRM0r, 
2998                  (outs GR8   :$dst), (ins),
2999                  "setns\t$dst",
3000                  [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
3001                TB;                        // GR8 = !<sign bit>
3002 def SETNSm   : I<0x99, MRM0m, 
3003                  (outs), (ins i8mem:$dst),
3004                  "setns\t$dst",
3005                  [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
3006                TB;                        // [mem8] = !<sign bit>
3007
3008 def SETPr    : I<0x9A, MRM0r, 
3009                  (outs GR8   :$dst), (ins),
3010                  "setp\t$dst",
3011                  [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
3012                TB;                        // GR8 = parity
3013 def SETPm    : I<0x9A, MRM0m, 
3014                  (outs), (ins i8mem:$dst),
3015                  "setp\t$dst",
3016                  [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
3017                TB;                        // [mem8] = parity
3018 def SETNPr   : I<0x9B, MRM0r, 
3019                  (outs GR8   :$dst), (ins),
3020                  "setnp\t$dst",
3021                  [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
3022                TB;                        // GR8 = not parity
3023 def SETNPm   : I<0x9B, MRM0m, 
3024                  (outs), (ins i8mem:$dst),
3025                  "setnp\t$dst",
3026                  [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
3027                TB;                        // [mem8] = not parity
3028
3029 def SETOr    : I<0x90, MRM0r, 
3030                  (outs GR8   :$dst), (ins),
3031                  "seto\t$dst",
3032                  [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
3033                TB;                        // GR8 = overflow
3034 def SETOm    : I<0x90, MRM0m, 
3035                  (outs), (ins i8mem:$dst),
3036                  "seto\t$dst",
3037                  [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
3038                TB;                        // [mem8] = overflow
3039 def SETNOr   : I<0x91, MRM0r, 
3040                  (outs GR8   :$dst), (ins),
3041                  "setno\t$dst",
3042                  [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
3043                TB;                        // GR8 = not overflow
3044 def SETNOm   : I<0x91, MRM0m, 
3045                  (outs), (ins i8mem:$dst),
3046                  "setno\t$dst",
3047                  [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
3048                TB;                        // [mem8] = not overflow
3049 } // Uses = [EFLAGS]
3050
3051
3052 // Integer comparisons
3053 let Defs = [EFLAGS] in {
3054 def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
3055                  "cmp{b}\t{$src, %al|%al, $src}", []>;
3056 def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
3057                     "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3058 def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
3059                     "cmp{l}\t{$src, %eax|%eax, $src}", []>;
3060
3061 def CMP8rr  : I<0x38, MRMDestReg,
3062                 (outs), (ins GR8 :$src1, GR8 :$src2),
3063                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3064                 [(X86cmp GR8:$src1, GR8:$src2), (implicit EFLAGS)]>;
3065 def CMP16rr : I<0x39, MRMDestReg,
3066                 (outs), (ins GR16:$src1, GR16:$src2),
3067                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3068                 [(X86cmp GR16:$src1, GR16:$src2), (implicit EFLAGS)]>, OpSize;
3069 def CMP32rr : I<0x39, MRMDestReg,
3070                 (outs), (ins GR32:$src1, GR32:$src2),
3071                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3072                 [(X86cmp GR32:$src1, GR32:$src2), (implicit EFLAGS)]>;
3073 def CMP8mr  : I<0x38, MRMDestMem,
3074                 (outs), (ins i8mem :$src1, GR8 :$src2),
3075                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3076                 [(X86cmp (loadi8 addr:$src1), GR8:$src2),
3077                  (implicit EFLAGS)]>;
3078 def CMP16mr : I<0x39, MRMDestMem,
3079                 (outs), (ins i16mem:$src1, GR16:$src2),
3080                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3081                 [(X86cmp (loadi16 addr:$src1), GR16:$src2),
3082                  (implicit EFLAGS)]>, OpSize;
3083 def CMP32mr : I<0x39, MRMDestMem,
3084                 (outs), (ins i32mem:$src1, GR32:$src2),
3085                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3086                 [(X86cmp (loadi32 addr:$src1), GR32:$src2),
3087                  (implicit EFLAGS)]>;
3088 def CMP8rm  : I<0x3A, MRMSrcMem,
3089                 (outs), (ins GR8 :$src1, i8mem :$src2),
3090                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3091                 [(X86cmp GR8:$src1, (loadi8 addr:$src2)),
3092                  (implicit EFLAGS)]>;
3093 def CMP16rm : I<0x3B, MRMSrcMem,
3094                 (outs), (ins GR16:$src1, i16mem:$src2),
3095                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3096                 [(X86cmp GR16:$src1, (loadi16 addr:$src2)),
3097                  (implicit EFLAGS)]>, OpSize;
3098 def CMP32rm : I<0x3B, MRMSrcMem,
3099                 (outs), (ins GR32:$src1, i32mem:$src2),
3100                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3101                 [(X86cmp GR32:$src1, (loadi32 addr:$src2)),
3102                  (implicit EFLAGS)]>;
3103 def CMP8ri  : Ii8<0x80, MRM7r,
3104                   (outs), (ins GR8:$src1, i8imm:$src2),
3105                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
3106                   [(X86cmp GR8:$src1, imm:$src2), (implicit EFLAGS)]>;
3107 def CMP16ri : Ii16<0x81, MRM7r,
3108                    (outs), (ins GR16:$src1, i16imm:$src2),
3109                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3110                    [(X86cmp GR16:$src1, imm:$src2),
3111                     (implicit EFLAGS)]>, OpSize;
3112 def CMP32ri : Ii32<0x81, MRM7r,
3113                    (outs), (ins GR32:$src1, i32imm:$src2),
3114                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3115                    [(X86cmp GR32:$src1, imm:$src2), (implicit EFLAGS)]>;
3116 def CMP8mi  : Ii8 <0x80, MRM7m,
3117                    (outs), (ins i8mem :$src1, i8imm :$src2),
3118                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
3119                    [(X86cmp (loadi8 addr:$src1), imm:$src2),
3120                     (implicit EFLAGS)]>;
3121 def CMP16mi : Ii16<0x81, MRM7m,
3122                    (outs), (ins i16mem:$src1, i16imm:$src2),
3123                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3124                    [(X86cmp (loadi16 addr:$src1), imm:$src2),
3125                     (implicit EFLAGS)]>, OpSize;
3126 def CMP32mi : Ii32<0x81, MRM7m,
3127                    (outs), (ins i32mem:$src1, i32imm:$src2),
3128                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3129                    [(X86cmp (loadi32 addr:$src1), imm:$src2),
3130                     (implicit EFLAGS)]>;
3131 def CMP16ri8 : Ii8<0x83, MRM7r,
3132                    (outs), (ins GR16:$src1, i16i8imm:$src2),
3133                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3134                    [(X86cmp GR16:$src1, i16immSExt8:$src2),
3135                     (implicit EFLAGS)]>, OpSize;
3136 def CMP16mi8 : Ii8<0x83, MRM7m,
3137                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
3138                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3139                    [(X86cmp (loadi16 addr:$src1), i16immSExt8:$src2),
3140                     (implicit EFLAGS)]>, OpSize;
3141 def CMP32mi8 : Ii8<0x83, MRM7m,
3142                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
3143                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3144                    [(X86cmp (loadi32 addr:$src1), i32immSExt8:$src2),
3145                     (implicit EFLAGS)]>;
3146 def CMP32ri8 : Ii8<0x83, MRM7r,
3147                    (outs), (ins GR32:$src1, i32i8imm:$src2),
3148                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3149                    [(X86cmp GR32:$src1, i32immSExt8:$src2),
3150                     (implicit EFLAGS)]>;
3151 } // Defs = [EFLAGS]
3152
3153 // Bit tests.
3154 // TODO: BTC, BTR, and BTS
3155 let Defs = [EFLAGS] in {
3156 def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3157                "bt{w}\t{$src2, $src1|$src1, $src2}",
3158                [(X86bt GR16:$src1, GR16:$src2),
3159                 (implicit EFLAGS)]>, OpSize, TB;
3160 def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3161                "bt{l}\t{$src2, $src1|$src1, $src2}",
3162                [(X86bt GR32:$src1, GR32:$src2),
3163                 (implicit EFLAGS)]>, TB;
3164
3165 // Unlike with the register+register form, the memory+register form of the
3166 // bt instruction does not ignore the high bits of the index. From ISel's
3167 // perspective, this is pretty bizarre. Disable these instructions for now.
3168 //def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3169 //               "bt{w}\t{$src2, $src1|$src1, $src2}",
3170 //               [(X86bt (loadi16 addr:$src1), GR16:$src2),
3171 //                (implicit EFLAGS)]>, OpSize, TB, Requires<[FastBTMem]>;
3172 //def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3173 //               "bt{l}\t{$src2, $src1|$src1, $src2}",
3174 //               [(X86bt (loadi32 addr:$src1), GR32:$src2),
3175 //                (implicit EFLAGS)]>, TB, Requires<[FastBTMem]>;
3176
3177 def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3178                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3179                 [(X86bt GR16:$src1, i16immSExt8:$src2),
3180                  (implicit EFLAGS)]>, OpSize, TB;
3181 def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3182                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3183                 [(X86bt GR32:$src1, i32immSExt8:$src2),
3184                  (implicit EFLAGS)]>, TB;
3185 // Note that these instructions don't need FastBTMem because that
3186 // only applies when the other operand is in a register. When it's
3187 // an immediate, bt is still fast.
3188 def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3189                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3190                 [(X86bt (loadi16 addr:$src1), i16immSExt8:$src2),
3191                  (implicit EFLAGS)]>, OpSize, TB;
3192 def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3193                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3194                 [(X86bt (loadi32 addr:$src1), i32immSExt8:$src2),
3195                  (implicit EFLAGS)]>, TB;
3196 } // Defs = [EFLAGS]
3197
3198 // Sign/Zero extenders
3199 // Use movsbl intead of movsbw; we don't care about the high 16 bits
3200 // of the register here. This has a smaller encoding and avoids a
3201 // partial-register update.
3202 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3203                    "movs{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
3204                    [(set GR16:$dst, (sext GR8:$src))]>, TB;
3205 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3206                    "movs{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
3207                    [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
3208 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3209                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3210                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
3211 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3212                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3213                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
3214 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3215                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3216                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
3217 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3218                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3219                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
3220
3221 // Use movzbl intead of movzbw; we don't care about the high 16 bits
3222 // of the register here. This has a smaller encoding and avoids a
3223 // partial-register update.
3224 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3225                    "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
3226                    [(set GR16:$dst, (zext GR8:$src))]>, TB;
3227 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3228                    "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
3229                    [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
3230 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3231                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3232                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
3233 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3234                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3235                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
3236 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3237                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3238                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
3239 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3240                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3241                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
3242
3243 // These are the same as the regular regular MOVZX32rr8 and MOVZX32rm8
3244 // except that they use GR32_NOREX for the output operand register class
3245 // instead of GR32. This allows them to operate on h registers on x86-64.
3246 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
3247                          (outs GR32_NOREX:$dst), (ins GR8:$src),
3248                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3249                          []>, TB;
3250 let mayLoad = 1 in
3251 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
3252                          (outs GR32_NOREX:$dst), (ins i8mem:$src),
3253                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3254                          []>, TB;
3255
3256 let neverHasSideEffects = 1 in {
3257   let Defs = [AX], Uses = [AL] in
3258   def CBW : I<0x98, RawFrm, (outs), (ins),
3259               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
3260   let Defs = [EAX], Uses = [AX] in
3261   def CWDE : I<0x98, RawFrm, (outs), (ins),
3262               "{cwtl|cwde}", []>;   // EAX = signext(AX)
3263
3264   let Defs = [AX,DX], Uses = [AX] in
3265   def CWD : I<0x99, RawFrm, (outs), (ins),
3266               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
3267   let Defs = [EAX,EDX], Uses = [EAX] in
3268   def CDQ : I<0x99, RawFrm, (outs), (ins),
3269               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
3270 }
3271
3272 //===----------------------------------------------------------------------===//
3273 // Alias Instructions
3274 //===----------------------------------------------------------------------===//
3275
3276 // Alias instructions that map movr0 to xor.
3277 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
3278 let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
3279     isCodeGenOnly = 1 in {
3280 def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins),
3281                  "xor{b}\t$dst, $dst",
3282                  [(set GR8:$dst, 0)]>;
3283 // Use xorl instead of xorw since we don't care about the high 16 bits,
3284 // it's smaller, and it avoids a partial-register update.
3285 def MOV16r0  : I<0x31, MRMInitReg,  (outs GR16:$dst), (ins),
3286                  "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
3287                  [(set GR16:$dst, 0)]>;
3288 def MOV32r0  : I<0x31, MRMInitReg,  (outs GR32:$dst), (ins),
3289                  "xor{l}\t$dst, $dst",
3290                  [(set GR32:$dst, 0)]>;
3291 }
3292
3293 //===----------------------------------------------------------------------===//
3294 // Thread Local Storage Instructions
3295 //
3296
3297 // All calls clobber the non-callee saved registers. ESP is marked as
3298 // a use to prevent stack-pointer assignments that appear immediately
3299 // before calls from potentially appearing dead.
3300 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3301             MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3302             XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3303             XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
3304     Uses = [ESP] in
3305 def TLS_addr32 : I<0, Pseudo, (outs), (ins lea32mem:$sym),
3306                   "leal\t$sym, %eax; "
3307                   "call\t___tls_get_addr@PLT",
3308                   [(X86tlsaddr tls32addr:$sym)]>,
3309                   Requires<[In32BitMode]>;
3310
3311 let AddedComplexity = 5, isCodeGenOnly = 1 in
3312 def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3313                    "movl\t%gs:$src, $dst",
3314                    [(set GR32:$dst, (gsload addr:$src))]>, SegGS;
3315
3316 let AddedComplexity = 5, isCodeGenOnly = 1 in
3317 def FS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3318                    "movl\t%fs:$src, $dst",
3319                    [(set GR32:$dst, (fsload addr:$src))]>, SegFS;
3320
3321 //===----------------------------------------------------------------------===//
3322 // DWARF Pseudo Instructions
3323 //
3324
3325 def DWARF_LOC   : I<0, Pseudo, (outs),
3326                     (ins i32imm:$line, i32imm:$col, i32imm:$file),
3327                     ".loc\t$file $line $col",
3328                     [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
3329                       (i32 imm:$file))]>;
3330
3331 //===----------------------------------------------------------------------===//
3332 // EH Pseudo Instructions
3333 //
3334 let isTerminator = 1, isReturn = 1, isBarrier = 1,
3335     hasCtrlDep = 1, isCodeGenOnly = 1 in {
3336 def EH_RETURN   : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
3337                     "ret\t#eh_return, addr: $addr",
3338                     [(X86ehret GR32:$addr)]>;
3339
3340 }
3341
3342 //===----------------------------------------------------------------------===//
3343 // Atomic support
3344 //
3345
3346 // Atomic swap. These are just normal xchg instructions. But since a memory
3347 // operand is referenced, the atomicity is ensured.
3348 let Constraints = "$val = $dst" in {
3349 def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
3350                "xchg{l}\t{$val, $ptr|$ptr, $val}", 
3351                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
3352 def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
3353                "xchg{w}\t{$val, $ptr|$ptr, $val}", 
3354                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
3355                 OpSize;
3356 def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
3357                "xchg{b}\t{$val, $ptr|$ptr, $val}", 
3358                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
3359 }
3360
3361 // Atomic compare and swap.
3362 let Defs = [EAX, EFLAGS], Uses = [EAX] in {
3363 def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
3364                "lock\n\t"
3365                "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
3366                [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
3367 }
3368 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
3369 def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i32mem:$ptr),
3370                "lock\n\t"
3371                "cmpxchg8b\t$ptr",
3372                [(X86cas8 addr:$ptr)]>, TB, LOCK;
3373 }
3374
3375 let Defs = [AX, EFLAGS], Uses = [AX] in {
3376 def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
3377                "lock\n\t"
3378                "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
3379                [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
3380 }
3381 let Defs = [AL, EFLAGS], Uses = [AL] in {
3382 def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
3383                "lock\n\t"
3384                "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
3385                [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
3386 }
3387
3388 // Atomic exchange and add
3389 let Constraints = "$val = $dst", Defs = [EFLAGS] in {
3390 def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
3391                "lock\n\t"
3392                "xadd{l}\t{$val, $ptr|$ptr, $val}",
3393                [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
3394                 TB, LOCK;
3395 def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
3396                "lock\n\t"
3397                "xadd{w}\t{$val, $ptr|$ptr, $val}",
3398                [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
3399                 TB, OpSize, LOCK;
3400 def LXADD8  : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins i8mem:$ptr, GR8:$val),
3401                "lock\n\t"
3402                "xadd{b}\t{$val, $ptr|$ptr, $val}",
3403                [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
3404                 TB, LOCK;
3405 }
3406
3407 // Optimized codegen when the non-memory output is not used.
3408 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
3409 def LOCK_ADD8mr  : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
3410                     "lock\n\t"
3411                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3412 def LOCK_ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3413                     "lock\n\t"
3414                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3415 def LOCK_ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
3416                     "lock\n\t"
3417                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3418 def LOCK_ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
3419                     "lock\n\t"
3420                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3421 def LOCK_ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
3422                     "lock\n\t"
3423                      "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3424 def LOCK_ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
3425                     "lock\n\t"
3426                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3427 def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
3428                     "lock\n\t"
3429                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3430 def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3431                     "lock\n\t"
3432                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3433
3434 def LOCK_INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
3435                     "lock\n\t"
3436                     "inc{b}\t$dst", []>, LOCK;
3437 def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
3438                     "lock\n\t"
3439                     "inc{w}\t$dst", []>, OpSize, LOCK;
3440 def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
3441                     "lock\n\t"
3442                     "inc{l}\t$dst", []>, LOCK;
3443
3444 def LOCK_SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
3445                     "lock\n\t"
3446                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3447 def LOCK_SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3448                     "lock\n\t"
3449                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3450 def LOCK_SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3451                     "lock\n\t"
3452                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3453 def LOCK_SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
3454                     "lock\n\t"
3455                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3456 def LOCK_SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3457                     "lock\n\t"
3458                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3459 def LOCK_SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3460                     "lock\n\t"
3461                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3462 def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
3463                     "lock\n\t"
3464                      "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3465 def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3466                     "lock\n\t"
3467                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3468
3469 def LOCK_DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
3470                     "lock\n\t"
3471                     "dec{b}\t$dst", []>, LOCK;
3472 def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
3473                     "lock\n\t"
3474                     "dec{w}\t$dst", []>, OpSize, LOCK;
3475 def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
3476                     "lock\n\t"
3477                     "dec{l}\t$dst", []>, LOCK;
3478
3479 // Atomic exchange, and, or, xor
3480 let Constraints = "$val = $dst", Defs = [EFLAGS],
3481                   usesCustomDAGSchedInserter = 1 in {
3482 def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3483                "#ATOMAND32 PSEUDO!", 
3484                [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
3485 def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3486                "#ATOMOR32 PSEUDO!", 
3487                [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
3488 def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3489                "#ATOMXOR32 PSEUDO!", 
3490                [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
3491 def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3492                "#ATOMNAND32 PSEUDO!", 
3493                [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
3494 def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
3495                "#ATOMMIN32 PSEUDO!", 
3496                [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
3497 def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3498                "#ATOMMAX32 PSEUDO!", 
3499                [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
3500 def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3501                "#ATOMUMIN32 PSEUDO!", 
3502                [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
3503 def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3504                "#ATOMUMAX32 PSEUDO!", 
3505                [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
3506
3507 def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3508                "#ATOMAND16 PSEUDO!", 
3509                [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
3510 def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3511                "#ATOMOR16 PSEUDO!", 
3512                [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
3513 def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3514                "#ATOMXOR16 PSEUDO!", 
3515                [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
3516 def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3517                "#ATOMNAND16 PSEUDO!", 
3518                [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
3519 def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
3520                "#ATOMMIN16 PSEUDO!", 
3521                [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
3522 def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3523                "#ATOMMAX16 PSEUDO!", 
3524                [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
3525 def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3526                "#ATOMUMIN16 PSEUDO!", 
3527                [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
3528 def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3529                "#ATOMUMAX16 PSEUDO!", 
3530                [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
3531
3532 def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3533                "#ATOMAND8 PSEUDO!", 
3534                [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
3535 def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3536                "#ATOMOR8 PSEUDO!", 
3537                [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
3538 def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3539                "#ATOMXOR8 PSEUDO!", 
3540                [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
3541 def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3542                "#ATOMNAND8 PSEUDO!", 
3543                [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
3544 }
3545
3546 let Constraints = "$val1 = $dst1, $val2 = $dst2", 
3547                   Defs = [EFLAGS, EAX, EBX, ECX, EDX],
3548                   Uses = [EAX, EBX, ECX, EDX],
3549                   mayLoad = 1, mayStore = 1,
3550                   usesCustomDAGSchedInserter = 1 in {
3551 def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3552                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3553                "#ATOMAND6432 PSEUDO!", []>;
3554 def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3555                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3556                "#ATOMOR6432 PSEUDO!", []>;
3557 def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3558                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3559                "#ATOMXOR6432 PSEUDO!", []>;
3560 def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3561                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3562                "#ATOMNAND6432 PSEUDO!", []>;
3563 def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3564                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3565                "#ATOMADD6432 PSEUDO!", []>;
3566 def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3567                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3568                "#ATOMSUB6432 PSEUDO!", []>;
3569 def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3570                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3571                "#ATOMSWAP6432 PSEUDO!", []>;
3572 }
3573
3574 //===----------------------------------------------------------------------===//
3575 // Non-Instruction Patterns
3576 //===----------------------------------------------------------------------===//
3577
3578 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
3579 def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
3580 def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
3581 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
3582 def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
3583 def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
3584
3585 def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
3586           (ADD32ri GR32:$src1, tconstpool:$src2)>;
3587 def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
3588           (ADD32ri GR32:$src1, tjumptable:$src2)>;
3589 def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
3590           (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
3591 def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
3592           (ADD32ri GR32:$src1, texternalsym:$src2)>;
3593
3594 def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
3595           (MOV32mi addr:$dst, tglobaladdr:$src)>;
3596 def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
3597           (MOV32mi addr:$dst, texternalsym:$src)>;
3598
3599 // Calls
3600 // tailcall stuff
3601 def : Pat<(X86tcret GR32:$dst, imm:$off),
3602           (TCRETURNri GR32:$dst, imm:$off)>;
3603
3604 def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
3605           (TCRETURNdi texternalsym:$dst, imm:$off)>;
3606
3607 def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
3608           (TCRETURNdi texternalsym:$dst, imm:$off)>;
3609
3610 // Normal calls, with various flavors of addresses.
3611 def : Pat<(X86call (i32 tglobaladdr:$dst)),
3612           (CALLpcrel32 tglobaladdr:$dst)>;
3613 def : Pat<(X86call (i32 texternalsym:$dst)),
3614           (CALLpcrel32 texternalsym:$dst)>;
3615 def : Pat<(X86call (i32 imm:$dst)),
3616           (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
3617
3618 // X86 specific add which produces a flag.
3619 def : Pat<(addc GR32:$src1, GR32:$src2),
3620           (ADD32rr GR32:$src1, GR32:$src2)>;
3621 def : Pat<(addc GR32:$src1, (load addr:$src2)),
3622           (ADD32rm GR32:$src1, addr:$src2)>;
3623 def : Pat<(addc GR32:$src1, imm:$src2),
3624           (ADD32ri GR32:$src1, imm:$src2)>;
3625 def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
3626           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
3627
3628 def : Pat<(subc GR32:$src1, GR32:$src2),
3629           (SUB32rr GR32:$src1, GR32:$src2)>;
3630 def : Pat<(subc GR32:$src1, (load addr:$src2)),
3631           (SUB32rm GR32:$src1, addr:$src2)>;
3632 def : Pat<(subc GR32:$src1, imm:$src2),
3633           (SUB32ri GR32:$src1, imm:$src2)>;
3634 def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
3635           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
3636
3637 // Comparisons.
3638
3639 // TEST R,R is smaller than CMP R,0
3640 def : Pat<(parallel (X86cmp GR8:$src1, 0), (implicit EFLAGS)),
3641           (TEST8rr GR8:$src1, GR8:$src1)>;
3642 def : Pat<(parallel (X86cmp GR16:$src1, 0), (implicit EFLAGS)),
3643           (TEST16rr GR16:$src1, GR16:$src1)>;
3644 def : Pat<(parallel (X86cmp GR32:$src1, 0), (implicit EFLAGS)),
3645           (TEST32rr GR32:$src1, GR32:$src1)>;
3646
3647 // Conditional moves with folded loads with operands swapped and conditions
3648 // inverted.
3649 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS),
3650           (CMOVAE16rm GR16:$src2, addr:$src1)>;
3651 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS),
3652           (CMOVAE32rm GR32:$src2, addr:$src1)>;
3653 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS),
3654           (CMOVB16rm GR16:$src2, addr:$src1)>;
3655 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS),
3656           (CMOVB32rm GR32:$src2, addr:$src1)>;
3657 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS),
3658           (CMOVNE16rm GR16:$src2, addr:$src1)>;
3659 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS),
3660           (CMOVNE32rm GR32:$src2, addr:$src1)>;
3661 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS),
3662           (CMOVE16rm GR16:$src2, addr:$src1)>;
3663 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS),
3664           (CMOVE32rm GR32:$src2, addr:$src1)>;
3665 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS),
3666           (CMOVA16rm GR16:$src2, addr:$src1)>;
3667 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS),
3668           (CMOVA32rm GR32:$src2, addr:$src1)>;
3669 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS),
3670           (CMOVBE16rm GR16:$src2, addr:$src1)>;
3671 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS),
3672           (CMOVBE32rm GR32:$src2, addr:$src1)>;
3673 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS),
3674           (CMOVGE16rm GR16:$src2, addr:$src1)>;
3675 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS),
3676           (CMOVGE32rm GR32:$src2, addr:$src1)>;
3677 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS),
3678           (CMOVL16rm GR16:$src2, addr:$src1)>;
3679 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS),
3680           (CMOVL32rm GR32:$src2, addr:$src1)>;
3681 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS),
3682           (CMOVG16rm GR16:$src2, addr:$src1)>;
3683 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS),
3684           (CMOVG32rm GR32:$src2, addr:$src1)>;
3685 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS),
3686           (CMOVLE16rm GR16:$src2, addr:$src1)>;
3687 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS),
3688           (CMOVLE32rm GR32:$src2, addr:$src1)>;
3689 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS),
3690           (CMOVNP16rm GR16:$src2, addr:$src1)>;
3691 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS),
3692           (CMOVNP32rm GR32:$src2, addr:$src1)>;
3693 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS),
3694           (CMOVP16rm GR16:$src2, addr:$src1)>;
3695 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS),
3696           (CMOVP32rm GR32:$src2, addr:$src1)>;
3697 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS),
3698           (CMOVNS16rm GR16:$src2, addr:$src1)>;
3699 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS),
3700           (CMOVNS32rm GR32:$src2, addr:$src1)>;
3701 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS),
3702           (CMOVS16rm GR16:$src2, addr:$src1)>;
3703 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS),
3704           (CMOVS32rm GR32:$src2, addr:$src1)>;
3705 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS),
3706           (CMOVNO16rm GR16:$src2, addr:$src1)>;
3707 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS),
3708           (CMOVNO32rm GR32:$src2, addr:$src1)>;
3709 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS),
3710           (CMOVO16rm GR16:$src2, addr:$src1)>;
3711 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS),
3712           (CMOVO32rm GR32:$src2, addr:$src1)>;
3713
3714 // zextload bool -> zextload byte
3715 def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
3716 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
3717 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
3718
3719 // extload bool -> extload byte
3720 def : Pat<(extloadi8i1 addr:$src),   (MOV8rm      addr:$src)>;
3721 def : Pat<(extloadi16i1 addr:$src),  (MOVZX16rm8  addr:$src)>;
3722 def : Pat<(extloadi32i1 addr:$src),  (MOVZX32rm8  addr:$src)>;
3723 def : Pat<(extloadi16i8 addr:$src),  (MOVZX16rm8  addr:$src)>;
3724 def : Pat<(extloadi32i8 addr:$src),  (MOVZX32rm8  addr:$src)>;
3725 def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
3726
3727 // anyext. Define these to do an explicit zero-extend to
3728 // avoid partial-register updates.
3729 def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8  GR8 :$src)>;
3730 def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8  GR8 :$src)>;
3731 def : Pat<(i32 (anyext GR16:$src)), (MOVZX32rr16 GR16:$src)>;
3732
3733 // (and (i32 load), 255) -> (zextload i8)
3734 def : Pat<(i32 (and (nvloadi32 addr:$src), (i32 255))),
3735           (MOVZX32rm8 addr:$src)>;
3736 def : Pat<(i32 (and (nvloadi32 addr:$src), (i32 65535))),
3737           (MOVZX32rm16 addr:$src)>;
3738
3739 //===----------------------------------------------------------------------===//
3740 // Some peepholes
3741 //===----------------------------------------------------------------------===//
3742
3743 // Odd encoding trick: -128 fits into an 8-bit immediate field while
3744 // +128 doesn't, so in this special case use a sub instead of an add.
3745 def : Pat<(add GR16:$src1, 128),
3746           (SUB16ri8 GR16:$src1, -128)>;
3747 def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst),
3748           (SUB16mi8 addr:$dst, -128)>;
3749 def : Pat<(add GR32:$src1, 128),
3750           (SUB32ri8 GR32:$src1, -128)>;
3751 def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst),
3752           (SUB32mi8 addr:$dst, -128)>;
3753
3754 // r & (2^16-1) ==> movz
3755 def : Pat<(and GR32:$src1, 0xffff),
3756           (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, x86_subreg_16bit))>;
3757 // r & (2^8-1) ==> movz
3758 def : Pat<(and GR32:$src1, 0xff),
3759           (MOVZX32rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src1, GR32_ABCD),
3760                                       x86_subreg_8bit))>,
3761       Requires<[In32BitMode]>;
3762 // r & (2^8-1) ==> movz
3763 def : Pat<(and GR16:$src1, 0xff),
3764           (MOVZX16rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src1, GR16_ABCD),
3765                                       x86_subreg_8bit))>,
3766       Requires<[In32BitMode]>;
3767
3768 // sext_inreg patterns
3769 def : Pat<(sext_inreg GR32:$src, i16),
3770           (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, x86_subreg_16bit))>;
3771 def : Pat<(sext_inreg GR32:$src, i8),
3772           (MOVSX32rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
3773                                       x86_subreg_8bit))>,
3774       Requires<[In32BitMode]>;
3775 def : Pat<(sext_inreg GR16:$src, i8),
3776           (MOVSX16rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3777                                       x86_subreg_8bit))>,
3778       Requires<[In32BitMode]>;
3779
3780 // trunc patterns
3781 def : Pat<(i16 (trunc GR32:$src)),
3782           (EXTRACT_SUBREG GR32:$src, x86_subreg_16bit)>;
3783 def : Pat<(i8 (trunc GR32:$src)),
3784           (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
3785                           x86_subreg_8bit)>,
3786       Requires<[In32BitMode]>;
3787 def : Pat<(i8 (trunc GR16:$src)),
3788           (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3789                           x86_subreg_8bit)>,
3790       Requires<[In32BitMode]>;
3791
3792 // h-register tricks
3793 def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))),
3794           (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3795                           x86_subreg_8bit_hi)>,
3796       Requires<[In32BitMode]>;
3797 def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))),
3798           (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
3799                           x86_subreg_8bit_hi)>,
3800       Requires<[In32BitMode]>;
3801 def : Pat<(srl_su GR16:$src, (i8 8)),
3802           (EXTRACT_SUBREG
3803             (MOVZX32rr8
3804               (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3805                               x86_subreg_8bit_hi)),
3806             x86_subreg_16bit)>,
3807       Requires<[In32BitMode]>;
3808 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
3809           (MOVZX32rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3810                                       x86_subreg_8bit_hi))>,
3811       Requires<[In32BitMode]>;
3812 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
3813           (MOVZX32rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
3814                                       x86_subreg_8bit_hi))>,
3815       Requires<[In32BitMode]>;
3816 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
3817           (MOVZX32rr8 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
3818                                       x86_subreg_8bit_hi))>,
3819       Requires<[In32BitMode]>;
3820
3821 // (shl x, 1) ==> (add x, x)
3822 def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr  GR8 :$src1, GR8 :$src1)>;
3823 def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
3824 def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
3825
3826 // (shl x (and y, 31)) ==> (shl x, y)
3827 def : Pat<(shl GR8:$src1, (and CL:$amt, 31)),
3828           (SHL8rCL GR8:$src1)>;
3829 def : Pat<(shl GR16:$src1, (and CL:$amt, 31)),
3830           (SHL16rCL GR16:$src1)>;
3831 def : Pat<(shl GR32:$src1, (and CL:$amt, 31)),
3832           (SHL32rCL GR32:$src1)>;
3833 def : Pat<(store (shl (loadi8 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3834           (SHL8mCL addr:$dst)>;
3835 def : Pat<(store (shl (loadi16 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3836           (SHL16mCL addr:$dst)>;
3837 def : Pat<(store (shl (loadi32 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3838           (SHL32mCL addr:$dst)>;
3839
3840 def : Pat<(srl GR8:$src1, (and CL:$amt, 31)),
3841           (SHR8rCL GR8:$src1)>;
3842 def : Pat<(srl GR16:$src1, (and CL:$amt, 31)),
3843           (SHR16rCL GR16:$src1)>;
3844 def : Pat<(srl GR32:$src1, (and CL:$amt, 31)),
3845           (SHR32rCL GR32:$src1)>;
3846 def : Pat<(store (srl (loadi8 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3847           (SHR8mCL addr:$dst)>;
3848 def : Pat<(store (srl (loadi16 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3849           (SHR16mCL addr:$dst)>;
3850 def : Pat<(store (srl (loadi32 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3851           (SHR32mCL addr:$dst)>;
3852
3853 def : Pat<(sra GR8:$src1, (and CL:$amt, 31)),
3854           (SAR8rCL GR8:$src1)>;
3855 def : Pat<(sra GR16:$src1, (and CL:$amt, 31)),
3856           (SAR16rCL GR16:$src1)>;
3857 def : Pat<(sra GR32:$src1, (and CL:$amt, 31)),
3858           (SAR32rCL GR32:$src1)>;
3859 def : Pat<(store (sra (loadi8 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3860           (SAR8mCL addr:$dst)>;
3861 def : Pat<(store (sra (loadi16 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3862           (SAR16mCL addr:$dst)>;
3863 def : Pat<(store (sra (loadi32 addr:$dst), (and CL:$amt, 31)), addr:$dst),
3864           (SAR32mCL addr:$dst)>;
3865
3866 // (or (x >> c) | (y << (32 - c))) ==> (shrd32 x, y, c)
3867 def : Pat<(or (srl GR32:$src1, CL:$amt),
3868               (shl GR32:$src2, (sub 32, CL:$amt))),
3869           (SHRD32rrCL GR32:$src1, GR32:$src2)>;
3870
3871 def : Pat<(store (or (srl (loadi32 addr:$dst), CL:$amt),
3872                      (shl GR32:$src2, (sub 32, CL:$amt))), addr:$dst),
3873           (SHRD32mrCL addr:$dst, GR32:$src2)>;
3874
3875 def : Pat<(or (srl GR32:$src1, (i8 (trunc ECX:$amt))),
3876               (shl GR32:$src2, (i8 (trunc (sub 32, ECX:$amt))))),
3877           (SHRD32rrCL GR32:$src1, GR32:$src2)>;
3878
3879 def : Pat<(store (or (srl (loadi32 addr:$dst), (i8 (trunc ECX:$amt))),
3880                      (shl GR32:$src2, (i8 (trunc (sub 32, ECX:$amt))))),
3881                  addr:$dst),
3882           (SHRD32mrCL addr:$dst, GR32:$src2)>;
3883
3884 def : Pat<(shrd GR32:$src1, (i8 imm:$amt1), GR32:$src2, (i8 imm:$amt2)),
3885           (SHRD32rri8 GR32:$src1, GR32:$src2, (i8 imm:$amt1))>;
3886
3887 def : Pat<(store (shrd (loadi32 addr:$dst), (i8 imm:$amt1),
3888                        GR32:$src2, (i8 imm:$amt2)), addr:$dst),
3889           (SHRD32mri8 addr:$dst, GR32:$src2, (i8 imm:$amt1))>;
3890
3891 // (or (x << c) | (y >> (32 - c))) ==> (shld32 x, y, c)
3892 def : Pat<(or (shl GR32:$src1, CL:$amt),
3893               (srl GR32:$src2, (sub 32, CL:$amt))),
3894           (SHLD32rrCL GR32:$src1, GR32:$src2)>;
3895
3896 def : Pat<(store (or (shl (loadi32 addr:$dst), CL:$amt),
3897                      (srl GR32:$src2, (sub 32, CL:$amt))), addr:$dst),
3898           (SHLD32mrCL addr:$dst, GR32:$src2)>;
3899
3900 def : Pat<(or (shl GR32:$src1, (i8 (trunc ECX:$amt))),
3901               (srl GR32:$src2, (i8 (trunc (sub 32, ECX:$amt))))),
3902           (SHLD32rrCL GR32:$src1, GR32:$src2)>;
3903
3904 def : Pat<(store (or (shl (loadi32 addr:$dst), (i8 (trunc ECX:$amt))),
3905                      (srl GR32:$src2, (i8 (trunc (sub 32, ECX:$amt))))),
3906                  addr:$dst),
3907           (SHLD32mrCL addr:$dst, GR32:$src2)>;
3908
3909 def : Pat<(shld GR32:$src1, (i8 imm:$amt1), GR32:$src2, (i8 imm:$amt2)),
3910           (SHLD32rri8 GR32:$src1, GR32:$src2, (i8 imm:$amt1))>;
3911
3912 def : Pat<(store (shld (loadi32 addr:$dst), (i8 imm:$amt1),
3913                        GR32:$src2, (i8 imm:$amt2)), addr:$dst),
3914           (SHLD32mri8 addr:$dst, GR32:$src2, (i8 imm:$amt1))>;
3915
3916 // (or (x >> c) | (y << (16 - c))) ==> (shrd16 x, y, c)
3917 def : Pat<(or (srl GR16:$src1, CL:$amt),
3918               (shl GR16:$src2, (sub 16, CL:$amt))),
3919           (SHRD16rrCL GR16:$src1, GR16:$src2)>;
3920
3921 def : Pat<(store (or (srl (loadi16 addr:$dst), CL:$amt),
3922                      (shl GR16:$src2, (sub 16, CL:$amt))), addr:$dst),
3923           (SHRD16mrCL addr:$dst, GR16:$src2)>;
3924
3925 def : Pat<(or (srl GR16:$src1, (i8 (trunc CX:$amt))),
3926               (shl GR16:$src2, (i8 (trunc (sub 16, CX:$amt))))),
3927           (SHRD16rrCL GR16:$src1, GR16:$src2)>;
3928
3929 def : Pat<(store (or (srl (loadi16 addr:$dst), (i8 (trunc CX:$amt))),
3930                      (shl GR16:$src2, (i8 (trunc (sub 16, CX:$amt))))),
3931                  addr:$dst),
3932           (SHRD16mrCL addr:$dst, GR16:$src2)>;
3933
3934 def : Pat<(shrd GR16:$src1, (i8 imm:$amt1), GR16:$src2, (i8 imm:$amt2)),
3935           (SHRD16rri8 GR16:$src1, GR16:$src2, (i8 imm:$amt1))>;
3936
3937 def : Pat<(store (shrd (loadi16 addr:$dst), (i8 imm:$amt1),
3938                        GR16:$src2, (i8 imm:$amt2)), addr:$dst),
3939           (SHRD16mri8 addr:$dst, GR16:$src2, (i8 imm:$amt1))>;
3940
3941 // (or (x << c) | (y >> (16 - c))) ==> (shld16 x, y, c)
3942 def : Pat<(or (shl GR16:$src1, CL:$amt),
3943               (srl GR16:$src2, (sub 16, CL:$amt))),
3944           (SHLD16rrCL GR16:$src1, GR16:$src2)>;
3945
3946 def : Pat<(store (or (shl (loadi16 addr:$dst), CL:$amt),
3947                      (srl GR16:$src2, (sub 16, CL:$amt))), addr:$dst),
3948           (SHLD16mrCL addr:$dst, GR16:$src2)>;
3949
3950 def : Pat<(or (shl GR16:$src1, (i8 (trunc CX:$amt))),
3951               (srl GR16:$src2, (i8 (trunc (sub 16, CX:$amt))))),
3952           (SHLD16rrCL GR16:$src1, GR16:$src2)>;
3953
3954 def : Pat<(store (or (shl (loadi16 addr:$dst), (i8 (trunc CX:$amt))),
3955                      (srl GR16:$src2, (i8 (trunc (sub 16, CX:$amt))))),
3956                  addr:$dst),
3957           (SHLD16mrCL addr:$dst, GR16:$src2)>;
3958
3959 def : Pat<(shld GR16:$src1, (i8 imm:$amt1), GR16:$src2, (i8 imm:$amt2)),
3960           (SHLD16rri8 GR16:$src1, GR16:$src2, (i8 imm:$amt1))>;
3961
3962 def : Pat<(store (shld (loadi16 addr:$dst), (i8 imm:$amt1),
3963                        GR16:$src2, (i8 imm:$amt2)), addr:$dst),
3964           (SHLD16mri8 addr:$dst, GR16:$src2, (i8 imm:$amt1))>;
3965
3966 //===----------------------------------------------------------------------===//
3967 // EFLAGS-defining Patterns
3968 //===----------------------------------------------------------------------===//
3969
3970 // Register-Register Addition with EFLAGS result
3971 def : Pat<(parallel (X86add_flag GR8:$src1, GR8:$src2),
3972                     (implicit EFLAGS)),
3973           (ADD8rr GR8:$src1, GR8:$src2)>;
3974 def : Pat<(parallel (X86add_flag GR16:$src1, GR16:$src2),
3975                     (implicit EFLAGS)),
3976           (ADD16rr GR16:$src1, GR16:$src2)>;
3977 def : Pat<(parallel (X86add_flag GR32:$src1, GR32:$src2),
3978                     (implicit EFLAGS)),
3979           (ADD32rr GR32:$src1, GR32:$src2)>;
3980
3981 // Register-Memory Addition with EFLAGS result
3982 def : Pat<(parallel (X86add_flag GR8:$src1, (loadi8 addr:$src2)),
3983                     (implicit EFLAGS)),
3984           (ADD8rm GR8:$src1, addr:$src2)>;
3985 def : Pat<(parallel (X86add_flag GR16:$src1, (loadi16 addr:$src2)),
3986                     (implicit EFLAGS)),
3987           (ADD16rm GR16:$src1, addr:$src2)>;
3988 def : Pat<(parallel (X86add_flag GR32:$src1, (loadi32 addr:$src2)),
3989                     (implicit EFLAGS)),
3990           (ADD32rm GR32:$src1, addr:$src2)>;
3991
3992 // Register-Integer Addition with EFLAGS result
3993 def : Pat<(parallel (X86add_flag GR8:$src1, imm:$src2),
3994                     (implicit EFLAGS)),
3995           (ADD8ri GR8:$src1, imm:$src2)>;
3996 def : Pat<(parallel (X86add_flag GR16:$src1, imm:$src2),
3997                     (implicit EFLAGS)),
3998           (ADD16ri GR16:$src1, imm:$src2)>;
3999 def : Pat<(parallel (X86add_flag GR32:$src1, imm:$src2),
4000                     (implicit EFLAGS)),
4001           (ADD32ri GR32:$src1, imm:$src2)>;
4002 def : Pat<(parallel (X86add_flag GR16:$src1, i16immSExt8:$src2),
4003                     (implicit EFLAGS)),
4004           (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
4005 def : Pat<(parallel (X86add_flag GR32:$src1, i32immSExt8:$src2),
4006                     (implicit EFLAGS)),
4007           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4008
4009 // Memory-Register Addition with EFLAGS result
4010 def : Pat<(parallel (store (X86add_flag (loadi8 addr:$dst), GR8:$src2),
4011                            addr:$dst),
4012                     (implicit EFLAGS)),
4013           (ADD8mr addr:$dst, GR8:$src2)>;
4014 def : Pat<(parallel (store (X86add_flag (loadi16 addr:$dst), GR16:$src2),
4015                            addr:$dst),
4016                     (implicit EFLAGS)),
4017           (ADD16mr addr:$dst, GR16:$src2)>;
4018 def : Pat<(parallel (store (X86add_flag (loadi32 addr:$dst), GR32:$src2),
4019                            addr:$dst),
4020                     (implicit EFLAGS)),
4021           (ADD32mr addr:$dst, GR32:$src2)>;
4022
4023 // Memory-Integer Addition with EFLAGS result
4024 def : Pat<(parallel (store (X86add_flag (loadi8 addr:$dst), imm:$src2),
4025                            addr:$dst),
4026                     (implicit EFLAGS)),
4027           (ADD8mi addr:$dst, imm:$src2)>;
4028 def : Pat<(parallel (store (X86add_flag (loadi16 addr:$dst), imm:$src2),
4029                            addr:$dst),
4030                     (implicit EFLAGS)),
4031           (ADD16mi addr:$dst, imm:$src2)>;
4032 def : Pat<(parallel (store (X86add_flag (loadi32 addr:$dst), imm:$src2),
4033                            addr:$dst),
4034                     (implicit EFLAGS)),
4035           (ADD32mi addr:$dst, imm:$src2)>;
4036 def : Pat<(parallel (store (X86add_flag (loadi16 addr:$dst), i16immSExt8:$src2),
4037                            addr:$dst),
4038                     (implicit EFLAGS)),
4039           (ADD16mi8 addr:$dst, i16immSExt8:$src2)>;
4040 def : Pat<(parallel (store (X86add_flag (loadi32 addr:$dst), i32immSExt8:$src2),
4041                            addr:$dst),
4042                     (implicit EFLAGS)),
4043           (ADD32mi8 addr:$dst, i32immSExt8:$src2)>;
4044
4045 // Register-Register Subtraction with EFLAGS result
4046 def : Pat<(parallel (X86sub_flag GR8:$src1, GR8:$src2),
4047                     (implicit EFLAGS)),
4048           (SUB8rr GR8:$src1, GR8:$src2)>;
4049 def : Pat<(parallel (X86sub_flag GR16:$src1, GR16:$src2),
4050                     (implicit EFLAGS)),
4051           (SUB16rr GR16:$src1, GR16:$src2)>;
4052 def : Pat<(parallel (X86sub_flag GR32:$src1, GR32:$src2),
4053                     (implicit EFLAGS)),
4054           (SUB32rr GR32:$src1, GR32:$src2)>;
4055
4056 // Register-Memory Subtraction with EFLAGS result
4057 def : Pat<(parallel (X86sub_flag GR8:$src1, (loadi8 addr:$src2)),
4058                     (implicit EFLAGS)),
4059           (SUB8rm GR8:$src1, addr:$src2)>;
4060 def : Pat<(parallel (X86sub_flag GR16:$src1, (loadi16 addr:$src2)),
4061                     (implicit EFLAGS)),
4062           (SUB16rm GR16:$src1, addr:$src2)>;
4063 def : Pat<(parallel (X86sub_flag GR32:$src1, (loadi32 addr:$src2)),
4064                     (implicit EFLAGS)),
4065           (SUB32rm GR32:$src1, addr:$src2)>;
4066
4067 // Register-Integer Subtraction with EFLAGS result
4068 def : Pat<(parallel (X86sub_flag GR8:$src1, imm:$src2),
4069                     (implicit EFLAGS)),
4070           (SUB8ri GR8:$src1, imm:$src2)>;
4071 def : Pat<(parallel (X86sub_flag GR16:$src1, imm:$src2),
4072                     (implicit EFLAGS)),
4073           (SUB16ri GR16:$src1, imm:$src2)>;
4074 def : Pat<(parallel (X86sub_flag GR32:$src1, imm:$src2),
4075                     (implicit EFLAGS)),
4076           (SUB32ri GR32:$src1, imm:$src2)>;
4077 def : Pat<(parallel (X86sub_flag GR16:$src1, i16immSExt8:$src2),
4078                     (implicit EFLAGS)),
4079           (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>;
4080 def : Pat<(parallel (X86sub_flag GR32:$src1, i32immSExt8:$src2),
4081                     (implicit EFLAGS)),
4082           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4083
4084 // Memory-Register Subtraction with EFLAGS result
4085 def : Pat<(parallel (store (X86sub_flag (loadi8 addr:$dst), GR8:$src2),
4086                            addr:$dst),
4087                     (implicit EFLAGS)),
4088           (SUB8mr addr:$dst, GR8:$src2)>;
4089 def : Pat<(parallel (store (X86sub_flag (loadi16 addr:$dst), GR16:$src2),
4090                            addr:$dst),
4091                     (implicit EFLAGS)),
4092           (SUB16mr addr:$dst, GR16:$src2)>;
4093 def : Pat<(parallel (store (X86sub_flag (loadi32 addr:$dst), GR32:$src2),
4094                            addr:$dst),
4095                     (implicit EFLAGS)),
4096           (SUB32mr addr:$dst, GR32:$src2)>;
4097
4098 // Memory-Integer Subtraction with EFLAGS result
4099 def : Pat<(parallel (store (X86sub_flag (loadi8 addr:$dst), imm:$src2),
4100                            addr:$dst),
4101                     (implicit EFLAGS)),
4102           (SUB8mi addr:$dst, imm:$src2)>;
4103 def : Pat<(parallel (store (X86sub_flag (loadi16 addr:$dst), imm:$src2),
4104                            addr:$dst),
4105                     (implicit EFLAGS)),
4106           (SUB16mi addr:$dst, imm:$src2)>;
4107 def : Pat<(parallel (store (X86sub_flag (loadi32 addr:$dst), imm:$src2),
4108                            addr:$dst),
4109                     (implicit EFLAGS)),
4110           (SUB32mi addr:$dst, imm:$src2)>;
4111 def : Pat<(parallel (store (X86sub_flag (loadi16 addr:$dst), i16immSExt8:$src2),
4112                            addr:$dst),
4113                     (implicit EFLAGS)),
4114           (SUB16mi8 addr:$dst, i16immSExt8:$src2)>;
4115 def : Pat<(parallel (store (X86sub_flag (loadi32 addr:$dst), i32immSExt8:$src2),
4116                            addr:$dst),
4117                     (implicit EFLAGS)),
4118           (SUB32mi8 addr:$dst, i32immSExt8:$src2)>;
4119
4120
4121 // Register-Register Signed Integer Multiply with EFLAGS result
4122 def : Pat<(parallel (X86smul_flag GR16:$src1, GR16:$src2),
4123                     (implicit EFLAGS)),
4124           (IMUL16rr GR16:$src1, GR16:$src2)>;
4125 def : Pat<(parallel (X86smul_flag GR32:$src1, GR32:$src2),
4126                     (implicit EFLAGS)),
4127           (IMUL32rr GR32:$src1, GR32:$src2)>;
4128
4129 // Register-Memory Signed Integer Multiply with EFLAGS result
4130 def : Pat<(parallel (X86smul_flag GR16:$src1, (loadi16 addr:$src2)),
4131                     (implicit EFLAGS)),
4132           (IMUL16rm GR16:$src1, addr:$src2)>;
4133 def : Pat<(parallel (X86smul_flag GR32:$src1, (loadi32 addr:$src2)),
4134                     (implicit EFLAGS)),
4135           (IMUL32rm GR32:$src1, addr:$src2)>;
4136
4137 // Register-Integer Signed Integer Multiply with EFLAGS result
4138 def : Pat<(parallel (X86smul_flag GR16:$src1, imm:$src2),
4139                     (implicit EFLAGS)),
4140           (IMUL16rri GR16:$src1, imm:$src2)>;
4141 def : Pat<(parallel (X86smul_flag GR32:$src1, imm:$src2),
4142                     (implicit EFLAGS)),
4143           (IMUL32rri GR32:$src1, imm:$src2)>;
4144 def : Pat<(parallel (X86smul_flag GR16:$src1, i16immSExt8:$src2),
4145                     (implicit EFLAGS)),
4146           (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>;
4147 def : Pat<(parallel (X86smul_flag GR32:$src1, i32immSExt8:$src2),
4148                     (implicit EFLAGS)),
4149           (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>;
4150
4151 // Memory-Integer Signed Integer Multiply with EFLAGS result
4152 def : Pat<(parallel (X86smul_flag (loadi16 addr:$src1), imm:$src2),
4153                     (implicit EFLAGS)),
4154           (IMUL16rmi addr:$src1, imm:$src2)>;
4155 def : Pat<(parallel (X86smul_flag (loadi32 addr:$src1), imm:$src2),
4156                     (implicit EFLAGS)),
4157           (IMUL32rmi addr:$src1, imm:$src2)>;
4158 def : Pat<(parallel (X86smul_flag (loadi16 addr:$src1), i16immSExt8:$src2),
4159                     (implicit EFLAGS)),
4160           (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>;
4161 def : Pat<(parallel (X86smul_flag (loadi32 addr:$src1), i32immSExt8:$src2),
4162                     (implicit EFLAGS)),
4163           (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>;
4164
4165 // Optimize multiply by 2 with EFLAGS result.
4166 let AddedComplexity = 2 in {
4167 def : Pat<(parallel (X86smul_flag GR16:$src1, 2),
4168                     (implicit EFLAGS)),
4169           (ADD16rr GR16:$src1, GR16:$src1)>;
4170
4171 def : Pat<(parallel (X86smul_flag GR32:$src1, 2),
4172                     (implicit EFLAGS)),
4173           (ADD32rr GR32:$src1, GR32:$src1)>;
4174 }
4175
4176 // INC and DEC with EFLAGS result. Note that these do not set CF.
4177 def : Pat<(parallel (X86inc_flag GR8:$src), (implicit EFLAGS)),
4178           (INC8r GR8:$src)>;
4179 def : Pat<(parallel (store (i8 (X86inc_flag (loadi8 addr:$dst))), addr:$dst),
4180                     (implicit EFLAGS)),
4181           (INC8m addr:$dst)>;
4182 def : Pat<(parallel (X86dec_flag GR8:$src), (implicit EFLAGS)),
4183           (DEC8r GR8:$src)>;
4184 def : Pat<(parallel (store (i8 (X86dec_flag (loadi8 addr:$dst))), addr:$dst),
4185                     (implicit EFLAGS)),
4186           (DEC8m addr:$dst)>;
4187
4188 def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
4189           (INC16r GR16:$src)>, Requires<[In32BitMode]>;
4190 def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
4191                     (implicit EFLAGS)),
4192           (INC16m addr:$dst)>, Requires<[In32BitMode]>;
4193 def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
4194           (DEC16r GR16:$src)>, Requires<[In32BitMode]>;
4195 def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
4196                     (implicit EFLAGS)),
4197           (DEC16m addr:$dst)>, Requires<[In32BitMode]>;
4198
4199 def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
4200           (INC32r GR32:$src)>, Requires<[In32BitMode]>;
4201 def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
4202                     (implicit EFLAGS)),
4203           (INC32m addr:$dst)>, Requires<[In32BitMode]>;
4204 def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
4205           (DEC32r GR32:$src)>, Requires<[In32BitMode]>;
4206 def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
4207                     (implicit EFLAGS)),
4208           (DEC32m addr:$dst)>, Requires<[In32BitMode]>;
4209
4210 // -disable-16bit support.
4211 def : Pat<(truncstorei16 (i32 imm:$src), addr:$dst),
4212           (MOV16mi addr:$dst, imm:$src)>;
4213 def : Pat<(truncstorei16 GR32:$src, addr:$dst),
4214           (MOV16mr addr:$dst, (EXTRACT_SUBREG GR32:$src, x86_subreg_16bit))>;
4215 def : Pat<(i32 (sextloadi16 addr:$dst)),
4216           (MOVSX32rm16 addr:$dst)>;
4217 def : Pat<(i32 (zextloadi16 addr:$dst)),
4218           (MOVZX32rm16 addr:$dst)>;
4219 def : Pat<(i32 (extloadi16 addr:$dst)),
4220           (MOVZX32rm16 addr:$dst)>;
4221
4222 //===----------------------------------------------------------------------===//
4223 // Floating Point Stack Support
4224 //===----------------------------------------------------------------------===//
4225
4226 include "X86InstrFPStack.td"
4227
4228 //===----------------------------------------------------------------------===//
4229 // X86-64 Support
4230 //===----------------------------------------------------------------------===//
4231
4232 include "X86Instr64bit.td"
4233
4234 //===----------------------------------------------------------------------===//
4235 // XMM Floating point support (requires SSE / SSE2)
4236 //===----------------------------------------------------------------------===//
4237
4238 include "X86InstrSSE.td"
4239
4240 //===----------------------------------------------------------------------===//
4241 // MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
4242 //===----------------------------------------------------------------------===//
4243
4244 include "X86InstrMMX.td"