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