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