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