blob: 36e493a7c11dbcf5b502fefd57735c7e983fbdd4 [file] [log] [blame]
Chris Lattner589ad5d2010-03-25 05:44:01 +00001//===----------------------------------------------------------------------===//
John Criswell856ba762003-10-21 15:17:13 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
John Criswell856ba762003-10-21 15:17:13 +00007//
8//===----------------------------------------------------------------------===//
Chris Lattner1cca5e32003-08-03 21:54:21 +00009//
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
Evan Chengaed7c722005-12-17 01:24:02 +000016//===----------------------------------------------------------------------===//
17// X86 specific DAG Nodes.
18//
19
Evan Chenge3413162006-01-09 18:33:28 +000020def SDTIntShiftDOp: SDTypeProfile<1, 3,
21 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22 SDTCisInt<0>, SDTCisInt<3>]>;
23
Chris Lattnere3486a42010-03-19 00:01:11 +000024def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000025
Evan Chenge5f62042007-09-29 00:00:36 +000026def SDTX86Cmov : SDTypeProfile<1, 4,
Evan Cheng0488db92007-09-25 01:57:46 +000027 [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28 SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000029
Dan Gohman076aee32009-03-04 19:44:21 +000030// Unary and binary operator instructions that set EFLAGS as a side-effect.
Chris Lattner74c8d672010-03-24 00:47:47 +000031def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
32 [SDTCisInt<0>, SDTCisVT<1, i32>]>;
33
Chris Lattner1aec4d72010-03-24 00:49:29 +000034def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
35 [SDTCisSameAs<0, 2>,
36 SDTCisSameAs<0, 3>,
37 SDTCisInt<0>, SDTCisVT<1, i32>]>;
Evan Chenge5f62042007-09-29 00:00:36 +000038def SDTX86BrCond : SDTypeProfile<0, 3,
Evan Cheng0488db92007-09-25 01:57:46 +000039 [SDTCisVT<0, OtherVT>,
40 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000041
Evan Chenge5f62042007-09-29 00:00:36 +000042def SDTX86SetCC : SDTypeProfile<1, 2,
Evan Cheng0488db92007-09-25 01:57:46 +000043 [SDTCisVT<0, i8>,
44 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Cheng2e489c42009-12-16 00:53:11 +000045def SDTX86SetCC_C : SDTypeProfile<1, 2,
46 [SDTCisInt<0>,
47 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Chengd5781fc2005-12-21 20:21:51 +000048
Andrew Lenharth26ed8692008-03-01 21:52:34 +000049def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>,
50 SDTCisVT<2, i8>]>;
Andrew Lenharthd19189e2008-03-05 01:15:49 +000051def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
Andrew Lenharth26ed8692008-03-01 21:52:34 +000052
Dale Johannesen48c1bc22008-10-02 18:53:47 +000053def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
54 SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
Chris Lattner447ff682008-03-11 03:23:40 +000055def SDTX86Ret : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
Evan Cheng898101c2005-12-19 23:12:38 +000056
Sean Callanan1c97ceb2009-06-23 23:25:37 +000057def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
58def SDT_X86CallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>,
59 SDTCisVT<1, i32>]>;
Evan Chenge3413162006-01-09 18:33:28 +000060
Dan Gohmand35121a2008-05-29 19:57:41 +000061def SDT_X86Call : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
Evan Chenge3413162006-01-09 18:33:28 +000062
Dan Gohmand6708ea2009-08-15 01:38:56 +000063def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
64 SDTCisVT<1, iPTR>,
65 SDTCisVT<2, iPTR>]>;
66
Chris Lattnered52c8f2010-03-28 07:38:39 +000067def SDTX86RepStr : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
68
Anton Korobeynikov043f3c22010-03-06 19:32:29 +000069def SDTX86Void : SDTypeProfile<0, 0, []>;
Evan Chengd90eb7f2006-01-05 00:27:02 +000070
Evan Cheng71fb8342006-02-25 10:02:21 +000071def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
72
Rafael Espindola2ee3db32009-04-17 14:35:58 +000073def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +000074
Eric Christopher30ef0e52010-06-03 04:07:48 +000075def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
76
Rafael Espindola094fad32009-04-08 21:14:34 +000077def SDT_X86SegmentBaseAddress : SDTypeProfile<1, 1, [SDTCisPtrTy<0>]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +000078
Anton Korobeynikov2365f512007-07-14 14:06:15 +000079def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
80
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000081def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
82
Chris Lattnerd486d772010-03-28 05:07:17 +000083def X86bsf : SDNode<"X86ISD::BSF", SDTUnaryArithWithFlags>;
84def X86bsr : SDNode<"X86ISD::BSR", SDTUnaryArithWithFlags>;
Evan Chenge3413162006-01-09 18:33:28 +000085def X86shld : SDNode<"X86ISD::SHLD", SDTIntShiftDOp>;
86def X86shrd : SDNode<"X86ISD::SHRD", SDTIntShiftDOp>;
Evan Chengb077b842005-12-21 02:39:21 +000087
Evan Chenge5f62042007-09-29 00:00:36 +000088def X86cmp : SDNode<"X86ISD::CMP" , SDTX86CmpTest>;
Dan Gohmanc7a37d42008-12-23 22:45:23 +000089def X86bt : SDNode<"X86ISD::BT", SDTX86CmpTest>;
90
Evan Chenge5f62042007-09-29 00:00:36 +000091def X86cmov : SDNode<"X86ISD::CMOV", SDTX86Cmov>;
Evan Chenge3413162006-01-09 18:33:28 +000092def X86brcond : SDNode<"X86ISD::BRCOND", SDTX86BrCond,
Evan Cheng0488db92007-09-25 01:57:46 +000093 [SDNPHasChain]>;
Evan Chenge5f62042007-09-29 00:00:36 +000094def X86setcc : SDNode<"X86ISD::SETCC", SDTX86SetCC>;
Evan Cheng2e489c42009-12-16 00:53:11 +000095def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
Evan Chengb077b842005-12-21 02:39:21 +000096
Andrew Lenharth26ed8692008-03-01 21:52:34 +000097def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
98 [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
99 SDNPMayLoad]>;
Andrew Lenharthd19189e2008-03-05 01:15:49 +0000100def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
101 [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
102 SDNPMayLoad]>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000103def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
104 [SDNPHasChain, SDNPMayStore,
105 SDNPMayLoad, SDNPMemOperand]>;
106def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
107 [SDNPHasChain, SDNPMayStore,
108 SDNPMayLoad, SDNPMemOperand]>;
109def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
110 [SDNPHasChain, SDNPMayStore,
111 SDNPMayLoad, SDNPMemOperand]>;
112def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
113 [SDNPHasChain, SDNPMayStore,
114 SDNPMayLoad, SDNPMemOperand]>;
115def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
116 [SDNPHasChain, SDNPMayStore,
117 SDNPMayLoad, SDNPMemOperand]>;
118def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
119 [SDNPHasChain, SDNPMayStore,
120 SDNPMayLoad, SDNPMemOperand]>;
Dale Johannesen880ae362008-10-03 22:25:52 +0000121def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
122 [SDNPHasChain, SDNPMayStore,
123 SDNPMayLoad, SDNPMemOperand]>;
Evan Chenge3413162006-01-09 18:33:28 +0000124def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000125 [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
Evan Chengb077b842005-12-21 02:39:21 +0000126
Dan Gohmand6708ea2009-08-15 01:38:56 +0000127def X86vastart_save_xmm_regs :
128 SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
129 SDT_X86VASTART_SAVE_XMM_REGS,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000130 [SDNPHasChain, SDNPVariadic]>;
Dan Gohmand6708ea2009-08-15 01:38:56 +0000131
Evan Chenge3413162006-01-09 18:33:28 +0000132def X86callseq_start :
133 SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
Evan Chengbb7b8442006-08-11 09:03:33 +0000134 [SDNPHasChain, SDNPOutFlag]>;
Evan Chenge3413162006-01-09 18:33:28 +0000135def X86callseq_end :
136 SDNode<"ISD::CALLSEQ_END", SDT_X86CallSeqEnd,
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000137 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Evan Chengb077b842005-12-21 02:39:21 +0000138
Evan Chenge3413162006-01-09 18:33:28 +0000139def X86call : SDNode<"X86ISD::CALL", SDT_X86Call,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000140 [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
141 SDNPVariadic]>;
Evan Chengaed7c722005-12-17 01:24:02 +0000142
Chris Lattnered52c8f2010-03-28 07:38:39 +0000143def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
Chris Lattner9b37aaf2008-01-10 05:12:37 +0000144 [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
Chris Lattnered52c8f2010-03-28 07:38:39 +0000145def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
Chris Lattner9b37aaf2008-01-10 05:12:37 +0000146 [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
147 SDNPMayLoad]>;
Evan Cheng67f92a72006-01-11 22:15:48 +0000148
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000149def X86rdtsc : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
Chris Lattnerba7e7562008-01-10 07:59:24 +0000150 [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
Evan Chengd90eb7f2006-01-05 00:27:02 +0000151
Evan Cheng0085a282006-11-30 21:55:46 +0000152def X86Wrapper : SDNode<"X86ISD::Wrapper", SDTX86Wrapper>;
153def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP", SDTX86Wrapper>;
Evan Cheng71fb8342006-02-25 10:02:21 +0000154
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000155def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
Anton Korobeynikov6625eff2008-05-04 21:36:32 +0000156 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Rafael Espindola094fad32009-04-08 21:14:34 +0000157def X86SegmentBaseAddress : SDNode<"X86ISD::SegmentBaseAddress",
158 SDT_X86SegmentBaseAddress, []>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000159
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000160def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
161 [SDNPHasChain]>;
162
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000163def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000164 [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000165
Dan Gohman43ffe672010-01-04 20:51:05 +0000166def X86add_flag : SDNode<"X86ISD::ADD", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000167 [SDNPCommutative]>;
Dan Gohman076aee32009-03-04 19:44:21 +0000168def X86sub_flag : SDNode<"X86ISD::SUB", SDTBinaryArithWithFlags>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000169def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000170 [SDNPCommutative]>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000171def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000172 [SDNPCommutative]>;
Chris Lattner74c8d672010-03-24 00:47:47 +0000173
Dan Gohman076aee32009-03-04 19:44:21 +0000174def X86inc_flag : SDNode<"X86ISD::INC", SDTUnaryArithWithFlags>;
175def X86dec_flag : SDNode<"X86ISD::DEC", SDTUnaryArithWithFlags>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000176def X86or_flag : SDNode<"X86ISD::OR", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000177 [SDNPCommutative]>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000178def X86xor_flag : SDNode<"X86ISD::XOR", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000179 [SDNPCommutative]>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000180def X86and_flag : SDNode<"X86ISD::AND", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000181 [SDNPCommutative]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +0000182
Evan Cheng73f24c92009-03-30 21:36:47 +0000183def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
184
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000185def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
186 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
Eric Christopher30ef0e52010-06-03 04:07:48 +0000187
188def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
189 []>;
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000190
Evan Chengaed7c722005-12-17 01:24:02 +0000191//===----------------------------------------------------------------------===//
192// X86 Operand Definitions.
193//
194
Dan Gohmana4714e02009-07-30 01:56:29 +0000195// A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
196// the index operand of an address, to conform to x86 encoding restrictions.
197def ptr_rc_nosp : PointerLikeRegClass<1>;
Chris Lattner7680e732009-06-20 19:34:09 +0000198
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000199// *mem - Operand definitions for the funky X86 addressing mode operands.
200//
Daniel Dunbar338825c2009-08-10 18:41:10 +0000201def X86MemAsmOperand : AsmOperandClass {
202 let Name = "Mem";
Daniel Dunbar54ddf3d2010-05-22 21:02:29 +0000203 let SuperClasses = [];
Daniel Dunbar338825c2009-08-10 18:41:10 +0000204}
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000205def X86NoSegMemAsmOperand : AsmOperandClass {
206 let Name = "NoSegMem";
Daniel Dunbar54ddf3d2010-05-22 21:02:29 +0000207 let SuperClasses = [X86MemAsmOperand];
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000208}
Daniel Dunbarc26ae5a2010-05-06 22:39:14 +0000209def X86AbsMemAsmOperand : AsmOperandClass {
210 let Name = "AbsMem";
Daniel Dunbar54ddf3d2010-05-22 21:02:29 +0000211 let SuperClasses = [X86NoSegMemAsmOperand];
Daniel Dunbarc26ae5a2010-05-06 22:39:14 +0000212}
Evan Chengaf78ef52006-05-17 21:21:41 +0000213class X86MemOperand<string printMethod> : Operand<iPTR> {
Nate Begeman391c5d22005-11-30 18:54:35 +0000214 let PrintMethod = printMethod;
Dan Gohmana4714e02009-07-30 01:56:29 +0000215 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar338825c2009-08-10 18:41:10 +0000216 let ParserMatchClass = X86MemAsmOperand;
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000217}
Nate Begeman391c5d22005-11-30 18:54:35 +0000218
Sean Callanan9947bbb2009-09-03 00:04:47 +0000219def opaque32mem : X86MemOperand<"printopaquemem">;
220def opaque48mem : X86MemOperand<"printopaquemem">;
221def opaque80mem : X86MemOperand<"printopaquemem">;
Sean Callanan108934c2009-12-18 00:01:26 +0000222def opaque512mem : X86MemOperand<"printopaquemem">;
223
Chris Lattner45432512005-12-17 19:47:05 +0000224def i8mem : X86MemOperand<"printi8mem">;
225def i16mem : X86MemOperand<"printi16mem">;
226def i32mem : X86MemOperand<"printi32mem">;
227def i64mem : X86MemOperand<"printi64mem">;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000228def i128mem : X86MemOperand<"printi128mem">;
Chris Lattnere895c612009-09-20 07:17:49 +0000229//def i256mem : X86MemOperand<"printi256mem">;
Chris Lattner45432512005-12-17 19:47:05 +0000230def f32mem : X86MemOperand<"printf32mem">;
231def f64mem : X86MemOperand<"printf64mem">;
Dale Johannesen59a58732007-08-05 18:49:15 +0000232def f80mem : X86MemOperand<"printf80mem">;
Evan Cheng223547a2006-01-31 22:28:30 +0000233def f128mem : X86MemOperand<"printf128mem">;
Chris Lattnere895c612009-09-20 07:17:49 +0000234//def f256mem : X86MemOperand<"printf256mem">;
Nate Begeman391c5d22005-11-30 18:54:35 +0000235
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000236// A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
237// plain GR64, so that it doesn't potentially require a REX prefix.
238def i8mem_NOREX : Operand<i64> {
239 let PrintMethod = "printi8mem";
Dan Gohmana4714e02009-07-30 01:56:29 +0000240 let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
Daniel Dunbar338825c2009-08-10 18:41:10 +0000241 let ParserMatchClass = X86MemAsmOperand;
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000242}
243
Evan Chengf48ef032010-03-14 03:48:46 +0000244// Special i32mem for addresses of load folding tail calls. These are not
245// allowed to use callee-saved registers since they must be scheduled
246// after callee-saved register are popped.
247def i32mem_TC : Operand<i32> {
248 let PrintMethod = "printi32mem";
249 let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
250 let ParserMatchClass = X86MemAsmOperand;
251}
252
Evan Cheng25ab6902006-09-08 06:48:29 +0000253def lea32mem : Operand<i32> {
Rafael Espindola094fad32009-04-08 21:14:34 +0000254 let PrintMethod = "printlea32mem";
Dan Gohman74f6f9a2009-08-05 17:40:24 +0000255 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000256 let ParserMatchClass = X86NoSegMemAsmOperand;
Evan Cheng25ab6902006-09-08 06:48:29 +0000257}
258
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000259let ParserMatchClass = X86AbsMemAsmOperand,
260 PrintMethod = "print_pcrel_imm" in {
Daniel Dunbar728e5eb2010-01-30 00:24:12 +0000261def i32imm_pcrel : Operand<i32>;
262
263def offset8 : Operand<i64>;
264def offset16 : Operand<i64>;
265def offset32 : Operand<i64>;
266def offset64 : Operand<i64>;
267
268// Branch targets have OtherVT type and print as pc-relative values.
269def brtarget : Operand<OtherVT>;
270def brtarget8 : Operand<OtherVT>;
271
272}
273
Nate Begeman16b04f32005-07-15 00:38:55 +0000274def SSECC : Operand<i8> {
275 let PrintMethod = "printSSECC";
276}
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000277
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000278class ImmSExtAsmOperandClass : AsmOperandClass {
Daniel Dunbar54ddf3d2010-05-22 21:02:29 +0000279 let SuperClasses = [ImmAsmOperand];
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000280 let RenderMethod = "addImmOperands";
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000281}
282
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000283// Sign-extended immediate classes. We don't need to define the full lattice
284// here because there is no instruction with an ambiguity between ImmSExti64i32
285// and ImmSExti32i8.
286//
287// The strange ranges come from the fact that the assembler always works with
288// 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
289// (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
290
291// [0, 0x7FFFFFFF] | [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
292def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
293 let Name = "ImmSExti64i32";
294}
295
296// [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] | [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
297def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
298 let Name = "ImmSExti16i8";
299 let SuperClasses = [ImmSExti64i32AsmOperand];
300}
301
302// [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] | [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
303def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
304 let Name = "ImmSExti32i8";
305}
306
307// [0, 0x0000007F] | [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
308def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
309 let Name = "ImmSExti64i8";
310 let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand, ImmSExti64i32AsmOperand];
Daniel Dunbar338825c2009-08-10 18:41:10 +0000311}
312
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000313// A couple of more descriptive operand definitions.
314// 16-bits but only 8 bits are significant.
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000315def i16i8imm : Operand<i16> {
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000316 let ParserMatchClass = ImmSExti16i8AsmOperand;
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000317}
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000318// 32-bits but only 8 bits are significant.
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000319def i32i8imm : Operand<i32> {
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000320 let ParserMatchClass = ImmSExti32i8AsmOperand;
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000321}
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000322
Evan Chengaed7c722005-12-17 01:24:02 +0000323//===----------------------------------------------------------------------===//
324// X86 Complex Pattern Definitions.
325//
326
Evan Chengec693f72005-12-08 02:01:35 +0000327// Define X86 specific addressing mode.
Rafael Espindola094fad32009-04-08 21:14:34 +0000328def addr : ComplexPattern<iPTR, 5, "SelectAddr", [], []>;
Evan Cheng25ab6902006-09-08 06:48:29 +0000329def lea32addr : ComplexPattern<i32, 4, "SelectLEAAddr",
Dan Gohmana98634b2009-08-02 16:09:17 +0000330 [add, sub, mul, X86mul_imm, shl, or, frameindex],
331 []>;
Chris Lattner5c0b16d2009-06-20 20:38:48 +0000332def tls32addr : ComplexPattern<i32, 4, "SelectTLSADDRAddr",
333 [tglobaltlsaddr], []>;
Evan Chengec693f72005-12-08 02:01:35 +0000334
Evan Chengaed7c722005-12-17 01:24:02 +0000335//===----------------------------------------------------------------------===//
Evan Chengbbc8ddb2005-12-20 22:59:51 +0000336// X86 Instruction Predicate Definitions.
Chris Lattner314a1132010-03-14 18:31:44 +0000337def HasCMov : Predicate<"Subtarget->hasCMov()">;
338def NoCMov : Predicate<"!Subtarget->hasCMov()">;
Evan Cheng28b514392006-12-05 19:50:18 +0000339def HasMMX : Predicate<"Subtarget->hasMMX()">;
340def HasSSE1 : Predicate<"Subtarget->hasSSE1()">;
341def HasSSE2 : Predicate<"Subtarget->hasSSE2()">;
342def HasSSE3 : Predicate<"Subtarget->hasSSE3()">;
Bill Wendlingbb1ee052007-04-10 22:10:25 +0000343def HasSSSE3 : Predicate<"Subtarget->hasSSSE3()">;
Nate Begeman63ec90a2008-02-03 07:18:54 +0000344def HasSSE41 : Predicate<"Subtarget->hasSSE41()">;
345def HasSSE42 : Predicate<"Subtarget->hasSSE42()">;
David Greene343dadb2009-06-26 22:46:54 +0000346def HasSSE4A : Predicate<"Subtarget->hasSSE4A()">;
347def HasAVX : Predicate<"Subtarget->hasAVX()">;
348def HasFMA3 : Predicate<"Subtarget->hasFMA3()">;
349def HasFMA4 : Predicate<"Subtarget->hasFMA4()">;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000350def FPStackf32 : Predicate<"!Subtarget->hasSSE1()">;
351def FPStackf64 : Predicate<"!Subtarget->hasSSE2()">;
Evan Cheng28b514392006-12-05 19:50:18 +0000352def In32BitMode : Predicate<"!Subtarget->is64Bit()">;
353def In64BitMode : Predicate<"Subtarget->is64Bit()">;
Anton Korobeynikovcf6b7392009-08-03 08:12:53 +0000354def IsWin64 : Predicate<"Subtarget->isTargetWin64()">;
355def NotWin64 : Predicate<"!Subtarget->isTargetWin64()">;
Anton Korobeynikovd7697d02009-08-06 11:23:24 +0000356def SmallCode : Predicate<"TM.getCodeModel() == CodeModel::Small">;
357def KernelCode : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
358def FarData : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
Anton Korobeynikov186fa1d2009-08-06 09:11:19 +0000359 "TM.getCodeModel() != CodeModel::Kernel">;
Anton Korobeynikovd7697d02009-08-06 11:23:24 +0000360def NearData : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
361 "TM.getCodeModel() == CodeModel::Kernel">;
Evan Cheng28b514392006-12-05 19:50:18 +0000362def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
Evan Chengcb0f06e2010-03-25 00:10:31 +0000363def IsNotPIC : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
Evan Chengb1f49812009-12-22 17:47:23 +0000364def OptForSize : Predicate<"OptForSize">;
Evan Chengb7a75a52008-09-26 23:41:32 +0000365def OptForSpeed : Predicate<"!OptForSize">;
Evan Chengccb69762009-01-02 05:35:45 +0000366def FastBTMem : Predicate<"!Subtarget->isBTMemSlow()">;
Evan Chengd7f666a2009-05-20 04:53:57 +0000367def CallImmAddr : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
Eric Christopher6d1cd1c2010-04-02 21:54:27 +0000368def HasAES : Predicate<"Subtarget->hasAES()">;
Evan Chengbbc8ddb2005-12-20 22:59:51 +0000369
370//===----------------------------------------------------------------------===//
Evan Chengc64a1a92007-07-31 08:04:03 +0000371// X86 Instruction Format Definitions.
Evan Chengaed7c722005-12-17 01:24:02 +0000372//
373
Evan Chengc64a1a92007-07-31 08:04:03 +0000374include "X86InstrFormats.td"
Chris Lattner1cca5e32003-08-03 21:54:21 +0000375
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +0000376//===----------------------------------------------------------------------===//
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000377// Pattern fragments...
378//
Evan Chengd9558e02006-01-06 00:43:03 +0000379
380// X86 specific condition code. These correspond to CondCode in
Nate Begeman9a225302007-05-06 04:00:55 +0000381// X86InstrInfo.h. They must be kept in synch.
Dan Gohman653456c2009-01-07 00:15:08 +0000382def X86_COND_A : PatLeaf<(i8 0)>; // alt. COND_NBE
383def X86_COND_AE : PatLeaf<(i8 1)>; // alt. COND_NC
384def X86_COND_B : PatLeaf<(i8 2)>; // alt. COND_C
385def X86_COND_BE : PatLeaf<(i8 3)>; // alt. COND_NA
386def X86_COND_E : PatLeaf<(i8 4)>; // alt. COND_Z
387def X86_COND_G : PatLeaf<(i8 5)>; // alt. COND_NLE
388def X86_COND_GE : PatLeaf<(i8 6)>; // alt. COND_NL
389def X86_COND_L : PatLeaf<(i8 7)>; // alt. COND_NGE
390def X86_COND_LE : PatLeaf<(i8 8)>; // alt. COND_NG
391def X86_COND_NE : PatLeaf<(i8 9)>; // alt. COND_NZ
Evan Chengd9558e02006-01-06 00:43:03 +0000392def X86_COND_NO : PatLeaf<(i8 10)>;
Dan Gohman653456c2009-01-07 00:15:08 +0000393def X86_COND_NP : PatLeaf<(i8 11)>; // alt. COND_PO
Evan Chengd9558e02006-01-06 00:43:03 +0000394def X86_COND_NS : PatLeaf<(i8 12)>;
Dan Gohman653456c2009-01-07 00:15:08 +0000395def X86_COND_O : PatLeaf<(i8 13)>;
396def X86_COND_P : PatLeaf<(i8 14)>; // alt. COND_PE
397def X86_COND_S : PatLeaf<(i8 15)>;
Evan Chengd9558e02006-01-06 00:43:03 +0000398
Chris Lattner18409912010-03-03 01:45:01 +0000399def immSext8 : PatLeaf<(imm), [{
400 return N->getSExtValue() == (int8_t)N->getSExtValue();
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000401}]>;
402
Chris Lattner18409912010-03-03 01:45:01 +0000403def i16immSExt8 : PatLeaf<(i16 immSext8)>;
404def i32immSExt8 : PatLeaf<(i32 immSext8)>;
Evan Chengb3558542005-12-13 00:01:09 +0000405
Chris Lattnerf85eff72010-03-03 01:52:59 +0000406/// Load patterns: these constraint the match to the right address space.
407def dsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
408 if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
409 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
410 if (PT->getAddressSpace() > 255)
411 return false;
412 return true;
413}]>;
414
415def gsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
416 if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
417 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
418 return PT->getAddressSpace() == 256;
419 return false;
420}]>;
421
422def fsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
423 if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
424 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
425 return PT->getAddressSpace() == 257;
426 return false;
427}]>;
428
429
Evan Cheng605c4152005-12-13 01:57:51 +0000430// Helper fragments for loads.
Evan Chengb6564432008-05-13 18:59:59 +0000431// It's always safe to treat a anyext i16 load as a i32 load if the i16 is
432// known to be 32-bit aligned or better. Ditto for i8 to i16.
Dan Gohman33586292008-10-15 06:50:19 +0000433def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
Dan Gohman67ca6be2008-08-20 15:24:22 +0000434 LoadSDNode *LD = cast<LoadSDNode>(N);
Chris Lattnerc2406f22009-04-10 00:16:23 +0000435 if (const Value *Src = LD->getSrcValue())
436 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
Mon P Wanga7e01d72009-04-27 07:22:10 +0000437 if (PT->getAddressSpace() > 255)
Chris Lattnerc2406f22009-04-10 00:16:23 +0000438 return false;
Dan Gohman67ca6be2008-08-20 15:24:22 +0000439 ISD::LoadExtType ExtType = LD->getExtensionType();
440 if (ExtType == ISD::NON_EXTLOAD)
441 return true;
442 if (ExtType == ISD::EXTLOAD)
443 return LD->getAlignment() >= 2 && !LD->isVolatile();
Evan Chengfa7fd332008-05-13 00:54:02 +0000444 return false;
445}]>;
446
Chris Lattnerf85eff72010-03-03 01:52:59 +0000447def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
Evan Chengca57f782008-09-24 23:27:55 +0000448 LoadSDNode *LD = cast<LoadSDNode>(N);
Chris Lattnerc2406f22009-04-10 00:16:23 +0000449 if (const Value *Src = LD->getSrcValue())
450 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
Mon P Wanga7e01d72009-04-27 07:22:10 +0000451 if (PT->getAddressSpace() > 255)
Chris Lattnerc2406f22009-04-10 00:16:23 +0000452 return false;
Evan Chengca57f782008-09-24 23:27:55 +0000453 ISD::LoadExtType ExtType = LD->getExtensionType();
454 if (ExtType == ISD::EXTLOAD)
455 return LD->getAlignment() >= 2 && !LD->isVolatile();
456 return false;
457}]>;
458
Dan Gohman33586292008-10-15 06:50:19 +0000459def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
Dan Gohman67ca6be2008-08-20 15:24:22 +0000460 LoadSDNode *LD = cast<LoadSDNode>(N);
Chris Lattnerc2406f22009-04-10 00:16:23 +0000461 if (const Value *Src = LD->getSrcValue())
462 if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
Mon P Wanga7e01d72009-04-27 07:22:10 +0000463 if (PT->getAddressSpace() > 255)
Chris Lattnerc2406f22009-04-10 00:16:23 +0000464 return false;
Dan Gohman67ca6be2008-08-20 15:24:22 +0000465 ISD::LoadExtType ExtType = LD->getExtensionType();
466 if (ExtType == ISD::NON_EXTLOAD)
467 return true;
468 if (ExtType == ISD::EXTLOAD)
469 return LD->getAlignment() >= 4 && !LD->isVolatile();
Evan Chengfa7fd332008-05-13 00:54:02 +0000470 return false;
471}]>;
472
Chris Lattnerf85eff72010-03-03 01:52:59 +0000473def loadi8 : PatFrag<(ops node:$ptr), (i8 (dsload node:$ptr))>;
474def loadi64 : PatFrag<(ops node:$ptr), (i64 (dsload node:$ptr))>;
475def loadf32 : PatFrag<(ops node:$ptr), (f32 (dsload node:$ptr))>;
476def loadf64 : PatFrag<(ops node:$ptr), (f64 (dsload node:$ptr))>;
477def loadf80 : PatFrag<(ops node:$ptr), (f80 (dsload node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000478
Evan Cheng466685d2006-10-09 20:57:25 +0000479def sextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
480def sextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
481def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000482
Evan Cheng466685d2006-10-09 20:57:25 +0000483def zextloadi8i1 : PatFrag<(ops node:$ptr), (i8 (zextloadi1 node:$ptr))>;
484def zextloadi16i1 : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
485def zextloadi32i1 : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
486def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
487def zextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
488def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000489
Evan Cheng466685d2006-10-09 20:57:25 +0000490def extloadi8i1 : PatFrag<(ops node:$ptr), (i8 (extloadi1 node:$ptr))>;
491def extloadi16i1 : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
492def extloadi32i1 : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
493def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
494def extloadi32i8 : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
495def extloadi32i16 : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
Evan Cheng747a90d2006-02-21 02:24:38 +0000496
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000497
498// An 'and' node with a single use.
499def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
Evan Cheng07b7ea12008-03-04 00:40:35 +0000500 return N->hasOneUse();
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000501}]>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000502// An 'srl' node with a single use.
503def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
504 return N->hasOneUse();
505}]>;
506// An 'trunc' node with a single use.
507def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
508 return N->hasOneUse();
509}]>;
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000510
Evan Cheng4b0345b2010-01-11 17:03:47 +0000511// Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
512def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
513 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
514 return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
Chris Lattnerfdac0b62010-03-24 00:12:57 +0000515
516 unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
517 APInt Mask = APInt::getAllOnesValue(BitWidth);
518 APInt KnownZero0, KnownOne0;
519 CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
520 APInt KnownZero1, KnownOne1;
521 CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
522 return (~KnownZero0 & ~KnownZero1) == 0;
Evan Cheng4b0345b2010-01-11 17:03:47 +0000523}]>;
Evan Cheng4b0345b2010-01-11 17:03:47 +0000524
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000525//===----------------------------------------------------------------------===//
Chris Lattner1cca5e32003-08-03 21:54:21 +0000526// Instruction list...
527//
528
Chris Lattnerf18c0742006-10-12 17:42:56 +0000529// ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
530// a stack adjustment and the codegen must know that they may modify the stack
531// pointer before prolog-epilog rewriting occurs.
Chris Lattner447ff682008-03-11 03:23:40 +0000532// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
533// sub / add which can clobber EFLAGS.
Evan Cheng8decf6b2007-09-28 01:19:48 +0000534let Defs = [ESP, EFLAGS], Uses = [ESP] in {
Dan Gohman6d4b0522008-10-01 18:28:06 +0000535def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt),
536 "#ADJCALLSTACKDOWN",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000537 [(X86callseq_start timm:$amt)]>,
Dan Gohman6d4b0522008-10-01 18:28:06 +0000538 Requires<[In32BitMode]>;
539def ADJCALLSTACKUP32 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
540 "#ADJCALLSTACKUP",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000541 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman6d4b0522008-10-01 18:28:06 +0000542 Requires<[In32BitMode]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000543}
Evan Cheng4a460802006-01-11 00:33:36 +0000544
Dan Gohmand6708ea2009-08-15 01:38:56 +0000545// x86-64 va_start lowering magic.
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000546let usesCustomInserter = 1 in {
Dan Gohmand6708ea2009-08-15 01:38:56 +0000547def VASTART_SAVE_XMM_REGS : I<0, Pseudo,
548 (outs),
549 (ins GR8:$al,
550 i64imm:$regsavefi, i64imm:$offset,
551 variable_ops),
552 "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset",
553 [(X86vastart_save_xmm_regs GR8:$al,
554 imm:$regsavefi,
555 imm:$offset)]>;
556
Anton Korobeynikove765f2b2010-03-06 20:07:32 +0000557// Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets. Calls
558// to _alloca is needed to probe the stack when allocating more than 4k bytes in
559// one go. Touching the stack at 4K increments is necessary to ensure that the
560// guard pages used by the OS virtual memory manager are allocated in correct
561// sequence.
562// The main point of having separate instruction are extra unmodelled effects
563// (compared to ordinary calls) like stack pointer change.
564
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000565def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins),
Anton Korobeynikove765f2b2010-03-06 20:07:32 +0000566 "# dynamic stack allocation",
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000567 [(X86MingwAlloca)]>;
568}
569
Evan Cheng4a460802006-01-11 00:33:36 +0000570// Nop
Sean Callanan74e52102009-07-23 23:39:34 +0000571let neverHasSideEffects = 1 in {
Chris Lattnerba7e7562008-01-10 07:59:24 +0000572 def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
Sean Callanan108934c2009-12-18 00:01:26 +0000573 def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
574 "nop{w}\t$zero", []>, TB, OpSize;
Sean Callanan74e52102009-07-23 23:39:34 +0000575 def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
Sean Callanan108934c2009-12-18 00:01:26 +0000576 "nop{l}\t$zero", []>, TB;
Sean Callanan74e52102009-07-23 23:39:34 +0000577}
Evan Cheng4a460802006-01-11 00:33:36 +0000578
Sean Callanan1c5cf1b2009-08-11 01:09:06 +0000579// Trap
Kevin Enderbyc3ce05c2010-05-14 19:16:02 +0000580def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>;
581def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", []>;
582// FIXME: need to make sure that "int $3" matches int3
583def INT : Ii8<0xcd, RawFrm, (outs), (ins i8imm:$trap), "int\t$trap", []>;
Sean Callanan108934c2009-12-18 00:01:26 +0000584def IRET16 : I<0xcf, RawFrm, (outs), (ins), "iret{w}", []>, OpSize;
585def IRET32 : I<0xcf, RawFrm, (outs), (ins), "iret{l}", []>;
Sean Callanan1c5cf1b2009-08-11 01:09:06 +0000586
Chris Lattner71c7ace2009-09-20 07:32:00 +0000587// PIC base construction. This expands to code that looks like this:
588// call $next_inst
589// popl %destreg"
Dan Gohman2662d552008-10-01 04:14:30 +0000590let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in
Chris Lattnerb3c85472009-09-20 07:28:26 +0000591 def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label),
Chris Lattner71c7ace2009-09-20 07:32:00 +0000592 "", []>;
Evan Cheng8f7f7122006-05-05 05:40:20 +0000593
Chris Lattner1cca5e32003-08-03 21:54:21 +0000594//===----------------------------------------------------------------------===//
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000595// Control Flow Instructions.
Chris Lattner1cca5e32003-08-03 21:54:21 +0000596//
597
Chris Lattner1be48112005-05-13 17:56:48 +0000598// Return instructions.
Evan Cheng2b4ea792005-12-26 09:11:45 +0000599let isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesen70feca42010-03-25 18:52:01 +0000600 hasCtrlDep = 1, FPForm = SpecialFP in {
Dan Gohmane4c67cd2008-05-31 02:11:25 +0000601 def RET : I <0xC3, RawFrm, (outs), (ins variable_ops),
Chris Lattner447ff682008-03-11 03:23:40 +0000602 "ret",
Dan Gohmane4c67cd2008-05-31 02:11:25 +0000603 [(X86retflag 0)]>;
Chris Lattner447ff682008-03-11 03:23:40 +0000604 def RETI : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
605 "ret\t$amt",
Dan Gohman2f67df72009-09-03 17:18:51 +0000606 [(X86retflag timm:$amt)]>;
Sean Callanan356aed52009-09-15 23:37:51 +0000607 def LRET : I <0xCB, RawFrm, (outs), (ins),
608 "lret", []>;
609 def LRETI : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
610 "lret\t$amt", []>;
Evan Cheng171049d2005-12-23 22:14:32 +0000611}
Chris Lattner1cca5e32003-08-03 21:54:21 +0000612
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000613// Unconditional branches.
Chris Lattnerb8db3312010-02-11 21:45:31 +0000614let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
Chris Lattnera0331192010-02-12 22:27:07 +0000615 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
616 "jmp\t$dst", [(br bb:$dst)]>;
617 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
618 "jmp\t$dst", []>;
Sean Callanan52925882009-07-22 01:05:20 +0000619}
Evan Cheng898101c2005-12-19 23:12:38 +0000620
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000621// Conditional Branches.
622let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
623 multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
Chris Lattnera0331192010-02-12 22:27:07 +0000624 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, []>;
625 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
626 [(X86brcond bb:$dst, Cond, EFLAGS)]>, TB;
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000627 }
628}
629
630defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
Chris Lattner8b442a82010-02-11 19:52:11 +0000631defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000632defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
633defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
634defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
635defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
636defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
637defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
638defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
639defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
640defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
641defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
642defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
643defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
644defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
645defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
646
647// FIXME: What about the CX/RCX versions of this instruction?
Chris Lattnerb8db3312010-02-11 21:45:31 +0000648let Uses = [ECX], isBranch = 1, isTerminator = 1 in
Chris Lattnera0331192010-02-12 22:27:07 +0000649 def JCXZ8 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
650 "jcxz\t$dst", []>;
Chris Lattnerbd13fb62010-02-11 19:25:55 +0000651
652
Owen Anderson20ab2902007-11-12 07:39:39 +0000653// Indirect branches
654let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +0000655 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
Evan Cheng069287d2006-05-16 07:21:53 +0000656 [(brind GR32:$dst)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000657 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
Evan Cheng25ab6902006-09-08 06:48:29 +0000658 [(brind (loadi32 addr:$dst))]>;
Sean Callanan76f14be2009-09-15 00:35:17 +0000659
660 def FARJMP16i : Iseg16<0xEA, RawFrm, (outs),
661 (ins i16imm:$seg, i16imm:$off),
662 "ljmp{w}\t$seg, $off", []>, OpSize;
663 def FARJMP32i : Iseg32<0xEA, RawFrm, (outs),
664 (ins i16imm:$seg, i32imm:$off),
665 "ljmp{l}\t$seg, $off", []>;
666
667 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
Sean Callanan9947bbb2009-09-03 00:04:47 +0000668 "ljmp{w}\t{*}$dst", []>, OpSize;
Sean Callanan76f14be2009-09-15 00:35:17 +0000669 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
Sean Callanan9947bbb2009-09-03 00:04:47 +0000670 "ljmp{l}\t{*}$dst", []>;
Nate Begeman37efe672006-04-22 18:53:45 +0000671}
672
Chris Lattner1cca5e32003-08-03 21:54:21 +0000673
Sean Callanan7e6d7272009-09-16 21:50:07 +0000674// Loop instructions
675
Chris Lattner34b8a882010-03-18 20:50:06 +0000676def LOOP : I<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
677def LOOPE : I<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
678def LOOPNE : I<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
Sean Callanan7e6d7272009-09-16 21:50:07 +0000679
Chris Lattner1cca5e32003-08-03 21:54:21 +0000680//===----------------------------------------------------------------------===//
681// Call Instructions...
682//
Evan Chengffbacca2007-07-21 00:34:19 +0000683let isCall = 1 in
Dan Gohman6d4b0522008-10-01 18:28:06 +0000684 // All calls clobber the non-callee saved registers. ESP is marked as
685 // a use to prevent stack-pointer assignments that appear immediately
686 // before calls from potentially appearing dead. Uses for argument
687 // registers are added manually.
Nate Begemanf63be7d2005-07-06 18:59:04 +0000688 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
Bill Wendling3f3a17d2007-04-25 21:31:48 +0000689 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
Evan Cheng109a5622008-10-17 21:02:22 +0000690 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
691 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
Dan Gohman2662d552008-10-01 04:14:30 +0000692 Uses = [ESP] in {
Chris Lattnera0331192010-02-12 22:27:07 +0000693 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
Chris Lattner7680e732009-06-20 19:34:09 +0000694 (outs), (ins i32imm_pcrel:$dst,variable_ops),
695 "call\t$dst", []>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000696 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000697 "call\t{*}$dst", [(X86call GR32:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000698 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
Dan Gohmanb4106172008-05-29 21:50:34 +0000699 "call\t{*}$dst", [(X86call (loadi32 addr:$dst))]>;
Sean Callanan9947bbb2009-09-03 00:04:47 +0000700
Sean Callanan76f14be2009-09-15 00:35:17 +0000701 def FARCALL16i : Iseg16<0x9A, RawFrm, (outs),
702 (ins i16imm:$seg, i16imm:$off),
703 "lcall{w}\t$seg, $off", []>, OpSize;
704 def FARCALL32i : Iseg32<0x9A, RawFrm, (outs),
705 (ins i16imm:$seg, i32imm:$off),
706 "lcall{l}\t$seg, $off", []>;
707
708 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
Sean Callanan9947bbb2009-09-03 00:04:47 +0000709 "lcall{w}\t{*}$dst", []>, OpSize;
Sean Callanan76f14be2009-09-15 00:35:17 +0000710 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
Sean Callanan9947bbb2009-09-03 00:04:47 +0000711 "lcall{l}\t{*}$dst", []>;
Chris Lattner1cca5e32003-08-03 21:54:21 +0000712 }
713
Sean Callanan8d708542009-09-16 02:57:13 +0000714// Constructing a stack frame.
715
716def ENTER : I<0xC8, RawFrm, (outs), (ins i16imm:$len, i8imm:$lvl),
717 "enter\t$len, $lvl", []>;
718
Chris Lattner1e9448b2005-05-15 03:10:37 +0000719// Tail call stuff.
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000720
Evan Chengffbacca2007-07-21 00:34:19 +0000721let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengf48ef032010-03-14 03:48:46 +0000722 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
723 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
724 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
725 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
726 Uses = [ESP] in {
727 def TCRETURNdi : I<0, Pseudo, (outs),
728 (ins i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
729 "#TC_RETURN $dst $offset", []>;
730 def TCRETURNri : I<0, Pseudo, (outs),
731 (ins GR32_TC:$dst, i32imm:$offset, variable_ops),
732 "#TC_RETURN $dst $offset", []>;
Dan Gohman7f357ec2010-05-14 16:34:55 +0000733 let mayLoad = 1 in
Evan Chengf48ef032010-03-14 03:48:46 +0000734 def TCRETURNmi : I<0, Pseudo, (outs),
735 (ins i32mem_TC:$dst, i32imm:$offset, variable_ops),
736 "#TC_RETURN $dst $offset", []>;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000737
Evan Chengf48ef032010-03-14 03:48:46 +0000738 // FIXME: The should be pseudo instructions that are lowered when going to
739 // mcinst.
Chris Lattner840e6372010-03-16 06:30:18 +0000740 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
741 (ins i32imm_pcrel:$dst, variable_ops),
Evan Chengaa92bec2010-01-31 07:28:44 +0000742 "jmp\t$dst # TAILCALL",
Evan Chengf10c17f2006-09-22 21:43:59 +0000743 []>;
Evan Chengf48ef032010-03-14 03:48:46 +0000744 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32_TC:$dst, variable_ops),
Sean Callanan108934c2009-12-18 00:01:26 +0000745 "jmp{l}\t{*}$dst # TAILCALL",
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000746 []>;
Dan Gohman7f357ec2010-05-14 16:34:55 +0000747 let mayLoad = 1 in
Evan Chengf48ef032010-03-14 03:48:46 +0000748 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst, variable_ops),
749 "jmp{l}\t{*}$dst # TAILCALL", []>;
Daniel Dunbar52322e72010-05-19 15:26:43 +0000750
751 // FIXME: This is a hack so that MCInst lowering can preserve the TAILCALL
752 // marker on instructions, while still being able to relax.
753 let isCodeGenOnly = 1 in {
754 def TAILJMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
755 "jmp\t$dst # TAILCALL", []>;
756 }
Evan Chengf48ef032010-03-14 03:48:46 +0000757}
Chris Lattner1e9448b2005-05-15 03:10:37 +0000758
Chris Lattner1cca5e32003-08-03 21:54:21 +0000759//===----------------------------------------------------------------------===//
760// Miscellaneous Instructions...
761//
Chris Lattnerba7e7562008-01-10 07:59:24 +0000762let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
Chris Lattner30bf2d82004-08-10 20:17:41 +0000763def LEAVE : I<0xC9, RawFrm,
Evan Cheng071a2792007-09-11 19:55:27 +0000764 (outs), (ins), "leave", []>;
765
Sean Callanan108934c2009-12-18 00:01:26 +0000766def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
767 "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
Dan Gohman7f357ec2010-05-14 16:34:55 +0000768let mayLoad = 1 in
Sean Callanan108934c2009-12-18 00:01:26 +0000769def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
770 "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
771def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
772 "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
Dan Gohman7f357ec2010-05-14 16:34:55 +0000773let mayLoad = 1 in
Sean Callanan108934c2009-12-18 00:01:26 +0000774def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
775 "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
776
Chris Lattnerba7e7562008-01-10 07:59:24 +0000777let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
Sean Callanan1f24e012009-09-10 18:29:13 +0000778let mayLoad = 1 in {
779def POP16r : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
780 OpSize;
781def POP32r : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
782def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
783 OpSize;
784def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
785 OpSize;
786def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
787def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
788}
Chris Lattner1cca5e32003-08-03 21:54:21 +0000789
Sean Callanan1f24e012009-09-10 18:29:13 +0000790let mayStore = 1 in {
791def PUSH16r : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
792 OpSize;
Evan Cheng2f245ba2007-09-26 01:29:06 +0000793def PUSH32r : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
Sean Callanan1f24e012009-09-10 18:29:13 +0000794def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
795 OpSize;
796def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
797 OpSize;
798def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
799def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
800}
Evan Cheng071a2792007-09-11 19:55:27 +0000801}
Anton Korobeynikov57fc00d2007-04-17 09:20:00 +0000802
Bill Wendling453eb262009-06-15 19:39:04 +0000803let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
Kevin Enderby3c979b02010-05-03 20:45:05 +0000804def PUSHi8 : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm),
Bill Wendling927788c2009-06-15 20:59:31 +0000805 "push{l}\t$imm", []>;
Kevin Enderby3c979b02010-05-03 20:45:05 +0000806def PUSHi16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
807 "push{w}\t$imm", []>, OpSize;
808def PUSHi32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling927788c2009-06-15 20:59:31 +0000809 "push{l}\t$imm", []>;
Bill Wendling453eb262009-06-15 19:39:04 +0000810}
811
Sean Callanan108934c2009-12-18 00:01:26 +0000812let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
Dan Gohmane5e4ff92010-05-20 16:16:00 +0000813def POPF16 : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
814def POPF32 : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
815 Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000816}
817let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
Dan Gohmane5e4ff92010-05-20 16:16:00 +0000818def PUSHF16 : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
819def PUSHF32 : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
820 Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000821}
Evan Cheng2f245ba2007-09-26 01:29:06 +0000822
Evan Cheng069287d2006-05-16 07:21:53 +0000823let isTwoAddress = 1 in // GR32 = bswap GR32
Chris Lattner30bf2d82004-08-10 20:17:41 +0000824 def BSWAP32r : I<0xC8, AddRegFrm,
Evan Cheng64d80e32007-07-19 01:14:50 +0000825 (outs GR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000826 "bswap{l}\t$dst",
Evan Cheng069287d2006-05-16 07:21:53 +0000827 [(set GR32:$dst, (bswap GR32:$src))]>, TB;
Chris Lattner1cca5e32003-08-03 21:54:21 +0000828
Chris Lattner1cca5e32003-08-03 21:54:21 +0000829
Evan Cheng18efe262007-12-14 02:13:44 +0000830// Bit scan instructions.
831let Defs = [EFLAGS] in {
Evan Chengfd9e4732007-12-14 18:49:43 +0000832def BSF16rr : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000833 "bsf{w}\t{$src, $dst|$dst, $src}",
Kevin Enderby9ac72822010-04-28 23:20:40 +0000834 [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
Evan Cheng18efe262007-12-14 02:13:44 +0000835def BSF16rm : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000836 "bsf{w}\t{$src, $dst|$dst, $src}",
Kevin Enderby9ac72822010-04-28 23:20:40 +0000837 [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
838 OpSize;
Evan Chengfd9e4732007-12-14 18:49:43 +0000839def BSF32rr : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000840 "bsf{l}\t{$src, $dst|$dst, $src}",
Chris Lattnerd486d772010-03-28 05:07:17 +0000841 [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000842def BSF32rm : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000843 "bsf{l}\t{$src, $dst|$dst, $src}",
Chris Lattnerd486d772010-03-28 05:07:17 +0000844 [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000845
Evan Chengfd9e4732007-12-14 18:49:43 +0000846def BSR16rr : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000847 "bsr{w}\t{$src, $dst|$dst, $src}",
Kevin Enderby9ac72822010-04-28 23:20:40 +0000848 [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
Evan Cheng18efe262007-12-14 02:13:44 +0000849def BSR16rm : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000850 "bsr{w}\t{$src, $dst|$dst, $src}",
Kevin Enderby9ac72822010-04-28 23:20:40 +0000851 [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
852 OpSize;
Evan Chengfd9e4732007-12-14 18:49:43 +0000853def BSR32rr : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000854 "bsr{l}\t{$src, $dst|$dst, $src}",
Chris Lattnerd486d772010-03-28 05:07:17 +0000855 [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000856def BSR32rm : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000857 "bsr{l}\t{$src, $dst|$dst, $src}",
Chris Lattnerd486d772010-03-28 05:07:17 +0000858 [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000859} // Defs = [EFLAGS]
860
Chris Lattnerba7e7562008-01-10 07:59:24 +0000861let neverHasSideEffects = 1 in
Chris Lattner3a173df2004-10-03 20:35:00 +0000862def LEA16r : I<0x8D, MRMSrcMem,
Evan Cheng15b0d972009-12-12 18:51:56 +0000863 (outs GR16:$dst), (ins lea32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000864 "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
Evan Chenge771ebd2008-03-27 01:41:09 +0000865let isReMaterializable = 1 in
Chris Lattner3a173df2004-10-03 20:35:00 +0000866def LEA32r : I<0x8D, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000867 (outs GR32:$dst), (ins lea32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000868 "lea{l}\t{$src|$dst}, {$dst|$src}",
Evan Cheng25ab6902006-09-08 06:48:29 +0000869 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
Chris Lattner1cca5e32003-08-03 21:54:21 +0000870
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000871let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000872def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
Evan Cheng071a2792007-09-11 19:55:27 +0000873 [(X86rep_movs i8)]>, REP;
Evan Cheng64d80e32007-07-19 01:14:50 +0000874def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
Evan Cheng071a2792007-09-11 19:55:27 +0000875 [(X86rep_movs i16)]>, REP, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +0000876def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
Evan Cheng071a2792007-09-11 19:55:27 +0000877 [(X86rep_movs i32)]>, REP;
878}
Chris Lattner915e5e52004-02-12 17:53:22 +0000879
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000880// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
881let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
882def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
883def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
884def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
885}
886
887let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000888def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
Evan Cheng071a2792007-09-11 19:55:27 +0000889 [(X86rep_stos i8)]>, REP;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000890let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000891def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
Evan Cheng071a2792007-09-11 19:55:27 +0000892 [(X86rep_stos i16)]>, REP, OpSize;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000893let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000894def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
Evan Cheng071a2792007-09-11 19:55:27 +0000895 [(X86rep_stos i32)]>, REP;
Chris Lattner30bf2d82004-08-10 20:17:41 +0000896
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000897// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
898let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
899def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
900let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
901def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
902let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
903def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
904
Sean Callanana82e4652009-09-12 00:37:19 +0000905def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
906def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
907def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
908
Sean Callanan6f8f4622009-09-12 02:25:20 +0000909def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
910def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
911def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
912
Evan Cheng071a2792007-09-11 19:55:27 +0000913let Defs = [RAX, RDX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000914def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>,
Evan Cheng071a2792007-09-11 19:55:27 +0000915 TB;
Chris Lattnerb89abef2004-02-14 04:45:37 +0000916
Sean Callanancebe9552010-02-13 02:06:11 +0000917let Defs = [RAX, RCX, RDX] in
918def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", []>, TB;
919
Dan Gohmaneffc8c52010-05-14 16:46:02 +0000920let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
Chris Lattnerda68d302008-01-15 21:58:22 +0000921def TRAP : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
Anton Korobeynikov66fac792008-01-15 07:02:33 +0000922}
923
Chris Lattner02552de2009-08-11 16:58:39 +0000924def SYSCALL : I<0x05, RawFrm,
925 (outs), (ins), "syscall", []>, TB;
926def SYSRET : I<0x07, RawFrm,
927 (outs), (ins), "sysret", []>, TB;
928def SYSENTER : I<0x34, RawFrm,
929 (outs), (ins), "sysenter", []>, TB;
930def SYSEXIT : I<0x35, RawFrm,
931 (outs), (ins), "sysexit", []>, TB;
932
Sean Callanan2a46f362009-09-12 02:52:41 +0000933def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
Chris Lattner02552de2009-08-11 16:58:39 +0000934
935
Chris Lattner1cca5e32003-08-03 21:54:21 +0000936//===----------------------------------------------------------------------===//
John Criswell4ffff9e2004-04-08 20:31:47 +0000937// Input/Output Instructions...
938//
Evan Cheng071a2792007-09-11 19:55:27 +0000939let Defs = [AL], Uses = [DX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000940def IN8rr : I<0xEC, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000941 "in{b}\t{%dx, %al|%AL, %DX}", []>;
942let Defs = [AX], Uses = [DX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000943def IN16rr : I<0xED, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000944 "in{w}\t{%dx, %ax|%AX, %DX}", []>, OpSize;
945let Defs = [EAX], Uses = [DX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000946def IN32rr : I<0xED, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000947 "in{l}\t{%dx, %eax|%EAX, %DX}", []>;
John Criswell4ffff9e2004-04-08 20:31:47 +0000948
Evan Cheng071a2792007-09-11 19:55:27 +0000949let Defs = [AL] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000950def IN8ri : Ii8<0xE4, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000951 "in{b}\t{$port, %al|%AL, $port}", []>;
952let Defs = [AX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000953def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000954 "in{w}\t{$port, %ax|%AX, $port}", []>, OpSize;
955let Defs = [EAX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000956def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000957 "in{l}\t{$port, %eax|%EAX, $port}", []>;
Chris Lattner440bbc22004-04-13 17:19:31 +0000958
Evan Cheng071a2792007-09-11 19:55:27 +0000959let Uses = [DX, AL] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000960def OUT8rr : I<0xEE, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000961 "out{b}\t{%al, %dx|%DX, %AL}", []>;
962let Uses = [DX, AX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000963def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000964 "out{w}\t{%ax, %dx|%DX, %AX}", []>, OpSize;
965let Uses = [DX, EAX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000966def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
Evan Cheng071a2792007-09-11 19:55:27 +0000967 "out{l}\t{%eax, %dx|%DX, %EAX}", []>;
Chris Lattnerffff7082004-08-01 07:44:35 +0000968
Evan Cheng071a2792007-09-11 19:55:27 +0000969let Uses = [AL] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000970def OUT8ir : Ii8<0xE6, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000971 "out{b}\t{%al, $port|$port, %AL}", []>;
972let Uses = [AX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000973def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000974 "out{w}\t{%ax, $port|$port, %AX}", []>, OpSize;
975let Uses = [EAX] in
Evan Cheng64d80e32007-07-19 01:14:50 +0000976def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
Evan Cheng071a2792007-09-11 19:55:27 +0000977 "out{l}\t{%eax, $port|$port, %EAX}", []>;
John Criswell4ffff9e2004-04-08 20:31:47 +0000978
Sean Callanan108934c2009-12-18 00:01:26 +0000979def IN8 : I<0x6C, RawFrm, (outs), (ins),
980 "ins{b}", []>;
981def IN16 : I<0x6D, RawFrm, (outs), (ins),
982 "ins{w}", []>, OpSize;
983def IN32 : I<0x6D, RawFrm, (outs), (ins),
984 "ins{l}", []>;
985
John Criswell4ffff9e2004-04-08 20:31:47 +0000986//===----------------------------------------------------------------------===//
Chris Lattner1cca5e32003-08-03 21:54:21 +0000987// Move Instructions...
988//
Chris Lattnerba7e7562008-01-10 07:59:24 +0000989let neverHasSideEffects = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000990def MOV8rr : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000991 "mov{b}\t{$src, $dst|$dst, $src}", []>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000992def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000993 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +0000994def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000995 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000996}
Evan Cheng359e9372008-06-18 08:13:07 +0000997let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000998def MOV8ri : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000999 "mov{b}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001000 [(set GR8:$dst, imm:$src)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001001def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001002 "mov{w}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001003 [(set GR16:$dst, imm:$src)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001004def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001005 "mov{l}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001006 [(set GR32:$dst, imm:$src)]>;
Dan Gohmand45eddd2007-06-26 00:48:07 +00001007}
Kevin Enderby12ce0de2010-02-03 21:04:42 +00001008
Evan Cheng64d80e32007-07-19 01:14:50 +00001009def MOV8mi : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001010 "mov{b}\t{$src, $dst|$dst, $src}",
Evan Chengb51a0592005-12-10 00:48:20 +00001011 [(store (i8 imm:$src), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001012def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001013 "mov{w}\t{$src, $dst|$dst, $src}",
Evan Chengb51a0592005-12-10 00:48:20 +00001014 [(store (i16 imm:$src), addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001015def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001016 "mov{l}\t{$src, $dst|$dst, $src}",
Evan Chengb51a0592005-12-10 00:48:20 +00001017 [(store (i32 imm:$src), addr:$dst)]>;
Chris Lattner1cca5e32003-08-03 21:54:21 +00001018
Chris Lattnerb5505d02010-05-13 00:02:47 +00001019/// moffs8, moffs16 and moffs32 versions of moves. The immediate is a
1020/// 32-bit offset from the PC. These are only valid in x86-32 mode.
Chris Lattner2745f6e2010-05-12 22:48:24 +00001021def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
Sean Callanan2f34a132009-09-10 18:33:42 +00001022 "mov{b}\t{$src, %al|%al, $src}", []>;
Chris Lattner2745f6e2010-05-12 22:48:24 +00001023def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
Sean Callanan2f34a132009-09-10 18:33:42 +00001024 "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001025def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
Sean Callanan2f34a132009-09-10 18:33:42 +00001026 "mov{l}\t{$src, %eax|%eax, $src}", []>;
Chris Lattner2745f6e2010-05-12 22:48:24 +00001027def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
Sean Callanan2f34a132009-09-10 18:33:42 +00001028 "mov{b}\t{%al, $dst|$dst, %al}", []>;
Chris Lattner2745f6e2010-05-12 22:48:24 +00001029def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
Sean Callanan2f34a132009-09-10 18:33:42 +00001030 "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001031def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
Sean Callanan2f34a132009-09-10 18:33:42 +00001032 "mov{l}\t{%eax, $dst|$dst, %eax}", []>;
Chris Lattnerb5505d02010-05-13 00:02:47 +00001033
Sean Callanan38fee0e2009-09-15 18:47:29 +00001034// Moves to and from segment registers
1035def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
Kevin Enderbyb1065432010-05-26 20:10:45 +00001036 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1037def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
1038 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Sean Callanan38fee0e2009-09-15 18:47:29 +00001039def MOV16ms : I<0x8C, MRMDestMem, (outs i16mem:$dst), (ins SEGMENT_REG:$src),
Kevin Enderbyb1065432010-05-26 20:10:45 +00001040 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1041def MOV32ms : I<0x8C, MRMDestMem, (outs i32mem:$dst), (ins SEGMENT_REG:$src),
1042 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Sean Callanan38fee0e2009-09-15 18:47:29 +00001043def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
Kevin Enderbyb1065432010-05-26 20:10:45 +00001044 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1045def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
1046 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Sean Callanan38fee0e2009-09-15 18:47:29 +00001047def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
Kevin Enderbyb1065432010-05-26 20:10:45 +00001048 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1049def MOV32sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i32mem:$src),
1050 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Sean Callanan38fee0e2009-09-15 18:47:29 +00001051
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001052let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001053def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
1054 "mov{b}\t{$src, $dst|$dst, $src}", []>;
1055def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
1056 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1057def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
1058 "mov{l}\t{$src, $dst|$dst, $src}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001059}
Sean Callanan108934c2009-12-18 00:01:26 +00001060
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001061let canFoldAsLoad = 1, isReMaterializable = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001062def MOV8rm : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001063 "mov{b}\t{$src, $dst|$dst, $src}",
Chris Lattnerc2406f22009-04-10 00:16:23 +00001064 [(set GR8:$dst, (loadi8 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001065def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001066 "mov{w}\t{$src, $dst|$dst, $src}",
Chris Lattnerc2406f22009-04-10 00:16:23 +00001067 [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001068def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001069 "mov{l}\t{$src, $dst|$dst, $src}",
Chris Lattnerc2406f22009-04-10 00:16:23 +00001070 [(set GR32:$dst, (loadi32 addr:$src))]>;
Evan Cheng2f394262007-08-30 05:49:43 +00001071}
Chris Lattner1cca5e32003-08-03 21:54:21 +00001072
Evan Cheng64d80e32007-07-19 01:14:50 +00001073def MOV8mr : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001074 "mov{b}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001075 [(store GR8:$src, addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001076def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001077 "mov{w}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001078 [(store GR16:$src, addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001079def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001080 "mov{l}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00001081 [(store GR32:$src, addr:$dst)]>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +00001082
Evan Chengf48ef032010-03-14 03:48:46 +00001083/// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
1084let neverHasSideEffects = 1 in
1085def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
1086 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1087
1088let mayLoad = 1,
1089 canFoldAsLoad = 1, isReMaterializable = 1 in
1090def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
1091 "mov{l}\t{$src, $dst|$dst, $src}",
1092 []>;
1093
1094let mayStore = 1 in
1095def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
1096 "mov{l}\t{$src, $dst|$dst, $src}",
1097 []>;
1098
Dan Gohman4af325d2009-04-27 16:41:36 +00001099// Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
1100// that they can be used for copying and storing h registers, which can't be
1101// encoded when a REX prefix is present.
Dan Gohman6d9305c2009-04-15 00:04:23 +00001102let neverHasSideEffects = 1 in
Dan Gohmandf7dfc72009-04-15 19:48:57 +00001103def MOV8rr_NOREX : I<0x88, MRMDestReg,
1104 (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
Dan Gohman6d9305c2009-04-15 00:04:23 +00001105 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", []>;
Evan Cheng8c147402009-04-30 00:58:57 +00001106let mayStore = 1 in
Dan Gohman6d9305c2009-04-15 00:04:23 +00001107def MOV8mr_NOREX : I<0x88, MRMDestMem,
1108 (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
1109 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", []>;
Evan Cheng8c147402009-04-30 00:58:57 +00001110let mayLoad = 1,
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001111 canFoldAsLoad = 1, isReMaterializable = 1 in
Dan Gohman4af325d2009-04-27 16:41:36 +00001112def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
1113 (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
1114 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", []>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +00001115
Sean Callanan108934c2009-12-18 00:01:26 +00001116// Moves to and from debug registers
1117def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
1118 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1119def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
1120 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1121
1122// Moves to and from control registers
Sean Callanan1a8b7892010-05-06 20:59:00 +00001123def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
1124 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1125def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
1126 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001127
Chris Lattner1cca5e32003-08-03 21:54:21 +00001128//===----------------------------------------------------------------------===//
1129// Fixed-Register Multiplication and Division Instructions...
1130//
Chris Lattner1cca5e32003-08-03 21:54:21 +00001131
Chris Lattnerc8f45872003-08-04 04:59:56 +00001132// Extra precision multiplication
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001133
1134// AL is really implied by AX, by the registers in Defs must match the
1135// SDNode results (i8, i32).
1136let Defs = [AL,EFLAGS,AX], Uses = [AL] in
Dan Gohmanb1576f52007-07-31 20:11:57 +00001137def MUL8r : I<0xF6, MRM4r, (outs), (ins GR8:$src), "mul{b}\t$src",
Evan Chengcf74a7c2006-01-15 10:05:20 +00001138 // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1139 // This probably ought to be moved to a def : Pat<> if the
1140 // syntax can be accepted.
Bill Wendlingd350e022008-12-12 21:15:41 +00001141 [(set AL, (mul AL, GR8:$src)),
1142 (implicit EFLAGS)]>; // AL,AH = AL*GR8
1143
Chris Lattnera731c9f2008-01-11 07:18:17 +00001144let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
Bill Wendlingd350e022008-12-12 21:15:41 +00001145def MUL16r : I<0xF7, MRM4r, (outs), (ins GR16:$src),
1146 "mul{w}\t$src",
1147 []>, OpSize; // AX,DX = AX*GR16
1148
Chris Lattnera731c9f2008-01-11 07:18:17 +00001149let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
Bill Wendlingd350e022008-12-12 21:15:41 +00001150def MUL32r : I<0xF7, MRM4r, (outs), (ins GR32:$src),
1151 "mul{l}\t$src",
1152 []>; // EAX,EDX = EAX*GR32
1153
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001154let Defs = [AL,EFLAGS,AX], Uses = [AL] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001155def MUL8m : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001156 "mul{b}\t$src",
Evan Chengcf74a7c2006-01-15 10:05:20 +00001157 // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1158 // This probably ought to be moved to a def : Pat<> if the
1159 // syntax can be accepted.
Bill Wendlingd350e022008-12-12 21:15:41 +00001160 [(set AL, (mul AL, (loadi8 addr:$src))),
1161 (implicit EFLAGS)]>; // AL,AH = AL*[mem8]
1162
Chris Lattnerba7e7562008-01-10 07:59:24 +00001163let mayLoad = 1, neverHasSideEffects = 1 in {
Evan Cheng24f2ea32007-09-14 21:48:26 +00001164let Defs = [AX,DX,EFLAGS], Uses = [AX] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001165def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
Bill Wendlingd350e022008-12-12 21:15:41 +00001166 "mul{w}\t$src",
1167 []>, OpSize; // AX,DX = AX*[mem16]
1168
Evan Cheng24f2ea32007-09-14 21:48:26 +00001169let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001170def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
Bill Wendlingd350e022008-12-12 21:15:41 +00001171 "mul{l}\t$src",
1172 []>; // EAX,EDX = EAX*[mem32]
Chris Lattnerba7e7562008-01-10 07:59:24 +00001173}
Chris Lattner1cca5e32003-08-03 21:54:21 +00001174
Chris Lattnerba7e7562008-01-10 07:59:24 +00001175let neverHasSideEffects = 1 in {
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001176let Defs = [AL,EFLAGS,AX], Uses = [AL] in
Evan Cheng071a2792007-09-11 19:55:27 +00001177def IMUL8r : I<0xF6, MRM5r, (outs), (ins GR8:$src), "imul{b}\t$src", []>;
1178 // AL,AH = AL*GR8
Evan Cheng24f2ea32007-09-14 21:48:26 +00001179let Defs = [AX,DX,EFLAGS], Uses = [AX] in
Dan Gohmanb1576f52007-07-31 20:11:57 +00001180def IMUL16r : I<0xF7, MRM5r, (outs), (ins GR16:$src), "imul{w}\t$src", []>,
Evan Cheng071a2792007-09-11 19:55:27 +00001181 OpSize; // AX,DX = AX*GR16
Evan Cheng24f2ea32007-09-14 21:48:26 +00001182let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
Evan Cheng071a2792007-09-11 19:55:27 +00001183def IMUL32r : I<0xF7, MRM5r, (outs), (ins GR32:$src), "imul{l}\t$src", []>;
1184 // EAX,EDX = EAX*GR32
Chris Lattnerba7e7562008-01-10 07:59:24 +00001185let mayLoad = 1 in {
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001186let Defs = [AL,EFLAGS,AX], Uses = [AL] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001187def IMUL8m : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
Evan Cheng071a2792007-09-11 19:55:27 +00001188 "imul{b}\t$src", []>; // AL,AH = AL*[mem8]
Evan Cheng24f2ea32007-09-14 21:48:26 +00001189let Defs = [AX,DX,EFLAGS], Uses = [AX] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001190def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
Evan Cheng071a2792007-09-11 19:55:27 +00001191 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
Eli Friedmanba7b1c42009-12-26 20:08:30 +00001192let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
Evan Cheng64d80e32007-07-19 01:14:50 +00001193def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
Evan Cheng071a2792007-09-11 19:55:27 +00001194 "imul{l}\t$src", []>; // EAX,EDX = EAX*[mem32]
Chris Lattnerba7e7562008-01-10 07:59:24 +00001195}
Dan Gohmanc99da132008-11-18 21:29:14 +00001196} // neverHasSideEffects
Chris Lattner1e6a7152005-04-06 04:19:22 +00001197
Chris Lattnerc8f45872003-08-04 04:59:56 +00001198// unsigned division/remainder
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001199let Defs = [AL,EFLAGS,AX], Uses = [AX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001200def DIV8r : I<0xF6, MRM6r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
Evan Cheng071a2792007-09-11 19:55:27 +00001201 "div{b}\t$src", []>;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001202let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001203def DIV16r : I<0xF7, MRM6r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
Evan Cheng071a2792007-09-11 19:55:27 +00001204 "div{w}\t$src", []>, OpSize;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001205let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001206def DIV32r : I<0xF7, MRM6r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
Evan Cheng071a2792007-09-11 19:55:27 +00001207 "div{l}\t$src", []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +00001208let mayLoad = 1 in {
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001209let Defs = [AL,EFLAGS,AX], Uses = [AX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001210def DIV8m : I<0xF6, MRM6m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
Evan Cheng071a2792007-09-11 19:55:27 +00001211 "div{b}\t$src", []>;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001212let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001213def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
Evan Cheng071a2792007-09-11 19:55:27 +00001214 "div{w}\t$src", []>, OpSize;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001215let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001216 // EDX:EAX/[mem32] = EAX,EDX
1217def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
Evan Cheng071a2792007-09-11 19:55:27 +00001218 "div{l}\t$src", []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +00001219}
Chris Lattner1cca5e32003-08-03 21:54:21 +00001220
Chris Lattnerfc752712004-08-01 09:52:59 +00001221// Signed division/remainder.
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001222let Defs = [AL,EFLAGS,AX], Uses = [AX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001223def IDIV8r : I<0xF6, MRM7r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
Evan Cheng071a2792007-09-11 19:55:27 +00001224 "idiv{b}\t$src", []>;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001225let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001226def IDIV16r: I<0xF7, MRM7r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
Evan Cheng071a2792007-09-11 19:55:27 +00001227 "idiv{w}\t$src", []>, OpSize;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001228let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001229def IDIV32r: I<0xF7, MRM7r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
Evan Cheng071a2792007-09-11 19:55:27 +00001230 "idiv{l}\t$src", []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +00001231let mayLoad = 1, mayLoad = 1 in {
Jakob Stoklund Olesen3cfe0102010-03-04 20:42:07 +00001232let Defs = [AL,EFLAGS,AX], Uses = [AX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001233def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
Evan Cheng071a2792007-09-11 19:55:27 +00001234 "idiv{b}\t$src", []>;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001235let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001236def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
Evan Cheng071a2792007-09-11 19:55:27 +00001237 "idiv{w}\t$src", []>, OpSize;
Evan Cheng24f2ea32007-09-14 21:48:26 +00001238let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001239def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src),
1240 // EDX:EAX/[mem32] = EAX,EDX
Evan Cheng071a2792007-09-11 19:55:27 +00001241 "idiv{l}\t$src", []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +00001242}
Chris Lattner1cca5e32003-08-03 21:54:21 +00001243
Chris Lattner1cca5e32003-08-03 21:54:21 +00001244//===----------------------------------------------------------------------===//
Chris Lattnerba7e7562008-01-10 07:59:24 +00001245// Two address Instructions.
Chris Lattner1cca5e32003-08-03 21:54:21 +00001246//
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001247let isTwoAddress = 1 in {
Chris Lattner1cca5e32003-08-03 21:54:21 +00001248
Alkis Evlogimenosa3f66842004-03-12 17:59:56 +00001249// Conditional moves
Evan Cheng0488db92007-09-25 01:57:46 +00001250let Uses = [EFLAGS] in {
Dan Gohmancbbea0f2009-08-27 00:14:12 +00001251
Chris Lattner314a1132010-03-14 18:31:44 +00001252let Predicates = [HasCMov] in {
Dan Gohmana4c5c332009-08-27 18:16:24 +00001253let isCommutable = 1 in {
Evan Cheng069287d2006-05-16 07:21:53 +00001254def CMOVB16rr : I<0x42, MRMSrcReg, // if <u, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001255 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001256 "cmovb{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001257 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001258 X86_COND_B, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001259 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001260def CMOVB32rr : I<0x42, MRMSrcReg, // if <u, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001261 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001262 "cmovb{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001263 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001264 X86_COND_B, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001265 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001266def CMOVAE16rr: I<0x43, MRMSrcReg, // if >=u, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001267 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001268 "cmovae{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001269 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001270 X86_COND_AE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001271 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001272def CMOVAE32rr: I<0x43, MRMSrcReg, // if >=u, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001273 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001274 "cmovae{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001275 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001276 X86_COND_AE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001277 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001278def CMOVE16rr : I<0x44, MRMSrcReg, // if ==, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001279 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001280 "cmove{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001281 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001282 X86_COND_E, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001283 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001284def CMOVE32rr : I<0x44, MRMSrcReg, // if ==, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001285 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001286 "cmove{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001287 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001288 X86_COND_E, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001289 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001290def CMOVNE16rr: I<0x45, MRMSrcReg, // if !=, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001291 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001292 "cmovne{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001293 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001294 X86_COND_NE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001295 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001296def CMOVNE32rr: I<0x45, MRMSrcReg, // if !=, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001297 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001298 "cmovne{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001299 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001300 X86_COND_NE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001301 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001302def CMOVBE16rr: I<0x46, MRMSrcReg, // if <=u, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001303 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001304 "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001305 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001306 X86_COND_BE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001307 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001308def CMOVBE32rr: I<0x46, MRMSrcReg, // if <=u, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001309 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001310 "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001311 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001312 X86_COND_BE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001313 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001314def CMOVA16rr : I<0x47, MRMSrcReg, // if >u, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001315 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001316 "cmova{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001317 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001318 X86_COND_A, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001319 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001320def CMOVA32rr : I<0x47, MRMSrcReg, // if >u, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001321 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001322 "cmova{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001323 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001324 X86_COND_A, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001325 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001326def CMOVL16rr : I<0x4C, MRMSrcReg, // if <s, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001327 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001328 "cmovl{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001329 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001330 X86_COND_L, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001331 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001332def CMOVL32rr : I<0x4C, MRMSrcReg, // if <s, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001333 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001334 "cmovl{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001335 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001336 X86_COND_L, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001337 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001338def CMOVGE16rr: I<0x4D, MRMSrcReg, // if >=s, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001339 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001340 "cmovge{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001341 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001342 X86_COND_GE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001343 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001344def CMOVGE32rr: I<0x4D, MRMSrcReg, // if >=s, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001345 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001346 "cmovge{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001347 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001348 X86_COND_GE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001349 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001350def CMOVLE16rr: I<0x4E, MRMSrcReg, // if <=s, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001351 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001352 "cmovle{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001353 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001354 X86_COND_LE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001355 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001356def CMOVLE32rr: I<0x4E, MRMSrcReg, // if <=s, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001357 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001358 "cmovle{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001359 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001360 X86_COND_LE, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001361 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001362def CMOVG16rr : I<0x4F, MRMSrcReg, // if >s, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001363 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001364 "cmovg{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001365 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001366 X86_COND_G, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001367 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001368def CMOVG32rr : I<0x4F, MRMSrcReg, // if >s, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001369 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001370 "cmovg{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001371 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001372 X86_COND_G, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001373 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001374def CMOVS16rr : I<0x48, MRMSrcReg, // if signed, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001375 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001376 "cmovs{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001377 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001378 X86_COND_S, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001379 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001380def CMOVS32rr : I<0x48, MRMSrcReg, // if signed, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001381 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001382 "cmovs{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001383 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001384 X86_COND_S, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001385 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001386def CMOVNS16rr: I<0x49, MRMSrcReg, // if !signed, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001387 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001388 "cmovns{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001389 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001390 X86_COND_NS, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001391 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001392def CMOVNS32rr: I<0x49, MRMSrcReg, // if !signed, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001393 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001394 "cmovns{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001395 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001396 X86_COND_NS, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001397 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001398def CMOVP16rr : I<0x4A, MRMSrcReg, // if parity, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001399 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001400 "cmovp{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001401 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001402 X86_COND_P, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001403 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001404def CMOVP32rr : I<0x4A, MRMSrcReg, // if parity, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001405 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001406 "cmovp{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001407 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001408 X86_COND_P, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001409 TB;
Evan Cheng069287d2006-05-16 07:21:53 +00001410def CMOVNP16rr : I<0x4B, MRMSrcReg, // if !parity, GR16 = GR16
Evan Cheng64d80e32007-07-19 01:14:50 +00001411 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001412 "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001413 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001414 X86_COND_NP, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001415 TB, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00001416def CMOVNP32rr : I<0x4B, MRMSrcReg, // if !parity, GR32 = GR32
Evan Cheng64d80e32007-07-19 01:14:50 +00001417 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001418 "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00001419 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +00001420 X86_COND_NP, EFLAGS))]>,
Evan Cheng71fb9ad2006-01-26 00:29:36 +00001421 TB;
Dan Gohman305fceb2009-01-07 00:35:10 +00001422def CMOVO16rr : I<0x40, MRMSrcReg, // if overflow, GR16 = GR16
1423 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001424 "cmovo{w}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001425 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1426 X86_COND_O, EFLAGS))]>,
1427 TB, OpSize;
1428def CMOVO32rr : I<0x40, MRMSrcReg, // if overflow, GR32 = GR32
1429 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001430 "cmovo{l}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001431 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1432 X86_COND_O, EFLAGS))]>,
Evan Cheng0488db92007-09-25 01:57:46 +00001433 TB;
Dan Gohman305fceb2009-01-07 00:35:10 +00001434def CMOVNO16rr : I<0x41, MRMSrcReg, // if !overflow, GR16 = GR16
1435 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001436 "cmovno{w}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001437 [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1438 X86_COND_NO, EFLAGS))]>,
1439 TB, OpSize;
1440def CMOVNO32rr : I<0x41, MRMSrcReg, // if !overflow, GR32 = GR32
1441 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001442 "cmovno{l}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001443 [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1444 X86_COND_NO, EFLAGS))]>,
1445 TB;
1446} // isCommutable = 1
Evan Cheng7ad42d92007-10-05 23:13:21 +00001447
1448def CMOVB16rm : I<0x42, MRMSrcMem, // if <u, GR16 = [mem16]
1449 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001450 "cmovb{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001451 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1452 X86_COND_B, EFLAGS))]>,
1453 TB, OpSize;
1454def CMOVB32rm : I<0x42, MRMSrcMem, // if <u, GR32 = [mem32]
1455 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001456 "cmovb{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001457 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1458 X86_COND_B, EFLAGS))]>,
1459 TB;
1460def CMOVAE16rm: I<0x43, MRMSrcMem, // if >=u, GR16 = [mem16]
1461 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001462 "cmovae{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001463 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1464 X86_COND_AE, EFLAGS))]>,
1465 TB, OpSize;
1466def CMOVAE32rm: I<0x43, MRMSrcMem, // if >=u, GR32 = [mem32]
1467 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001468 "cmovae{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001469 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1470 X86_COND_AE, EFLAGS))]>,
1471 TB;
1472def CMOVE16rm : I<0x44, MRMSrcMem, // if ==, GR16 = [mem16]
1473 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001474 "cmove{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001475 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1476 X86_COND_E, EFLAGS))]>,
1477 TB, OpSize;
1478def CMOVE32rm : I<0x44, MRMSrcMem, // if ==, GR32 = [mem32]
1479 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001480 "cmove{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001481 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1482 X86_COND_E, EFLAGS))]>,
1483 TB;
1484def CMOVNE16rm: I<0x45, MRMSrcMem, // if !=, GR16 = [mem16]
1485 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001486 "cmovne{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001487 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1488 X86_COND_NE, EFLAGS))]>,
1489 TB, OpSize;
1490def CMOVNE32rm: I<0x45, MRMSrcMem, // if !=, GR32 = [mem32]
1491 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001492 "cmovne{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001493 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1494 X86_COND_NE, EFLAGS))]>,
1495 TB;
1496def CMOVBE16rm: I<0x46, MRMSrcMem, // if <=u, GR16 = [mem16]
1497 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001498 "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001499 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1500 X86_COND_BE, EFLAGS))]>,
1501 TB, OpSize;
1502def CMOVBE32rm: I<0x46, MRMSrcMem, // if <=u, GR32 = [mem32]
1503 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001504 "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001505 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1506 X86_COND_BE, EFLAGS))]>,
1507 TB;
1508def CMOVA16rm : I<0x47, MRMSrcMem, // if >u, GR16 = [mem16]
1509 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001510 "cmova{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001511 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1512 X86_COND_A, EFLAGS))]>,
1513 TB, OpSize;
1514def CMOVA32rm : I<0x47, MRMSrcMem, // if >u, GR32 = [mem32]
1515 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001516 "cmova{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001517 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1518 X86_COND_A, EFLAGS))]>,
1519 TB;
1520def CMOVL16rm : I<0x4C, MRMSrcMem, // if <s, GR16 = [mem16]
1521 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001522 "cmovl{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001523 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1524 X86_COND_L, EFLAGS))]>,
1525 TB, OpSize;
1526def CMOVL32rm : I<0x4C, MRMSrcMem, // if <s, GR32 = [mem32]
1527 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001528 "cmovl{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001529 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1530 X86_COND_L, EFLAGS))]>,
1531 TB;
1532def CMOVGE16rm: I<0x4D, MRMSrcMem, // if >=s, GR16 = [mem16]
1533 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001534 "cmovge{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001535 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1536 X86_COND_GE, EFLAGS))]>,
1537 TB, OpSize;
1538def CMOVGE32rm: I<0x4D, MRMSrcMem, // if >=s, GR32 = [mem32]
1539 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001540 "cmovge{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001541 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1542 X86_COND_GE, EFLAGS))]>,
1543 TB;
1544def CMOVLE16rm: I<0x4E, MRMSrcMem, // if <=s, GR16 = [mem16]
1545 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001546 "cmovle{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001547 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1548 X86_COND_LE, EFLAGS))]>,
1549 TB, OpSize;
1550def CMOVLE32rm: I<0x4E, MRMSrcMem, // if <=s, GR32 = [mem32]
1551 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001552 "cmovle{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001553 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1554 X86_COND_LE, EFLAGS))]>,
1555 TB;
1556def CMOVG16rm : I<0x4F, MRMSrcMem, // if >s, GR16 = [mem16]
1557 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001558 "cmovg{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001559 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1560 X86_COND_G, EFLAGS))]>,
1561 TB, OpSize;
1562def CMOVG32rm : I<0x4F, MRMSrcMem, // if >s, GR32 = [mem32]
1563 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001564 "cmovg{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001565 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1566 X86_COND_G, EFLAGS))]>,
1567 TB;
1568def CMOVS16rm : I<0x48, MRMSrcMem, // if signed, GR16 = [mem16]
1569 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001570 "cmovs{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001571 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1572 X86_COND_S, EFLAGS))]>,
1573 TB, OpSize;
1574def CMOVS32rm : I<0x48, MRMSrcMem, // if signed, GR32 = [mem32]
1575 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001576 "cmovs{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001577 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1578 X86_COND_S, EFLAGS))]>,
1579 TB;
1580def CMOVNS16rm: I<0x49, MRMSrcMem, // if !signed, GR16 = [mem16]
1581 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001582 "cmovns{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001583 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1584 X86_COND_NS, EFLAGS))]>,
1585 TB, OpSize;
1586def CMOVNS32rm: I<0x49, MRMSrcMem, // if !signed, GR32 = [mem32]
1587 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001588 "cmovns{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001589 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1590 X86_COND_NS, EFLAGS))]>,
1591 TB;
1592def CMOVP16rm : I<0x4A, MRMSrcMem, // if parity, GR16 = [mem16]
1593 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001594 "cmovp{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001595 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1596 X86_COND_P, EFLAGS))]>,
1597 TB, OpSize;
1598def CMOVP32rm : I<0x4A, MRMSrcMem, // if parity, GR32 = [mem32]
1599 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001600 "cmovp{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001601 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1602 X86_COND_P, EFLAGS))]>,
1603 TB;
1604def CMOVNP16rm : I<0x4B, MRMSrcMem, // if !parity, GR16 = [mem16]
1605 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001606 "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng7ad42d92007-10-05 23:13:21 +00001607 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1608 X86_COND_NP, EFLAGS))]>,
1609 TB, OpSize;
Dan Gohman305fceb2009-01-07 00:35:10 +00001610def CMOVNP32rm : I<0x4B, MRMSrcMem, // if !parity, GR32 = [mem32]
1611 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001612 "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001613 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1614 X86_COND_NP, EFLAGS))]>,
1615 TB;
1616def CMOVO16rm : I<0x40, MRMSrcMem, // if overflow, GR16 = [mem16]
1617 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001618 "cmovo{w}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001619 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1620 X86_COND_O, EFLAGS))]>,
1621 TB, OpSize;
1622def CMOVO32rm : I<0x40, MRMSrcMem, // if overflow, GR32 = [mem32]
1623 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001624 "cmovo{l}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001625 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1626 X86_COND_O, EFLAGS))]>,
1627 TB;
1628def CMOVNO16rm : I<0x41, MRMSrcMem, // if !overflow, GR16 = [mem16]
1629 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001630 "cmovno{w}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001631 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1632 X86_COND_NO, EFLAGS))]>,
1633 TB, OpSize;
1634def CMOVNO32rm : I<0x41, MRMSrcMem, // if !overflow, GR32 = [mem32]
1635 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001636 "cmovno{l}\t{$src2, $dst|$dst, $src2}",
Dan Gohman305fceb2009-01-07 00:35:10 +00001637 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1638 X86_COND_NO, EFLAGS))]>,
1639 TB;
Chris Lattner314a1132010-03-14 18:31:44 +00001640} // Predicates = [HasCMov]
1641
1642// X86 doesn't have 8-bit conditional moves. Use a customInserter to
1643// emit control flow. An alternative to this is to mark i8 SELECT as Promote,
1644// however that requires promoting the operands, and can induce additional
1645// i8 register pressure. Note that CMOV_GR8 is conservatively considered to
1646// clobber EFLAGS, because if one of the operands is zero, the expansion
1647// could involve an xor.
1648let usesCustomInserter = 1, isTwoAddress = 0, Defs = [EFLAGS] in {
1649def CMOV_GR8 : I<0, Pseudo,
1650 (outs GR8:$dst), (ins GR8:$src1, GR8:$src2, i8imm:$cond),
1651 "#CMOV_GR8 PSEUDO!",
1652 [(set GR8:$dst, (X86cmov GR8:$src1, GR8:$src2,
1653 imm:$cond, EFLAGS))]>;
1654
1655let Predicates = [NoCMov] in {
1656def CMOV_GR32 : I<0, Pseudo,
1657 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$cond),
1658 "#CMOV_GR32* PSEUDO!",
1659 [(set GR32:$dst,
1660 (X86cmov GR32:$src1, GR32:$src2, imm:$cond, EFLAGS))]>;
1661def CMOV_GR16 : I<0, Pseudo,
1662 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cond),
1663 "#CMOV_GR16* PSEUDO!",
1664 [(set GR16:$dst,
1665 (X86cmov GR16:$src1, GR16:$src2, imm:$cond, EFLAGS))]>;
1666def CMOV_RFP32 : I<0, Pseudo,
1667 (outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2, i8imm:$cond),
1668 "#CMOV_RFP32 PSEUDO!",
1669 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2, imm:$cond,
1670 EFLAGS))]>;
1671def CMOV_RFP64 : I<0, Pseudo,
1672 (outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2, i8imm:$cond),
1673 "#CMOV_RFP64 PSEUDO!",
1674 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2, imm:$cond,
1675 EFLAGS))]>;
1676def CMOV_RFP80 : I<0, Pseudo,
1677 (outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2, i8imm:$cond),
1678 "#CMOV_RFP80 PSEUDO!",
1679 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2, imm:$cond,
1680 EFLAGS))]>;
1681} // Predicates = [NoCMov]
1682} // UsesCustomInserter = 1, isTwoAddress = 0, Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001683} // Uses = [EFLAGS]
1684
1685
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001686// unary instructions
Evan Cheng1693e482006-07-19 00:27:29 +00001687let CodeSize = 2 in {
Evan Cheng24f2ea32007-09-14 21:48:26 +00001688let Defs = [EFLAGS] in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001689def NEG8r : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src), "neg{b}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001690 [(set GR8:$dst, (ineg GR8:$src)),
1691 (implicit EFLAGS)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001692def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src), "neg{w}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001693 [(set GR16:$dst, (ineg GR16:$src)),
1694 (implicit EFLAGS)]>, OpSize;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001695def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src), "neg{l}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001696 [(set GR32:$dst, (ineg GR32:$src)),
1697 (implicit EFLAGS)]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001698let isTwoAddress = 0 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001699 def NEG8m : I<0xF6, MRM3m, (outs), (ins i8mem :$dst), "neg{b}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001700 [(store (ineg (loadi8 addr:$dst)), addr:$dst),
1701 (implicit EFLAGS)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001702 def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst), "neg{w}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001703 [(store (ineg (loadi16 addr:$dst)), addr:$dst),
1704 (implicit EFLAGS)]>, OpSize;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001705 def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst), "neg{l}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001706 [(store (ineg (loadi32 addr:$dst)), addr:$dst),
1707 (implicit EFLAGS)]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001708}
Evan Cheng24f2ea32007-09-14 21:48:26 +00001709} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001710
Evan Chengaaf414c2009-01-21 02:09:05 +00001711// Match xor -1 to not. Favors these over a move imm + xor to save code size.
1712let AddedComplexity = 15 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001713def NOT8r : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src), "not{b}\t$dst",
Evan Cheng069287d2006-05-16 07:21:53 +00001714 [(set GR8:$dst, (not GR8:$src))]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001715def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src), "not{w}\t$dst",
Evan Cheng069287d2006-05-16 07:21:53 +00001716 [(set GR16:$dst, (not GR16:$src))]>, OpSize;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001717def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src), "not{l}\t$dst",
Evan Cheng069287d2006-05-16 07:21:53 +00001718 [(set GR32:$dst, (not GR32:$src))]>;
Evan Chengaaf414c2009-01-21 02:09:05 +00001719}
Chris Lattner57a02302004-08-11 04:31:00 +00001720let isTwoAddress = 0 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001721 def NOT8m : I<0xF6, MRM2m, (outs), (ins i8mem :$dst), "not{b}\t$dst",
Evan Cheng605c4152005-12-13 01:57:51 +00001722 [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001723 def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst), "not{w}\t$dst",
Evan Cheng605c4152005-12-13 01:57:51 +00001724 [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001725 def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst), "not{l}\t$dst",
Evan Cheng605c4152005-12-13 01:57:51 +00001726 [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001727}
Evan Cheng1693e482006-07-19 00:27:29 +00001728} // CodeSize
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001729
Evan Chengb51a0592005-12-10 00:48:20 +00001730// TODO: inc/dec is slow for P4, but fast for Pentium-M.
Evan Cheng24f2ea32007-09-14 21:48:26 +00001731let Defs = [EFLAGS] in {
Evan Cheng1693e482006-07-19 00:27:29 +00001732let CodeSize = 2 in
Dan Gohmanb1576f52007-07-31 20:11:57 +00001733def INC8r : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src), "inc{b}\t$dst",
Chris Lattnerc54a2f12010-03-24 01:02:12 +00001734 [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src))]>;
1735
Evan Cheng1693e482006-07-19 00:27:29 +00001736let isConvertibleToThreeAddress = 1, CodeSize = 1 in { // Can xform into LEA.
Sean Callanan108934c2009-12-18 00:01:26 +00001737def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src),
1738 "inc{w}\t$dst",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001739 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src))]>,
Evan Cheng25ab6902006-09-08 06:48:29 +00001740 OpSize, Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001741def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src),
1742 "inc{l}\t$dst",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001743 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src))]>,
1744 Requires<[In32BitMode]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00001745}
Evan Cheng1693e482006-07-19 00:27:29 +00001746let isTwoAddress = 0, CodeSize = 2 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001747 def INC8m : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001748 [(store (add (loadi8 addr:$dst), 1), addr:$dst),
1749 (implicit EFLAGS)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001750 def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001751 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
1752 (implicit EFLAGS)]>,
Evan Cheng66f71632007-10-19 21:23:22 +00001753 OpSize, Requires<[In32BitMode]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001754 def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001755 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
1756 (implicit EFLAGS)]>,
Evan Cheng66f71632007-10-19 21:23:22 +00001757 Requires<[In32BitMode]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001758}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001759
Evan Cheng1693e482006-07-19 00:27:29 +00001760let CodeSize = 2 in
Dan Gohmanb1576f52007-07-31 20:11:57 +00001761def DEC8r : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src), "dec{b}\t$dst",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001762 [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src))]>;
Evan Cheng1693e482006-07-19 00:27:29 +00001763let isConvertibleToThreeAddress = 1, CodeSize = 1 in { // Can xform into LEA.
Sean Callanan108934c2009-12-18 00:01:26 +00001764def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src),
1765 "dec{w}\t$dst",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001766 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src))]>,
Evan Cheng25ab6902006-09-08 06:48:29 +00001767 OpSize, Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001768def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src),
1769 "dec{l}\t$dst",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001770 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src))]>,
1771 Requires<[In32BitMode]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00001772}
Chris Lattner57a02302004-08-11 04:31:00 +00001773
Evan Cheng1693e482006-07-19 00:27:29 +00001774let isTwoAddress = 0, CodeSize = 2 in {
Dan Gohmanb1576f52007-07-31 20:11:57 +00001775 def DEC8m : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001776 [(store (add (loadi8 addr:$dst), -1), addr:$dst),
1777 (implicit EFLAGS)]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001778 def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001779 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
1780 (implicit EFLAGS)]>,
Evan Cheng66f71632007-10-19 21:23:22 +00001781 OpSize, Requires<[In32BitMode]>;
Dan Gohmanb1576f52007-07-31 20:11:57 +00001782 def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001783 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
1784 (implicit EFLAGS)]>,
Evan Cheng66f71632007-10-19 21:23:22 +00001785 Requires<[In32BitMode]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001786}
Evan Cheng24f2ea32007-09-14 21:48:26 +00001787} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001788
1789// Logical operators...
Evan Cheng24f2ea32007-09-14 21:48:26 +00001790let Defs = [EFLAGS] in {
Chris Lattnercc65bee2005-01-02 02:35:46 +00001791let isCommutable = 1 in { // X = AND Y, Z --> X = AND Z, Y
Chris Lattner589ad5d2010-03-25 05:44:01 +00001792def AND8rr : I<0x20, MRMDestReg,
1793 (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1794 "and{b}\t{$src2, $dst|$dst, $src2}",
1795 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
1796def AND16rr : I<0x21, MRMDestReg,
1797 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1798 "and{w}\t{$src2, $dst|$dst, $src2}",
1799 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1800 GR16:$src2))]>, OpSize;
1801def AND32rr : I<0x21, MRMDestReg,
1802 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1803 "and{l}\t{$src2, $dst|$dst, $src2}",
1804 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1805 GR32:$src2))]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00001806}
Chris Lattner57a02302004-08-11 04:31:00 +00001807
Sean Callanan108934c2009-12-18 00:01:26 +00001808// AND instructions with the destination register in REG and the source register
1809// in R/M. Included for the disassembler.
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001810let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001811def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1812 "and{b}\t{$src2, $dst|$dst, $src2}", []>;
1813def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst),
1814 (ins GR16:$src1, GR16:$src2),
1815 "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1816def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst),
1817 (ins GR32:$src1, GR32:$src2),
1818 "and{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001819}
Sean Callanan108934c2009-12-18 00:01:26 +00001820
Chris Lattner3a173df2004-10-03 20:35:00 +00001821def AND8rm : I<0x22, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001822 (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001823 "and{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001824 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1825 (loadi8 addr:$src2)))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001826def AND16rm : I<0x23, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001827 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001828 "and{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001829 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1830 (loadi16 addr:$src2)))]>,
1831 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001832def AND32rm : I<0x23, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001833 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001834 "and{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001835 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1836 (loadi32 addr:$src2)))]>;
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001837
Chris Lattner3a173df2004-10-03 20:35:00 +00001838def AND8ri : Ii8<0x80, MRM4r,
Evan Cheng64d80e32007-07-19 01:14:50 +00001839 (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001840 "and{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001841 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1842 imm:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001843def AND16ri : Ii16<0x81, MRM4r,
Evan Cheng64d80e32007-07-19 01:14:50 +00001844 (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001845 "and{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001846 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1847 imm:$src2))]>, OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001848def AND32ri : Ii32<0x81, MRM4r,
Evan Cheng64d80e32007-07-19 01:14:50 +00001849 (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001850 "and{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001851 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1852 imm:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001853def AND16ri8 : Ii8<0x83, MRM4r,
Evan Cheng64d80e32007-07-19 01:14:50 +00001854 (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001855 "and{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001856 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1857 i16immSExt8:$src2))]>,
Evan Cheng9b6b6422005-12-13 00:14:11 +00001858 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001859def AND32ri8 : Ii8<0x83, MRM4r,
Evan Cheng64d80e32007-07-19 01:14:50 +00001860 (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001861 "and{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001862 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1863 i32immSExt8:$src2))]>;
Chris Lattnerf29ed092004-08-11 05:07:25 +00001864
1865let isTwoAddress = 0 in {
Chris Lattner3a173df2004-10-03 20:35:00 +00001866 def AND8mr : I<0x20, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001867 (outs), (ins i8mem :$dst, GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001868 "and{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001869 [(store (and (load addr:$dst), GR8:$src), addr:$dst),
1870 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001871 def AND16mr : I<0x21, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001872 (outs), (ins i16mem:$dst, GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001873 "and{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001874 [(store (and (load addr:$dst), GR16:$src), addr:$dst),
1875 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00001876 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001877 def AND32mr : I<0x21, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001878 (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001879 "and{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001880 [(store (and (load addr:$dst), GR32:$src), addr:$dst),
1881 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001882 def AND8mi : Ii8<0x80, MRM4m,
Evan Cheng64d80e32007-07-19 01:14:50 +00001883 (outs), (ins i8mem :$dst, i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001884 "and{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001885 [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
1886 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001887 def AND16mi : Ii16<0x81, MRM4m,
Evan Cheng64d80e32007-07-19 01:14:50 +00001888 (outs), (ins i16mem:$dst, i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001889 "and{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001890 [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
1891 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00001892 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001893 def AND32mi : Ii32<0x81, MRM4m,
Evan Cheng64d80e32007-07-19 01:14:50 +00001894 (outs), (ins i32mem:$dst, i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001895 "and{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001896 [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
1897 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00001898 def AND16mi8 : Ii8<0x83, MRM4m,
Evan Cheng64d80e32007-07-19 01:14:50 +00001899 (outs), (ins i16mem:$dst, i16i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001900 "and{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001901 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
1902 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00001903 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00001904 def AND32mi8 : Ii8<0x83, MRM4m,
Evan Cheng64d80e32007-07-19 01:14:50 +00001905 (outs), (ins i32mem:$dst, i32i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001906 "and{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001907 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
1908 (implicit EFLAGS)]>;
Sean Callanana09caa52009-09-02 00:55:49 +00001909
1910 def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
1911 "and{b}\t{$src, %al|%al, $src}", []>;
1912 def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
1913 "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1914 def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
1915 "and{l}\t{$src, %eax|%eax, $src}", []>;
1916
Chris Lattnerf29ed092004-08-11 05:07:25 +00001917}
1918
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001919
Chris Lattnercc65bee2005-01-02 02:35:46 +00001920let isCommutable = 1 in { // X = OR Y, Z --> X = OR Z, Y
Sean Callanan108934c2009-12-18 00:01:26 +00001921def OR8rr : I<0x08, MRMDestReg, (outs GR8 :$dst),
1922 (ins GR8 :$src1, GR8 :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001923 "or{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001924 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001925def OR16rr : I<0x09, MRMDestReg, (outs GR16:$dst),
1926 (ins GR16:$src1, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001927 "or{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001928 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
1929 OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001930def OR32rr : I<0x09, MRMDestReg, (outs GR32:$dst),
1931 (ins GR32:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001932 "or{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001933 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00001934}
Sean Callanan108934c2009-12-18 00:01:26 +00001935
1936// OR instructions with the destination register in REG and the source register
1937// in R/M. Included for the disassembler.
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001938let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001939def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1940 "or{b}\t{$src2, $dst|$dst, $src2}", []>;
1941def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
1942 (ins GR16:$src1, GR16:$src2),
1943 "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1944def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst),
1945 (ins GR32:$src1, GR32:$src2),
1946 "or{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001947}
Sean Callanan108934c2009-12-18 00:01:26 +00001948
Chris Lattner589ad5d2010-03-25 05:44:01 +00001949def OR8rm : I<0x0A, MRMSrcMem, (outs GR8 :$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001950 (ins GR8 :$src1, i8mem :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001951 "or{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001952 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
1953 (load addr:$src2)))]>;
1954def OR16rm : I<0x0B, MRMSrcMem, (outs GR16:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001955 (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001956 "or{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001957 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1958 (load addr:$src2)))]>,
1959 OpSize;
1960def OR32rm : I<0x0B, MRMSrcMem, (outs GR32:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001961 (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001962 "or{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001963 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1964 (load addr:$src2)))]>;
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001965
Sean Callanan108934c2009-12-18 00:01:26 +00001966def OR8ri : Ii8 <0x80, MRM1r, (outs GR8 :$dst),
1967 (ins GR8 :$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001968 "or{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001969 [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001970def OR16ri : Ii16<0x81, MRM1r, (outs GR16:$dst),
1971 (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001972 "or{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001973 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1974 imm:$src2))]>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001975def OR32ri : Ii32<0x81, MRM1r, (outs GR32:$dst),
1976 (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001977 "or{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001978 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1979 imm:$src2))]>;
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001980
Sean Callanan108934c2009-12-18 00:01:26 +00001981def OR16ri8 : Ii8<0x83, MRM1r, (outs GR16:$dst),
1982 (ins GR16:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001983 "or{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001984 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1985 i16immSExt8:$src2))]>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001986def OR32ri8 : Ii8<0x83, MRM1r, (outs GR32:$dst),
1987 (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001988 "or{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00001989 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1990 i32immSExt8:$src2))]>;
Chris Lattner57a02302004-08-11 04:31:00 +00001991let isTwoAddress = 0 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001992 def OR8mr : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001993 "or{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001994 [(store (or (load addr:$dst), GR8:$src), addr:$dst),
1995 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001996 def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001997 "or{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00001998 [(store (or (load addr:$dst), GR16:$src), addr:$dst),
1999 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002000 def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002001 "or{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002002 [(store (or (load addr:$dst), GR32:$src), addr:$dst),
2003 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002004 def OR8mi : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002005 "or{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002006 [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
2007 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002008 def OR16mi : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002009 "or{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002010 [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
2011 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00002012 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002013 def OR32mi : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002014 "or{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002015 [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
2016 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002017 def OR16mi8 : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002018 "or{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002019 [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
2020 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00002021 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002022 def OR32mi8 : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002023 "or{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002024 [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
2025 (implicit EFLAGS)]>;
Sean Callanand00025a2009-09-11 19:01:56 +00002026
2027 def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
2028 "or{b}\t{$src, %al|%al, $src}", []>;
2029 def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
2030 "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2031 def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
2032 "or{l}\t{$src, %eax|%eax, $src}", []>;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002033} // isTwoAddress = 0
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002034
2035
Evan Cheng359e9372008-06-18 08:13:07 +00002036let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002037 def XOR8rr : I<0x30, MRMDestReg,
2038 (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
2039 "xor{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002040 [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2041 GR8:$src2))]>;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002042 def XOR16rr : I<0x31, MRMDestReg,
2043 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
2044 "xor{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002045 [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2046 GR16:$src2))]>, OpSize;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002047 def XOR32rr : I<0x31, MRMDestReg,
2048 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
2049 "xor{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002050 [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2051 GR32:$src2))]>;
Evan Cheng359e9372008-06-18 08:13:07 +00002052} // isCommutable = 1
Chris Lattnercc65bee2005-01-02 02:35:46 +00002053
Sean Callanan108934c2009-12-18 00:01:26 +00002054// XOR instructions with the destination register in REG and the source register
2055// in R/M. Included for the disassembler.
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002056let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00002057def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2058 "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
2059def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst),
2060 (ins GR16:$src1, GR16:$src2),
2061 "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2062def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst),
2063 (ins GR32:$src1, GR32:$src2),
2064 "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002065}
Sean Callanan108934c2009-12-18 00:01:26 +00002066
Chris Lattner589ad5d2010-03-25 05:44:01 +00002067def XOR8rm : I<0x32, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002068 (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002069 "xor{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002070 [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2071 (load addr:$src2)))]>;
2072def XOR16rm : I<0x33, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002073 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002074 "xor{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002075 [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2076 (load addr:$src2)))]>,
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002077 OpSize;
Chris Lattner589ad5d2010-03-25 05:44:01 +00002078def XOR32rm : I<0x33, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002079 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002080 "xor{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002081 [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2082 (load addr:$src2)))]>;
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002083
Chris Lattner589ad5d2010-03-25 05:44:01 +00002084def XOR8ri : Ii8<0x80, MRM6r,
2085 (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2086 "xor{b}\t{$src2, $dst|$dst, $src2}",
2087 [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
2088def XOR16ri : Ii16<0x81, MRM6r,
2089 (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
2090 "xor{w}\t{$src2, $dst|$dst, $src2}",
2091 [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2092 imm:$src2))]>, OpSize;
Bill Wendling75cf88f2008-05-29 03:46:36 +00002093def XOR32ri : Ii32<0x81, MRM6r,
2094 (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2095 "xor{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002096 [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2097 imm:$src2))]>;
Bill Wendling75cf88f2008-05-29 03:46:36 +00002098def XOR16ri8 : Ii8<0x83, MRM6r,
2099 (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2100 "xor{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002101 [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2102 i16immSExt8:$src2))]>,
Bill Wendling75cf88f2008-05-29 03:46:36 +00002103 OpSize;
2104def XOR32ri8 : Ii8<0x83, MRM6r,
2105 (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2106 "xor{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattner589ad5d2010-03-25 05:44:01 +00002107 [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2108 i32immSExt8:$src2))]>;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002109
Chris Lattner57a02302004-08-11 04:31:00 +00002110let isTwoAddress = 0 in {
Chris Lattner3a173df2004-10-03 20:35:00 +00002111 def XOR8mr : I<0x30, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002112 (outs), (ins i8mem :$dst, GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002113 "xor{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002114 [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
2115 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00002116 def XOR16mr : I<0x31, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002117 (outs), (ins i16mem:$dst, GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002118 "xor{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002119 [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
2120 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00002121 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00002122 def XOR32mr : I<0x31, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002123 (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002124 "xor{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002125 [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
2126 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00002127 def XOR8mi : Ii8<0x80, MRM6m,
Evan Cheng64d80e32007-07-19 01:14:50 +00002128 (outs), (ins i8mem :$dst, i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002129 "xor{b}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002130 [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
2131 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00002132 def XOR16mi : Ii16<0x81, MRM6m,
Evan Cheng64d80e32007-07-19 01:14:50 +00002133 (outs), (ins i16mem:$dst, i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002134 "xor{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002135 [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
2136 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00002137 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00002138 def XOR32mi : Ii32<0x81, MRM6m,
Evan Cheng64d80e32007-07-19 01:14:50 +00002139 (outs), (ins i32mem:$dst, i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002140 "xor{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002141 [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
2142 (implicit EFLAGS)]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00002143 def XOR16mi8 : Ii8<0x83, MRM6m,
Evan Cheng64d80e32007-07-19 01:14:50 +00002144 (outs), (ins i16mem:$dst, i16i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002145 "xor{w}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002146 [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
2147 (implicit EFLAGS)]>,
Evan Cheng0ef3a772005-12-13 01:41:36 +00002148 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00002149 def XOR32mi8 : Ii8<0x83, MRM6m,
Evan Cheng64d80e32007-07-19 01:14:50 +00002150 (outs), (ins i32mem:$dst, i32i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002151 "xor{l}\t{$src, $dst|$dst, $src}",
Dan Gohman09a2609e2009-03-03 19:53:46 +00002152 [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
2153 (implicit EFLAGS)]>;
Sean Callanan7893ec62009-09-10 19:52:26 +00002154
Chris Lattner589ad5d2010-03-25 05:44:01 +00002155 def XOR8i8 : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
2156 "xor{b}\t{$src, %al|%al, $src}", []>;
2157 def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
2158 "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2159 def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
2160 "xor{l}\t{$src, %eax|%eax, $src}", []>;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002161} // isTwoAddress = 0
Evan Cheng24f2ea32007-09-14 21:48:26 +00002162} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002163
2164// Shift instructions
Evan Cheng24f2ea32007-09-14 21:48:26 +00002165let Defs = [EFLAGS] in {
Evan Cheng071a2792007-09-11 19:55:27 +00002166let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002167def SHL8rCL : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002168 "shl{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002169 [(set GR8:$dst, (shl GR8:$src, CL))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002170def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002171 "shl{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002172 [(set GR16:$dst, (shl GR16:$src, CL))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002173def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002174 "shl{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002175 [(set GR32:$dst, (shl GR32:$src, CL))]>;
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002176} // Uses = [CL]
Chris Lattnercc65bee2005-01-02 02:35:46 +00002177
Evan Cheng64d80e32007-07-19 01:14:50 +00002178def SHL8ri : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002179 "shl{b}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002180 [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00002181let isConvertibleToThreeAddress = 1 in { // Can transform into LEA.
Evan Cheng64d80e32007-07-19 01:14:50 +00002182def SHL16ri : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002183 "shl{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002184 [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002185def SHL32ri : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002186 "shl{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002187 [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
Sean Callanan13cf8e92009-09-16 02:28:43 +00002188
2189// NOTE: We don't include patterns for shifts of a register by one, because
2190// 'add reg,reg' is cheaper.
2191
2192def SHL8r1 : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
2193 "shl{b}\t$dst", []>;
2194def SHL16r1 : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
2195 "shl{w}\t$dst", []>, OpSize;
2196def SHL32r1 : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
2197 "shl{l}\t$dst", []>;
2198
Bill Wendlingbd0879d2008-05-29 01:02:09 +00002199} // isConvertibleToThreeAddress = 1
Evan Cheng09c54572006-06-29 00:36:51 +00002200
Chris Lattnerf29ed092004-08-11 05:07:25 +00002201let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002202 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002203 def SHL8mCL : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002204 "shl{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002205 [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002206 def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002207 "shl{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002208 [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002209 def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002210 "shl{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002211 [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
2212 }
Evan Cheng64d80e32007-07-19 01:14:50 +00002213 def SHL8mi : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002214 "shl{b}\t{$src, $dst|$dst, $src}",
Evan Cheng763b0292005-12-13 02:34:51 +00002215 [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002216 def SHL16mi : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002217 "shl{w}\t{$src, $dst|$dst, $src}",
Evan Cheng763b0292005-12-13 02:34:51 +00002218 [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2219 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002220 def SHL32mi : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002221 "shl{l}\t{$src, $dst|$dst, $src}",
Evan Cheng763b0292005-12-13 02:34:51 +00002222 [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002223
2224 // Shift by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002225 def SHL8m1 : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002226 "shl{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002227 [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002228 def SHL16m1 : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002229 "shl{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002230 [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2231 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002232 def SHL32m1 : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002233 "shl{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002234 [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
Chris Lattnerf29ed092004-08-11 05:07:25 +00002235}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002236
Evan Cheng071a2792007-09-11 19:55:27 +00002237let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002238def SHR8rCL : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002239 "shr{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002240 [(set GR8:$dst, (srl GR8:$src, CL))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002241def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002242 "shr{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002243 [(set GR16:$dst, (srl GR16:$src, CL))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002244def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002245 "shr{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002246 [(set GR32:$dst, (srl GR32:$src, CL))]>;
2247}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002248
Evan Cheng64d80e32007-07-19 01:14:50 +00002249def SHR8ri : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002250 "shr{b}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002251 [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002252def SHR16ri : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002253 "shr{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002254 [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002255def SHR32ri : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002256 "shr{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002257 [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf29ed092004-08-11 05:07:25 +00002258
Evan Cheng09c54572006-06-29 00:36:51 +00002259// Shift by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002260def SHR8r1 : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002261 "shr{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002262 [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002263def SHR16r1 : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002264 "shr{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002265 [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002266def SHR32r1 : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002267 "shr{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002268 [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
2269
Chris Lattner57a02302004-08-11 04:31:00 +00002270let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002271 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002272 def SHR8mCL : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002273 "shr{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002274 [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002275 def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002276 "shr{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002277 [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
Evan Cheng071a2792007-09-11 19:55:27 +00002278 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002279 def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002280 "shr{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002281 [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
2282 }
Evan Cheng64d80e32007-07-19 01:14:50 +00002283 def SHR8mi : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002284 "shr{b}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002285 [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002286 def SHR16mi : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002287 "shr{w}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002288 [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2289 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002290 def SHR32mi : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002291 "shr{l}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002292 [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002293
2294 // Shift by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002295 def SHR8m1 : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002296 "shr{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002297 [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002298 def SHR16m1 : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002299 "shr{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002300 [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002301 def SHR32m1 : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002302 "shr{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002303 [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
Chris Lattner57a02302004-08-11 04:31:00 +00002304}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002305
Evan Cheng071a2792007-09-11 19:55:27 +00002306let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002307def SAR8rCL : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002308 "sar{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002309 [(set GR8:$dst, (sra GR8:$src, CL))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002310def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002311 "sar{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002312 [(set GR16:$dst, (sra GR16:$src, CL))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002313def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002314 "sar{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002315 [(set GR32:$dst, (sra GR32:$src, CL))]>;
2316}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002317
Evan Cheng64d80e32007-07-19 01:14:50 +00002318def SAR8ri : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002319 "sar{b}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002320 [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002321def SAR16ri : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002322 "sar{w}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002323 [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
Chris Lattner3d36a9f2005-12-05 02:40:25 +00002324 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002325def SAR32ri : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002326 "sar{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002327 [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002328
2329// Shift by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002330def SAR8r1 : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002331 "sar{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002332 [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002333def SAR16r1 : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002334 "sar{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002335 [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002336def SAR32r1 : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002337 "sar{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002338 [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
2339
Chris Lattnerf29ed092004-08-11 05:07:25 +00002340let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002341 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002342 def SAR8mCL : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002343 "sar{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002344 [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002345 def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002346 "sar{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002347 [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002348 def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002349 "sar{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002350 [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
2351 }
Evan Cheng64d80e32007-07-19 01:14:50 +00002352 def SAR8mi : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002353 "sar{b}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002354 [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002355 def SAR16mi : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002356 "sar{w}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002357 [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2358 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002359 def SAR32mi : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002360 "sar{l}\t{$src, $dst|$dst, $src}",
Evan Cheng85dd8892005-12-13 07:24:22 +00002361 [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002362
2363 // Shift by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002364 def SAR8m1 : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002365 "sar{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002366 [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002367 def SAR16m1 : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002368 "sar{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002369 [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2370 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002371 def SAR32m1 : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002372 "sar{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002373 [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
Chris Lattnerf29ed092004-08-11 05:07:25 +00002374}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002375
Chris Lattner40ff6332005-01-19 07:50:03 +00002376// Rotate instructions
Sean Callanana2dc2822009-09-18 19:35:23 +00002377
2378def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src),
2379 "rcl{b}\t{1, $dst|$dst, 1}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002380let Uses = [CL] in {
2381def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src),
2382 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002383}
2384def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src, i8imm:$cnt),
2385 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002386
2387def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src),
2388 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002389let Uses = [CL] in {
2390def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src),
2391 "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002392}
2393def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src, i8imm:$cnt),
2394 "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002395
2396def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src),
2397 "rcl{l}\t{1, $dst|$dst, 1}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002398let Uses = [CL] in {
2399def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src),
2400 "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002401}
2402def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src, i8imm:$cnt),
2403 "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002404
2405def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src),
2406 "rcr{b}\t{1, $dst|$dst, 1}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002407let Uses = [CL] in {
2408def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src),
2409 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002410}
2411def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src, i8imm:$cnt),
2412 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002413
2414def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src),
2415 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002416let Uses = [CL] in {
2417def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src),
2418 "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002419}
2420def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src, i8imm:$cnt),
2421 "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
Sean Callanana2dc2822009-09-18 19:35:23 +00002422
2423def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src),
2424 "rcr{l}\t{1, $dst|$dst, 1}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002425let Uses = [CL] in {
2426def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src),
2427 "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
Sean Callanana2dc2822009-09-18 19:35:23 +00002428}
2429def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src, i8imm:$cnt),
2430 "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
Daniel Dunbarccfa1db2010-02-12 01:22:03 +00002431
2432let isTwoAddress = 0 in {
2433def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
2434 "rcl{b}\t{1, $dst|$dst, 1}", []>;
2435def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2436 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2437def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
2438 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2439def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2440 "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2441def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
2442 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2443def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2444 "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2445def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
2446 "rcr{b}\t{1, $dst|$dst, 1}", []>;
2447def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2448 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2449def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
2450 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2451def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2452 "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2453def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
2454 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2455def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
Sean Callanana2dc2822009-09-18 19:35:23 +00002456 "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2457
Daniel Dunbarccfa1db2010-02-12 01:22:03 +00002458let Uses = [CL] in {
2459def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
2460 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2461def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
2462 "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2463def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
2464 "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2465def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
2466 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2467def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
2468 "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2469def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
2470 "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2471}
2472}
2473
Chris Lattner40ff6332005-01-19 07:50:03 +00002474// FIXME: provide shorter instructions when imm8 == 1
Evan Cheng071a2792007-09-11 19:55:27 +00002475let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002476def ROL8rCL : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002477 "rol{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002478 [(set GR8:$dst, (rotl GR8:$src, CL))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002479def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002480 "rol{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002481 [(set GR16:$dst, (rotl GR16:$src, CL))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002482def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002483 "rol{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002484 [(set GR32:$dst, (rotl GR32:$src, CL))]>;
2485}
Chris Lattner40ff6332005-01-19 07:50:03 +00002486
Evan Cheng64d80e32007-07-19 01:14:50 +00002487def ROL8ri : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002488 "rol{b}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002489 [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002490def ROL16ri : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002491 "rol{w}\t{$src2, $dst|$dst, $src2}",
Sean Callanan108934c2009-12-18 00:01:26 +00002492 [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>,
2493 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002494def ROL32ri : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002495 "rol{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002496 [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
Chris Lattner40ff6332005-01-19 07:50:03 +00002497
Evan Cheng09c54572006-06-29 00:36:51 +00002498// Rotate by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002499def ROL8r1 : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002500 "rol{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002501 [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002502def ROL16r1 : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002503 "rol{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002504 [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002505def ROL32r1 : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002506 "rol{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002507 [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
2508
Chris Lattner40ff6332005-01-19 07:50:03 +00002509let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002510 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002511 def ROL8mCL : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002512 "rol{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002513 [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002514 def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002515 "rol{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002516 [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002517 def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002518 "rol{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002519 [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
2520 }
Evan Cheng64d80e32007-07-19 01:14:50 +00002521 def ROL8mi : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002522 "rol{b}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002523 [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002524 def ROL16mi : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002525 "rol{w}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002526 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2527 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002528 def ROL32mi : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002529 "rol{l}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002530 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002531
2532 // Rotate by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002533 def ROL8m1 : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002534 "rol{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002535 [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002536 def ROL16m1 : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002537 "rol{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002538 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2539 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002540 def ROL32m1 : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002541 "rol{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002542 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
Chris Lattner40ff6332005-01-19 07:50:03 +00002543}
2544
Evan Cheng071a2792007-09-11 19:55:27 +00002545let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002546def ROR8rCL : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002547 "ror{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002548 [(set GR8:$dst, (rotr GR8:$src, CL))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002549def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002550 "ror{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002551 [(set GR16:$dst, (rotr GR16:$src, CL))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002552def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002553 "ror{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002554 [(set GR32:$dst, (rotr GR32:$src, CL))]>;
2555}
Chris Lattner40ff6332005-01-19 07:50:03 +00002556
Evan Cheng64d80e32007-07-19 01:14:50 +00002557def ROR8ri : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002558 "ror{b}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002559 [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002560def ROR16ri : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002561 "ror{w}\t{$src2, $dst|$dst, $src2}",
Sean Callanan108934c2009-12-18 00:01:26 +00002562 [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>,
2563 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002564def ROR32ri : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002565 "ror{l}\t{$src2, $dst|$dst, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002566 [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002567
2568// Rotate by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002569def ROR8r1 : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002570 "ror{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002571 [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002572def ROR16r1 : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002573 "ror{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002574 [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002575def ROR32r1 : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002576 "ror{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002577 [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
2578
Chris Lattner40ff6332005-01-19 07:50:03 +00002579let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002580 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002581 def ROR8mCL : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002582 "ror{b}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002583 [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002584 def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002585 "ror{w}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002586 [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002587 def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002588 "ror{l}\t{%cl, $dst|$dst, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002589 [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
2590 }
Evan Cheng64d80e32007-07-19 01:14:50 +00002591 def ROR8mi : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002592 "ror{b}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002593 [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002594 def ROR16mi : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002595 "ror{w}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002596 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2597 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002598 def ROR32mi : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002599 "ror{l}\t{$src, $dst|$dst, $src}",
Evan Chengeb422a72006-01-11 23:20:05 +00002600 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Cheng09c54572006-06-29 00:36:51 +00002601
2602 // Rotate by 1
Evan Cheng64d80e32007-07-19 01:14:50 +00002603 def ROR8m1 : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002604 "ror{b}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002605 [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002606 def ROR16m1 : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002607 "ror{w}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002608 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2609 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002610 def ROR32m1 : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002611 "ror{l}\t$dst",
Evan Cheng09c54572006-06-29 00:36:51 +00002612 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
Chris Lattner40ff6332005-01-19 07:50:03 +00002613}
2614
2615
2616
2617// Double shift instructions (generalizations of rotate)
Evan Cheng071a2792007-09-11 19:55:27 +00002618let Uses = [CL] in {
Sean Callanan108934c2009-12-18 00:01:26 +00002619def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst),
2620 (ins GR32:$src1, GR32:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002621 "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002622 [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00002623def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
2624 (ins GR32:$src1, GR32:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002625 "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng071a2792007-09-11 19:55:27 +00002626 [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00002627def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst),
2628 (ins GR16:$src1, GR16:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002629 "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002630 [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
Evan Cheng071a2792007-09-11 19:55:27 +00002631 TB, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00002632def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst),
2633 (ins GR16:$src1, GR16:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002634 "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002635 [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
Evan Cheng071a2792007-09-11 19:55:27 +00002636 TB, OpSize;
2637}
Chris Lattner41e431b2005-01-19 07:11:01 +00002638
2639let isCommutable = 1 in { // These instructions commute to each other.
Chris Lattner3a173df2004-10-03 20:35:00 +00002640def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
Sean Callanan108934c2009-12-18 00:01:26 +00002641 (outs GR32:$dst),
2642 (ins GR32:$src1, GR32:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002643 "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002644 [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002645 (i8 imm:$src3)))]>,
2646 TB;
Chris Lattner3a173df2004-10-03 20:35:00 +00002647def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
Sean Callanan108934c2009-12-18 00:01:26 +00002648 (outs GR32:$dst),
2649 (ins GR32:$src1, GR32:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002650 "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002651 [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002652 (i8 imm:$src3)))]>,
2653 TB;
Chris Lattner0df53d22005-01-19 07:31:24 +00002654def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
Sean Callanan108934c2009-12-18 00:01:26 +00002655 (outs GR16:$dst),
2656 (ins GR16:$src1, GR16:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002657 "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002658 [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002659 (i8 imm:$src3)))]>,
Chris Lattner0df53d22005-01-19 07:31:24 +00002660 TB, OpSize;
2661def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
Sean Callanan108934c2009-12-18 00:01:26 +00002662 (outs GR16:$dst),
2663 (ins GR16:$src1, GR16:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002664 "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002665 [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002666 (i8 imm:$src3)))]>,
Chris Lattner0df53d22005-01-19 07:31:24 +00002667 TB, OpSize;
Chris Lattner41e431b2005-01-19 07:11:01 +00002668}
Chris Lattner0e967d42004-08-01 08:13:11 +00002669
Chris Lattner57a02302004-08-11 04:31:00 +00002670let isTwoAddress = 0 in {
Evan Cheng071a2792007-09-11 19:55:27 +00002671 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002672 def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002673 "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002674 [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
Evan Cheng071a2792007-09-11 19:55:27 +00002675 addr:$dst)]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00002676 def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002677 "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002678 [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
Evan Cheng071a2792007-09-11 19:55:27 +00002679 addr:$dst)]>, TB;
2680 }
Chris Lattner3a173df2004-10-03 20:35:00 +00002681 def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002682 (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002683 "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002684 [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002685 (i8 imm:$src3)), addr:$dst)]>,
Chris Lattnerf124d5e2005-11-18 01:04:42 +00002686 TB;
Chris Lattner3a173df2004-10-03 20:35:00 +00002687 def SHRD32mri8 : Ii8<0xAC, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002688 (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002689 "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002690 [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002691 (i8 imm:$src3)), addr:$dst)]>,
Chris Lattnerf124d5e2005-11-18 01:04:42 +00002692 TB;
Chris Lattner0df53d22005-01-19 07:31:24 +00002693
Evan Cheng071a2792007-09-11 19:55:27 +00002694 let Uses = [CL] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002695 def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002696 "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002697 [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
Evan Cheng071a2792007-09-11 19:55:27 +00002698 addr:$dst)]>, TB, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002699 def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
Eli Friedmanaace4b12009-06-19 04:48:38 +00002700 "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
Evan Cheng069287d2006-05-16 07:21:53 +00002701 [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
Evan Cheng071a2792007-09-11 19:55:27 +00002702 addr:$dst)]>, TB, OpSize;
2703 }
Chris Lattner0df53d22005-01-19 07:31:24 +00002704 def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002705 (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002706 "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002707 [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002708 (i8 imm:$src3)), addr:$dst)]>,
Chris Lattner0df53d22005-01-19 07:31:24 +00002709 TB, OpSize;
2710 def SHRD16mri8 : Ii8<0xAC, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002711 (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002712 "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng069287d2006-05-16 07:21:53 +00002713 [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
Evan Chenge3413162006-01-09 18:33:28 +00002714 (i8 imm:$src3)), addr:$dst)]>,
Chris Lattner0df53d22005-01-19 07:31:24 +00002715 TB, OpSize;
Chris Lattner57a02302004-08-11 04:31:00 +00002716}
Evan Cheng24f2ea32007-09-14 21:48:26 +00002717} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002718
2719
Chris Lattnercc65bee2005-01-02 02:35:46 +00002720// Arithmetic.
Evan Cheng24f2ea32007-09-14 21:48:26 +00002721let Defs = [EFLAGS] in {
Chris Lattnercc65bee2005-01-02 02:35:46 +00002722let isCommutable = 1 in { // X = ADD Y, Z --> X = ADD Z, Y
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002723// Register-Register Addition
2724def ADD8rr : I<0x00, MRMDestReg, (outs GR8 :$dst),
2725 (ins GR8 :$src1, GR8 :$src2),
2726 "add{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002727 [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002728
Chris Lattnercc65bee2005-01-02 02:35:46 +00002729let isConvertibleToThreeAddress = 1 in { // Can transform into LEA.
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002730// Register-Register Addition
Evan Cheng071a2792007-09-11 19:55:27 +00002731def ADD16rr : I<0x01, MRMDestReg, (outs GR16:$dst),
2732 (ins GR16:$src1, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002733 "add{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002734 [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2735 GR16:$src2))]>, OpSize;
Evan Cheng071a2792007-09-11 19:55:27 +00002736def ADD32rr : I<0x01, MRMDestReg, (outs GR32:$dst),
2737 (ins GR32:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002738 "add{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002739 [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2740 GR32:$src2))]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00002741} // end isConvertibleToThreeAddress
2742} // end isCommutable
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002743
Daniel Dunbarf291be32010-03-09 22:50:46 +00002744// These are alternate spellings for use by the disassembler, we mark them as
2745// code gen only to ensure they aren't matched by the assembler.
2746let isCodeGenOnly = 1 in {
2747 def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2748 "add{b}\t{$src2, $dst|$dst, $src2}", []>;
2749 def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
2750 "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
Evan Cheng18ac4102010-04-05 22:21:09 +00002751 def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
Daniel Dunbarf291be32010-03-09 22:50:46 +00002752 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
2753}
2754
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002755// Register-Memory Addition
Evan Cheng071a2792007-09-11 19:55:27 +00002756def ADD8rm : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2757 (ins GR8 :$src1, i8mem :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002758 "add{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002759 [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
2760 (load addr:$src2)))]>;
Evan Cheng071a2792007-09-11 19:55:27 +00002761def ADD16rm : I<0x03, MRMSrcMem, (outs GR16:$dst),
2762 (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002763 "add{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002764 [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2765 (load addr:$src2)))]>, OpSize;
Evan Cheng071a2792007-09-11 19:55:27 +00002766def ADD32rm : I<0x03, MRMSrcMem, (outs GR32:$dst),
2767 (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002768 "add{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002769 [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2770 (load addr:$src2)))]>;
Sean Callanan37be5902009-09-15 20:53:57 +00002771
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002772// Register-Integer Addition
2773def ADD8ri : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2774 "add{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002775 [(set GR8:$dst, EFLAGS,
2776 (X86add_flag GR8:$src1, imm:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002777
Chris Lattnercc65bee2005-01-02 02:35:46 +00002778let isConvertibleToThreeAddress = 1 in { // Can transform into LEA.
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002779// Register-Integer Addition
Evan Cheng071a2792007-09-11 19:55:27 +00002780def ADD16ri : Ii16<0x81, MRM0r, (outs GR16:$dst),
2781 (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002782 "add{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002783 [(set GR16:$dst, EFLAGS,
2784 (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
Evan Cheng071a2792007-09-11 19:55:27 +00002785def ADD32ri : Ii32<0x81, MRM0r, (outs GR32:$dst),
2786 (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002787 "add{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002788 [(set GR32:$dst, EFLAGS,
2789 (X86add_flag GR32:$src1, imm:$src2))]>;
Evan Cheng071a2792007-09-11 19:55:27 +00002790def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2791 (ins GR16:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002792 "add{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002793 [(set GR16:$dst, EFLAGS,
2794 (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
Evan Cheng071a2792007-09-11 19:55:27 +00002795def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2796 (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002797 "add{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002798 [(set GR32:$dst, EFLAGS,
2799 (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
Evan Cheng09e3c802006-05-19 18:40:54 +00002800}
Chris Lattner57a02302004-08-11 04:31:00 +00002801
2802let isTwoAddress = 0 in {
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002803 // Memory-Register Addition
Bill Wendlingd350e022008-12-12 21:15:41 +00002804 def ADD8mr : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002805 "add{b}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002806 [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2807 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002808 def ADD16mr : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002809 "add{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002810 [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2811 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002812 def ADD32mr : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002813 "add{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002814 [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2815 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002816 def ADD8mi : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002817 "add{b}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002818 [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2819 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002820 def ADD16mi : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002821 "add{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002822 [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2823 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002824 def ADD32mi : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002825 "add{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002826 [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2827 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002828 def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002829 "add{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00002830 [(store (add (load addr:$dst), i16immSExt8:$src2),
2831 addr:$dst),
2832 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00002833 def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002834 "add{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002835 [(store (add (load addr:$dst), i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00002836 addr:$dst),
2837 (implicit EFLAGS)]>;
Sean Callananb08ae6b2009-08-11 21:26:06 +00002838
2839 // addition to rAX
2840 def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
Sean Callanana09caa52009-09-02 00:55:49 +00002841 "add{b}\t{$src, %al|%al, $src}", []>;
Sean Callananb08ae6b2009-08-11 21:26:06 +00002842 def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
Sean Callanana09caa52009-09-02 00:55:49 +00002843 "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
Sean Callananb08ae6b2009-08-11 21:26:06 +00002844 def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
Sean Callanana09caa52009-09-02 00:55:49 +00002845 "add{l}\t{$src, %eax|%eax, $src}", []>;
Chris Lattner57a02302004-08-11 04:31:00 +00002846}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002847
Evan Cheng3154cb62007-10-05 17:59:57 +00002848let Uses = [EFLAGS] in {
Chris Lattner10197ff2005-01-03 01:27:59 +00002849let isCommutable = 1 in { // X = ADC Y, Z --> X = ADC Z, Y
Dale Johannesen874ae252009-06-02 03:12:52 +00002850def ADC8rr : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002851 "adc{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002852 [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002853def ADC16rr : I<0x11, MRMDestReg, (outs GR16:$dst),
2854 (ins GR16:$src1, GR16:$src2),
2855 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002856 [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002857def ADC32rr : I<0x11, MRMDestReg, (outs GR32:$dst),
2858 (ins GR32:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002859 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002860 [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
Chris Lattner10197ff2005-01-03 01:27:59 +00002861}
Sean Callanan108934c2009-12-18 00:01:26 +00002862
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002863let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00002864def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2865 "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
2866def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst),
2867 (ins GR16:$src1, GR16:$src2),
2868 "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2869def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst),
2870 (ins GR32:$src1, GR32:$src2),
2871 "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002872}
Sean Callanan108934c2009-12-18 00:01:26 +00002873
Dale Johannesenca11dae2009-05-18 17:44:15 +00002874def ADC8rm : I<0x12, MRMSrcMem , (outs GR8:$dst),
2875 (ins GR8:$src1, i8mem:$src2),
2876 "adc{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002877 [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002878def ADC16rm : I<0x13, MRMSrcMem , (outs GR16:$dst),
2879 (ins GR16:$src1, i16mem:$src2),
2880 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002881 [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
Dale Johannesen94c9cd12009-05-18 21:41:59 +00002882 OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002883def ADC32rm : I<0x13, MRMSrcMem , (outs GR32:$dst),
2884 (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002885 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002886 [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2887def ADC8ri : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002888 "adc{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002889 [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002890def ADC16ri : Ii16<0x81, MRM2r, (outs GR16:$dst),
2891 (ins GR16:$src1, i16imm:$src2),
2892 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002893 [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002894def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2895 (ins GR16:$src1, i16i8imm:$src2),
2896 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002897 [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2898 OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002899def ADC32ri : Ii32<0x81, MRM2r, (outs GR32:$dst),
2900 (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002901 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002902 [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00002903def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2904 (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002905 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002906 [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
Chris Lattner57a02302004-08-11 04:31:00 +00002907
2908let isTwoAddress = 0 in {
Dale Johannesen874ae252009-06-02 03:12:52 +00002909 def ADC8mr : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002910 "adc{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002911 [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2912 def ADC16mr : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002913 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002914 [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2915 OpSize;
2916 def ADC32mr : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002917 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002918 [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2919 def ADC8mi : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002920 "adc{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002921 [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2922 def ADC16mi : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002923 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002924 [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2925 OpSize;
2926 def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
Dale Johannesenca11dae2009-05-18 17:44:15 +00002927 "adc{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002928 [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2929 OpSize;
2930 def ADC32mi : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002931 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002932 [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2933 def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002934 "adc{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00002935 [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
Sean Callanand00025a2009-09-11 19:01:56 +00002936
2937 def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
2938 "adc{b}\t{$src, %al|%al, $src}", []>;
2939 def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
2940 "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2941 def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
2942 "adc{l}\t{$src, %eax|%eax, $src}", []>;
Dale Johannesen874ae252009-06-02 03:12:52 +00002943}
Evan Cheng3154cb62007-10-05 17:59:57 +00002944} // Uses = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00002945
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002946// Register-Register Subtraction
2947def SUB8rr : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2948 "sub{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002949 [(set GR8:$dst, EFLAGS,
2950 (X86sub_flag GR8:$src1, GR8:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002951def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2952 "sub{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002953 [(set GR16:$dst, EFLAGS,
2954 (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002955def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2956 "sub{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002957 [(set GR32:$dst, EFLAGS,
2958 (X86sub_flag GR32:$src1, GR32:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002959
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002960let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00002961def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2962 "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
2963def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst),
2964 (ins GR16:$src1, GR16:$src2),
2965 "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2966def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst),
2967 (ins GR32:$src1, GR32:$src2),
2968 "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00002969}
Sean Callanan108934c2009-12-18 00:01:26 +00002970
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002971// Register-Memory Subtraction
2972def SUB8rm : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
2973 (ins GR8 :$src1, i8mem :$src2),
2974 "sub{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002975 [(set GR8:$dst, EFLAGS,
2976 (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002977def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
2978 (ins GR16:$src1, i16mem:$src2),
2979 "sub{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002980 [(set GR16:$dst, EFLAGS,
2981 (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002982def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
2983 (ins GR32:$src1, i32mem:$src2),
2984 "sub{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002985 [(set GR32:$dst, EFLAGS,
2986 (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002987
2988// Register-Integer Subtraction
2989def SUB8ri : Ii8 <0x80, MRM5r, (outs GR8:$dst),
2990 (ins GR8:$src1, i8imm:$src2),
2991 "sub{b}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002992 [(set GR8:$dst, EFLAGS,
2993 (X86sub_flag GR8:$src1, imm:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002994def SUB16ri : Ii16<0x81, MRM5r, (outs GR16:$dst),
2995 (ins GR16:$src1, i16imm:$src2),
2996 "sub{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00002997 [(set GR16:$dst, EFLAGS,
2998 (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00002999def SUB32ri : Ii32<0x81, MRM5r, (outs GR32:$dst),
3000 (ins GR32:$src1, i32imm:$src2),
3001 "sub{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003002 [(set GR32:$dst, EFLAGS,
3003 (X86sub_flag GR32:$src1, imm:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003004def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
3005 (ins GR16:$src1, i16i8imm:$src2),
3006 "sub{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003007 [(set GR16:$dst, EFLAGS,
3008 (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003009def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
3010 (ins GR32:$src1, i32i8imm:$src2),
3011 "sub{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003012 [(set GR32:$dst, EFLAGS,
3013 (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003014
Chris Lattner57a02302004-08-11 04:31:00 +00003015let isTwoAddress = 0 in {
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003016 // Memory-Register Subtraction
Evan Cheng64d80e32007-07-19 01:14:50 +00003017 def SUB8mr : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003018 "sub{b}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003019 [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
3020 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00003021 def SUB16mr : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003022 "sub{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003023 [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
3024 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003025 def SUB32mr : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003026 "sub{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003027 [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
3028 (implicit EFLAGS)]>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003029
3030 // Memory-Integer Subtraction
Evan Cheng64d80e32007-07-19 01:14:50 +00003031 def SUB8mi : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003032 "sub{b}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003033 [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
3034 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00003035 def SUB16mi : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003036 "sub{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003037 [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
3038 (implicit EFLAGS)]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003039 def SUB32mi : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003040 "sub{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingd350e022008-12-12 21:15:41 +00003041 [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
3042 (implicit EFLAGS)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00003043 def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003044 "sub{w}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003045 [(store (sub (load addr:$dst), i16immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00003046 addr:$dst),
3047 (implicit EFLAGS)]>, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003048 def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003049 "sub{l}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003050 [(store (sub (load addr:$dst), i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00003051 addr:$dst),
3052 (implicit EFLAGS)]>;
Sean Callanand00025a2009-09-11 19:01:56 +00003053
3054 def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
3055 "sub{b}\t{$src, %al|%al, $src}", []>;
3056 def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
3057 "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3058 def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
3059 "sub{l}\t{$src, %eax|%eax, $src}", []>;
Chris Lattner57a02302004-08-11 04:31:00 +00003060}
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003061
Evan Cheng3154cb62007-10-05 17:59:57 +00003062let Uses = [EFLAGS] in {
Dale Johannesenca11dae2009-05-18 17:44:15 +00003063def SBB8rr : I<0x18, MRMDestReg, (outs GR8:$dst),
3064 (ins GR8:$src1, GR8:$src2),
3065 "sbb{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003066 [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003067def SBB16rr : I<0x19, MRMDestReg, (outs GR16:$dst),
3068 (ins GR16:$src1, GR16:$src2),
3069 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003070 [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003071def SBB32rr : I<0x19, MRMDestReg, (outs GR32:$dst),
3072 (ins GR32:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003073 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003074 [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
Chris Lattnerd93d3b02004-10-06 04:01:02 +00003075
Chris Lattner57a02302004-08-11 04:31:00 +00003076let isTwoAddress = 0 in {
Dale Johannesenca11dae2009-05-18 17:44:15 +00003077 def SBB8mr : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
3078 "sbb{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003079 [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003080 def SBB16mr : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3081 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003082 [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
Dale Johannesen94c9cd12009-05-18 21:41:59 +00003083 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003084 def SBB32mr : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003085 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003086 [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
Chris Lattner8f60e4d2010-02-05 22:56:11 +00003087 def SBB8mi : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2),
3088 "sbb{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003089 [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003090 def SBB16mi : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2),
3091 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003092 [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
Dale Johannesen94c9cd12009-05-18 21:41:59 +00003093 OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003094 def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
3095 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003096 [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
Dale Johannesen94c9cd12009-05-18 21:41:59 +00003097 OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003098 def SBB32mi : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003099 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003100 [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00003101 def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003102 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003103 [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
Sean Callanand00025a2009-09-11 19:01:56 +00003104
3105 def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
3106 "sbb{b}\t{$src, %al|%al, $src}", []>;
3107 def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
3108 "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3109 def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
3110 "sbb{l}\t{$src, %eax|%eax, $src}", []>;
Chris Lattner57a02302004-08-11 04:31:00 +00003111}
Sean Callanan108934c2009-12-18 00:01:26 +00003112
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00003113let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00003114def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
3115 "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
3116def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst),
3117 (ins GR16:$src1, GR16:$src2),
3118 "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
3119def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst),
3120 (ins GR32:$src1, GR32:$src2),
3121 "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00003122}
Sean Callanan108934c2009-12-18 00:01:26 +00003123
Dale Johannesenca11dae2009-05-18 17:44:15 +00003124def SBB8rm : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
3125 "sbb{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003126 [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003127def SBB16rm : I<0x1B, MRMSrcMem, (outs GR16:$dst),
3128 (ins GR16:$src1, i16mem:$src2),
3129 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003130 [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
Dale Johannesen94c9cd12009-05-18 21:41:59 +00003131 OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003132def SBB32rm : I<0x1B, MRMSrcMem, (outs GR32:$dst),
3133 (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003134 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003135 [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003136def SBB8ri : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
3137 "sbb{b}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003138 [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003139def SBB16ri : Ii16<0x81, MRM3r, (outs GR16:$dst),
3140 (ins GR16:$src1, i16imm:$src2),
3141 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003142 [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003143def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
3144 (ins GR16:$src1, i16i8imm:$src2),
3145 "sbb{w}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003146 [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
3147 OpSize;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003148def SBB32ri : Ii32<0x81, MRM3r, (outs GR32:$dst),
3149 (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003150 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003151 [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
Dale Johannesenca11dae2009-05-18 17:44:15 +00003152def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
3153 (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003154 "sbb{l}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen874ae252009-06-02 03:12:52 +00003155 [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
Evan Cheng3154cb62007-10-05 17:59:57 +00003156} // Uses = [EFLAGS]
Evan Cheng24f2ea32007-09-14 21:48:26 +00003157} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003158
Evan Cheng24f2ea32007-09-14 21:48:26 +00003159let Defs = [EFLAGS] in {
Chris Lattner10197ff2005-01-03 01:27:59 +00003160let isCommutable = 1 in { // X = IMUL Y, Z --> X = IMUL Z, Y
Bill Wendlingd350e022008-12-12 21:15:41 +00003161// Register-Register Signed Integer Multiply
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003162def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003163 "imul{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003164 [(set GR16:$dst, EFLAGS,
3165 (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003166def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003167 "imul{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003168 [(set GR32:$dst, EFLAGS,
3169 (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
Chris Lattner10197ff2005-01-03 01:27:59 +00003170}
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003171
Bill Wendlingd350e022008-12-12 21:15:41 +00003172// Register-Memory Signed Integer Multiply
Bill Wendlingab55ebd2008-12-12 00:56:36 +00003173def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
3174 (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003175 "imul{w}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003176 [(set GR16:$dst, EFLAGS,
3177 (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
3178 TB, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00003179def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst),
3180 (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003181 "imul{l}\t{$src2, $dst|$dst, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003182 [(set GR32:$dst, EFLAGS,
3183 (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
Evan Cheng24f2ea32007-09-14 21:48:26 +00003184} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003185} // end Two Address instructions
3186
Chris Lattnerf5d3a832004-08-11 05:31:07 +00003187// Suprisingly enough, these are not two address instructions!
Evan Cheng24f2ea32007-09-14 21:48:26 +00003188let Defs = [EFLAGS] in {
Bill Wendlingd350e022008-12-12 21:15:41 +00003189// Register-Integer Signed Integer Multiply
Evan Cheng069287d2006-05-16 07:21:53 +00003190def IMUL16rri : Ii16<0x69, MRMSrcReg, // GR16 = GR16*I16
Evan Cheng64d80e32007-07-19 01:14:50 +00003191 (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003192 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003193 [(set GR16:$dst, EFLAGS,
3194 (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00003195def IMUL32rri : Ii32<0x69, MRMSrcReg, // GR32 = GR32*I32
Evan Cheng64d80e32007-07-19 01:14:50 +00003196 (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003197 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003198 [(set GR32:$dst, EFLAGS,
3199 (X86smul_flag GR32:$src1, imm:$src2))]>;
Evan Cheng069287d2006-05-16 07:21:53 +00003200def IMUL16rri8 : Ii8<0x6B, MRMSrcReg, // GR16 = GR16*I8
Evan Cheng64d80e32007-07-19 01:14:50 +00003201 (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003202 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003203 [(set GR16:$dst, EFLAGS,
3204 (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
3205 OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00003206def IMUL32rri8 : Ii8<0x6B, MRMSrcReg, // GR32 = GR32*I8
Evan Cheng64d80e32007-07-19 01:14:50 +00003207 (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003208 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003209 [(set GR32:$dst, EFLAGS,
3210 (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
Chris Lattnerf5d3a832004-08-11 05:31:07 +00003211
Bill Wendlingd350e022008-12-12 21:15:41 +00003212// Memory-Integer Signed Integer Multiply
Sean Callanan108934c2009-12-18 00:01:26 +00003213def IMUL16rmi : Ii16<0x69, MRMSrcMem, // GR16 = [mem16]*I16
Evan Cheng64d80e32007-07-19 01:14:50 +00003214 (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003215 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003216 [(set GR16:$dst, EFLAGS,
3217 (X86smul_flag (load addr:$src1), imm:$src2))]>,
3218 OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00003219def IMUL32rmi : Ii32<0x69, MRMSrcMem, // GR32 = [mem32]*I32
Evan Cheng64d80e32007-07-19 01:14:50 +00003220 (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003221 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003222 [(set GR32:$dst, EFLAGS,
3223 (X86smul_flag (load addr:$src1), imm:$src2))]>;
Evan Cheng069287d2006-05-16 07:21:53 +00003224def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem, // GR16 = [mem16]*I8
Evan Cheng64d80e32007-07-19 01:14:50 +00003225 (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003226 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003227 [(set GR16:$dst, EFLAGS,
3228 (X86smul_flag (load addr:$src1),
3229 i16immSExt8:$src2))]>, OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00003230def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem, // GR32 = [mem32]*I8
Evan Cheng64d80e32007-07-19 01:14:50 +00003231 (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003232 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Chris Lattnerec856802010-03-27 00:45:04 +00003233 [(set GR32:$dst, EFLAGS,
3234 (X86smul_flag (load addr:$src1),
3235 i32immSExt8:$src2))]>;
Evan Cheng24f2ea32007-09-14 21:48:26 +00003236} // Defs = [EFLAGS]
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003237
3238//===----------------------------------------------------------------------===//
3239// Test instructions are just like AND, except they don't generate a result.
Chris Lattner3a173df2004-10-03 20:35:00 +00003240//
Evan Cheng0488db92007-09-25 01:57:46 +00003241let Defs = [EFLAGS] in {
Chris Lattnercc65bee2005-01-02 02:35:46 +00003242let isCommutable = 1 in { // TEST X, Y --> TEST Y, X
Daniel Dunbarb93c72c2010-03-08 21:10:36 +00003243def TEST8rr : I<0x84, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003244 "test{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003245 [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
Daniel Dunbarb93c72c2010-03-08 21:10:36 +00003246def TEST16rr : I<0x85, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003247 "test{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003248 [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
3249 0))]>,
Evan Chenge5f62042007-09-29 00:00:36 +00003250 OpSize;
Daniel Dunbarb93c72c2010-03-08 21:10:36 +00003251def TEST32rr : I<0x85, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003252 "test{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003253 [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
3254 0))]>;
Chris Lattnercc65bee2005-01-02 02:35:46 +00003255}
Evan Cheng734503b2006-09-11 02:19:56 +00003256
Sean Callanan4a93b712009-09-01 18:14:18 +00003257def TEST8i8 : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
3258 "test{b}\t{$src, %al|%al, $src}", []>;
3259def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
3260 "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3261def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
3262 "test{l}\t{$src, %eax|%eax, $src}", []>;
3263
Evan Cheng64d80e32007-07-19 01:14:50 +00003264def TEST8rm : I<0x84, MRMSrcMem, (outs), (ins GR8 :$src1, i8mem :$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003265 "test{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003266 [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
3267 0))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00003268def TEST16rm : I<0x85, MRMSrcMem, (outs), (ins GR16:$src1, i16mem:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003269 "test{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003270 [(set EFLAGS, (X86cmp (and GR16:$src1,
3271 (loadi16 addr:$src2)), 0))]>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003272def TEST32rm : I<0x85, MRMSrcMem, (outs), (ins GR32:$src1, i32mem:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +00003273 "test{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003274 [(set EFLAGS, (X86cmp (and GR32:$src1,
3275 (loadi32 addr:$src2)), 0))]>;
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003276
Evan Cheng069287d2006-05-16 07:21:53 +00003277def TEST8ri : Ii8 <0xF6, MRM0r, // flags = GR8 & imm8
Evan Cheng64d80e32007-07-19 01:14:50 +00003278 (outs), (ins GR8:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003279 "test{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003280 [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
Evan Cheng069287d2006-05-16 07:21:53 +00003281def TEST16ri : Ii16<0xF7, MRM0r, // flags = GR16 & imm16
Evan Cheng64d80e32007-07-19 01:14:50 +00003282 (outs), (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003283 "test{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003284 [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
3285 OpSize;
Evan Cheng069287d2006-05-16 07:21:53 +00003286def TEST32ri : Ii32<0xF7, MRM0r, // flags = GR32 & imm32
Evan Cheng64d80e32007-07-19 01:14:50 +00003287 (outs), (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003288 "test{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003289 [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
Evan Cheng734503b2006-09-11 02:19:56 +00003290
Evan Chenge5f62042007-09-29 00:00:36 +00003291def TEST8mi : Ii8 <0xF6, MRM0m, // flags = [mem8] & imm8
Evan Cheng64d80e32007-07-19 01:14:50 +00003292 (outs), (ins i8mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003293 "test{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003294 [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
3295 0))]>;
Evan Chenge5f62042007-09-29 00:00:36 +00003296def TEST16mi : Ii16<0xF7, MRM0m, // flags = [mem16] & imm16
Evan Cheng64d80e32007-07-19 01:14:50 +00003297 (outs), (ins i16mem:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003298 "test{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003299 [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
3300 0))]>, OpSize;
Evan Chenge5f62042007-09-29 00:00:36 +00003301def TEST32mi : Ii32<0xF7, MRM0m, // flags = [mem32] & imm32
Evan Cheng64d80e32007-07-19 01:14:50 +00003302 (outs), (ins i32mem:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003303 "test{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003304 [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
3305 0))]>;
Evan Cheng0488db92007-09-25 01:57:46 +00003306} // Defs = [EFLAGS]
3307
3308
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003309// Condition code ops, incl. set if equal/not equal/...
Chris Lattnerba7e7562008-01-10 07:59:24 +00003310let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
Evan Cheng071a2792007-09-11 19:55:27 +00003311def SAHF : I<0x9E, RawFrm, (outs), (ins), "sahf", []>; // flags = AH
Chris Lattnerba7e7562008-01-10 07:59:24 +00003312let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
Evan Cheng071a2792007-09-11 19:55:27 +00003313def LAHF : I<0x9F, RawFrm, (outs), (ins), "lahf", []>; // AH = flags
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00003314
Evan Cheng0488db92007-09-25 01:57:46 +00003315let Uses = [EFLAGS] in {
Evan Chengad9c0a32009-12-15 00:53:42 +00003316// Use sbb to materialize carry bit.
Evan Chengad9c0a32009-12-15 00:53:42 +00003317let Defs = [EFLAGS], isCodeGenOnly = 1 in {
Chris Lattnerc74e3332010-02-05 21:13:48 +00003318// FIXME: These are pseudo ops that should be replaced with Pat<> patterns.
3319// However, Pat<> can't replicate the destination reg into the inputs of the
3320// result.
3321// FIXME: Change these to have encoding Pseudo when X86MCCodeEmitter replaces
3322// X86CodeEmitter.
3323def SETB_C8r : I<0x18, MRMInitReg, (outs GR8:$dst), (ins), "",
Evan Chengad9c0a32009-12-15 00:53:42 +00003324 [(set GR8:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
Chris Lattnerc74e3332010-02-05 21:13:48 +00003325def SETB_C16r : I<0x19, MRMInitReg, (outs GR16:$dst), (ins), "",
Evan Cheng2e489c42009-12-16 00:53:11 +00003326 [(set GR16:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>,
Evan Chengad9c0a32009-12-15 00:53:42 +00003327 OpSize;
Chris Lattnerc74e3332010-02-05 21:13:48 +00003328def SETB_C32r : I<0x19, MRMInitReg, (outs GR32:$dst), (ins), "",
Evan Cheng2e489c42009-12-16 00:53:11 +00003329 [(set GR32:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
Evan Chengad9c0a32009-12-15 00:53:42 +00003330} // isCodeGenOnly
3331
Chris Lattner3a173df2004-10-03 20:35:00 +00003332def SETEr : I<0x94, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003333 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003334 "sete\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003335 [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003336 TB; // GR8 = ==
Chris Lattner3a173df2004-10-03 20:35:00 +00003337def SETEm : I<0x94, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003338 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003339 "sete\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003340 [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003341 TB; // [mem8] = ==
Bill Wendling9f248742008-12-02 00:07:05 +00003342
Chris Lattner3a173df2004-10-03 20:35:00 +00003343def SETNEr : I<0x95, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003344 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003345 "setne\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003346 [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003347 TB; // GR8 = !=
Chris Lattner3a173df2004-10-03 20:35:00 +00003348def SETNEm : I<0x95, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003349 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003350 "setne\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003351 [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003352 TB; // [mem8] = !=
Bill Wendling9f248742008-12-02 00:07:05 +00003353
Evan Chengd5781fc2005-12-21 20:21:51 +00003354def SETLr : I<0x9C, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003355 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003356 "setl\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003357 [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003358 TB; // GR8 = < signed
Evan Chengd5781fc2005-12-21 20:21:51 +00003359def SETLm : I<0x9C, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003360 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003361 "setl\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003362 [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003363 TB; // [mem8] = < signed
Bill Wendling9f248742008-12-02 00:07:05 +00003364
Evan Chengd5781fc2005-12-21 20:21:51 +00003365def SETGEr : I<0x9D, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003366 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003367 "setge\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003368 [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003369 TB; // GR8 = >= signed
Evan Chengd5781fc2005-12-21 20:21:51 +00003370def SETGEm : I<0x9D, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003371 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003372 "setge\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003373 [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003374 TB; // [mem8] = >= signed
Bill Wendling9f248742008-12-02 00:07:05 +00003375
Evan Chengd5781fc2005-12-21 20:21:51 +00003376def SETLEr : I<0x9E, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003377 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003378 "setle\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003379 [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003380 TB; // GR8 = <= signed
Evan Chengd5781fc2005-12-21 20:21:51 +00003381def SETLEm : I<0x9E, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003382 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003383 "setle\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003384 [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003385 TB; // [mem8] = <= signed
Bill Wendling9f248742008-12-02 00:07:05 +00003386
Evan Chengd5781fc2005-12-21 20:21:51 +00003387def SETGr : I<0x9F, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003388 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003389 "setg\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003390 [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003391 TB; // GR8 = > signed
Evan Chengd5781fc2005-12-21 20:21:51 +00003392def SETGm : I<0x9F, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003393 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003394 "setg\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003395 [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003396 TB; // [mem8] = > signed
3397
3398def SETBr : I<0x92, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003399 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003400 "setb\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003401 [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003402 TB; // GR8 = < unsign
Evan Chengd5781fc2005-12-21 20:21:51 +00003403def SETBm : I<0x92, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003404 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003405 "setb\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003406 [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003407 TB; // [mem8] = < unsign
Bill Wendling9f248742008-12-02 00:07:05 +00003408
Evan Chengd5781fc2005-12-21 20:21:51 +00003409def SETAEr : I<0x93, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003410 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003411 "setae\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003412 [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003413 TB; // GR8 = >= unsign
Evan Chengd5781fc2005-12-21 20:21:51 +00003414def SETAEm : I<0x93, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003415 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003416 "setae\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003417 [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003418 TB; // [mem8] = >= unsign
Bill Wendling9f248742008-12-02 00:07:05 +00003419
Chris Lattner3a173df2004-10-03 20:35:00 +00003420def SETBEr : I<0x96, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003421 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003422 "setbe\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003423 [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003424 TB; // GR8 = <= unsign
Chris Lattner3a173df2004-10-03 20:35:00 +00003425def SETBEm : I<0x96, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003426 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003427 "setbe\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003428 [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003429 TB; // [mem8] = <= unsign
Bill Wendling9f248742008-12-02 00:07:05 +00003430
Chris Lattner3a173df2004-10-03 20:35:00 +00003431def SETAr : I<0x97, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003432 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003433 "seta\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003434 [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003435 TB; // GR8 = > signed
Chris Lattner3a173df2004-10-03 20:35:00 +00003436def SETAm : I<0x97, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003437 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003438 "seta\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003439 [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
Evan Chengd5781fc2005-12-21 20:21:51 +00003440 TB; // [mem8] = > signed
Evan Chengd9558e02006-01-06 00:43:03 +00003441
Chris Lattner3a173df2004-10-03 20:35:00 +00003442def SETSr : I<0x98, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003443 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003444 "sets\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003445 [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003446 TB; // GR8 = <sign bit>
Chris Lattner3a173df2004-10-03 20:35:00 +00003447def SETSm : I<0x98, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003448 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003449 "sets\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003450 [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
Evan Chengd9558e02006-01-06 00:43:03 +00003451 TB; // [mem8] = <sign bit>
Chris Lattner3a173df2004-10-03 20:35:00 +00003452def SETNSr : I<0x99, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003453 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003454 "setns\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003455 [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003456 TB; // GR8 = !<sign bit>
Chris Lattner3a173df2004-10-03 20:35:00 +00003457def SETNSm : I<0x99, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003458 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003459 "setns\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003460 [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
Evan Chengd9558e02006-01-06 00:43:03 +00003461 TB; // [mem8] = !<sign bit>
Bill Wendling9f248742008-12-02 00:07:05 +00003462
Chris Lattner3a173df2004-10-03 20:35:00 +00003463def SETPr : I<0x9A, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003464 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003465 "setp\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003466 [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003467 TB; // GR8 = parity
Chris Lattner3a173df2004-10-03 20:35:00 +00003468def SETPm : I<0x9A, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003469 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003470 "setp\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003471 [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
Evan Chengd9558e02006-01-06 00:43:03 +00003472 TB; // [mem8] = parity
Chris Lattnercc65bee2005-01-02 02:35:46 +00003473def SETNPr : I<0x9B, MRM0r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003474 (outs GR8 :$dst), (ins),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003475 "setnp\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003476 [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
Evan Cheng069287d2006-05-16 07:21:53 +00003477 TB; // GR8 = not parity
Chris Lattnercc65bee2005-01-02 02:35:46 +00003478def SETNPm : I<0x9B, MRM0m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003479 (outs), (ins i8mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003480 "setnp\t$dst",
Evan Chenge5f62042007-09-29 00:00:36 +00003481 [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
Evan Chengd9558e02006-01-06 00:43:03 +00003482 TB; // [mem8] = not parity
Bill Wendling9f248742008-12-02 00:07:05 +00003483
3484def SETOr : I<0x90, MRM0r,
3485 (outs GR8 :$dst), (ins),
3486 "seto\t$dst",
3487 [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
3488 TB; // GR8 = overflow
3489def SETOm : I<0x90, MRM0m,
3490 (outs), (ins i8mem:$dst),
3491 "seto\t$dst",
3492 [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
3493 TB; // [mem8] = overflow
3494def SETNOr : I<0x91, MRM0r,
3495 (outs GR8 :$dst), (ins),
3496 "setno\t$dst",
3497 [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
3498 TB; // GR8 = not overflow
3499def SETNOm : I<0x91, MRM0m,
3500 (outs), (ins i8mem:$dst),
3501 "setno\t$dst",
3502 [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
3503 TB; // [mem8] = not overflow
Evan Cheng0488db92007-09-25 01:57:46 +00003504} // Uses = [EFLAGS]
3505
Chris Lattner1cca5e32003-08-03 21:54:21 +00003506
3507// Integer comparisons
Evan Cheng24f2ea32007-09-14 21:48:26 +00003508let Defs = [EFLAGS] in {
Sean Callanana09caa52009-09-02 00:55:49 +00003509def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
3510 "cmp{b}\t{$src, %al|%al, $src}", []>;
3511def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
3512 "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3513def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
3514 "cmp{l}\t{$src, %eax|%eax, $src}", []>;
3515
Chris Lattner3a173df2004-10-03 20:35:00 +00003516def CMP8rr : I<0x38, MRMDestReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00003517 (outs), (ins GR8 :$src1, GR8 :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003518 "cmp{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003519 [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003520def CMP16rr : I<0x39, MRMDestReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00003521 (outs), (ins GR16:$src1, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003522 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003523 [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00003524def CMP32rr : I<0x39, MRMDestReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00003525 (outs), (ins GR32:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003526 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003527 [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003528def CMP8mr : I<0x38, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003529 (outs), (ins i8mem :$src1, GR8 :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003530 "cmp{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003531 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003532def CMP16mr : I<0x39, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003533 (outs), (ins i16mem:$src1, GR16:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003534 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003535 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
3536 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00003537def CMP32mr : I<0x39, MRMDestMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003538 (outs), (ins i32mem:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003539 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003540 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003541def CMP8rm : I<0x3A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003542 (outs), (ins GR8 :$src1, i8mem :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003543 "cmp{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003544 [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003545def CMP16rm : I<0x3B, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003546 (outs), (ins GR16:$src1, i16mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003547 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003548 [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
3549 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00003550def CMP32rm : I<0x3B, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00003551 (outs), (ins GR32:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003552 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003553 [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
Daniel Dunbar1e8ee892010-03-09 22:50:40 +00003554
3555// These are alternate spellings for use by the disassembler, we mark them as
3556// code gen only to ensure they aren't matched by the assembler.
3557let isCodeGenOnly = 1 in {
3558 def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
3559 "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
3560 def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
3561 "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
3562 def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
3563 "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
3564}
3565
Chris Lattner3a173df2004-10-03 20:35:00 +00003566def CMP8ri : Ii8<0x80, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003567 (outs), (ins GR8:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003568 "cmp{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003569 [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003570def CMP16ri : Ii16<0x81, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003571 (outs), (ins GR16:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003572 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003573 [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00003574def CMP32ri : Ii32<0x81, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003575 (outs), (ins GR32:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003576 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003577 [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003578def CMP8mi : Ii8 <0x80, MRM7m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003579 (outs), (ins i8mem :$src1, i8imm :$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003580 "cmp{b}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003581 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
Chris Lattner3a173df2004-10-03 20:35:00 +00003582def CMP16mi : Ii16<0x81, MRM7m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003583 (outs), (ins i16mem:$src1, i16imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003584 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003585 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
3586 OpSize;
Chris Lattner3a173df2004-10-03 20:35:00 +00003587def CMP32mi : Ii32<0x81, MRM7m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003588 (outs), (ins i32mem:$src1, i32imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003589 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003590 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
Chris Lattner29b4dd02006-03-23 16:13:50 +00003591def CMP16ri8 : Ii8<0x83, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003592 (outs), (ins GR16:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003593 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003594 [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
3595 OpSize;
Chris Lattner29b4dd02006-03-23 16:13:50 +00003596def CMP16mi8 : Ii8<0x83, MRM7m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003597 (outs), (ins i16mem:$src1, i16i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003598 "cmp{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003599 [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
3600 i16immSExt8:$src2))]>, OpSize;
Chris Lattner29b4dd02006-03-23 16:13:50 +00003601def CMP32mi8 : Ii8<0x83, MRM7m,
Evan Cheng64d80e32007-07-19 01:14:50 +00003602 (outs), (ins i32mem:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003603 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003604 [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
3605 i32immSExt8:$src2))]>;
Chris Lattner29b4dd02006-03-23 16:13:50 +00003606def CMP32ri8 : Ii8<0x83, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00003607 (outs), (ins GR32:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003608 "cmp{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003609 [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
Evan Cheng0488db92007-09-25 01:57:46 +00003610} // Defs = [EFLAGS]
3611
Dan Gohmanc7a37d42008-12-23 22:45:23 +00003612// Bit tests.
Dan Gohmanc7a37d42008-12-23 22:45:23 +00003613// TODO: BTC, BTR, and BTS
3614let Defs = [EFLAGS] in {
Dan Gohman0c89b7e2009-01-13 20:32:45 +00003615def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
Dan Gohmanc7a37d42008-12-23 22:45:23 +00003616 "bt{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003617 [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
Dan Gohman0c89b7e2009-01-13 20:32:45 +00003618def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
Dan Gohmanc7a37d42008-12-23 22:45:23 +00003619 "bt{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003620 [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
Dan Gohmanf31408d2009-01-13 23:23:30 +00003621
3622// Unlike with the register+register form, the memory+register form of the
3623// bt instruction does not ignore the high bits of the index. From ISel's
Sean Callanan108934c2009-12-18 00:01:26 +00003624// perspective, this is pretty bizarre. Make these instructions disassembly
3625// only for now.
3626
3627def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3628 "bt{w}\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf31408d2009-01-13 23:23:30 +00003629// [(X86bt (loadi16 addr:$src1), GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00003630// (implicit EFLAGS)]
3631 []
3632 >, OpSize, TB, Requires<[FastBTMem]>;
3633def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3634 "bt{l}\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf31408d2009-01-13 23:23:30 +00003635// [(X86bt (loadi32 addr:$src1), GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00003636// (implicit EFLAGS)]
3637 []
3638 >, TB, Requires<[FastBTMem]>;
Dan Gohman4afe15b2009-01-13 20:33:23 +00003639
3640def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3641 "bt{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003642 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
3643 OpSize, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00003644def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3645 "bt{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003646 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00003647// Note that these instructions don't need FastBTMem because that
3648// only applies when the other operand is in a register. When it's
3649// an immediate, bt is still fast.
3650def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3651 "bt{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003652 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
3653 ]>, OpSize, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00003654def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3655 "bt{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00003656 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
3657 ]>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00003658
3659def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3660 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3661def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3662 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3663def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3664 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3665def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3666 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3667def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3668 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3669def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3670 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3671def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3672 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3673def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3674 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3675
3676def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3677 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3678def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3679 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3680def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3681 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3682def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3683 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3684def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3685 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3686def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3687 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3688def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3689 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3690def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3691 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3692
3693def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3694 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3695def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3696 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3697def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3698 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3699def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3700 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3701def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3702 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3703def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3704 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3705def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3706 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3707def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3708 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
Dan Gohmanc7a37d42008-12-23 22:45:23 +00003709} // Defs = [EFLAGS]
3710
Chris Lattner1cca5e32003-08-03 21:54:21 +00003711// Sign/Zero extenders
Dan Gohman11ba3b12008-07-30 18:09:17 +00003712// Use movsbl intead of movsbw; we don't care about the high 16 bits
3713// of the register here. This has a smaller encoding and avoids a
Sean Callanan108934c2009-12-18 00:01:26 +00003714// partial-register update. Actual movsbw included for the disassembler.
3715def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3716 "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3717def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3718 "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003719def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
Chris Lattner172862a2009-10-19 19:51:42 +00003720 "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003721def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
Chris Lattner172862a2009-10-19 19:51:42 +00003722 "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003723def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003724 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003725 [(set GR32:$dst, (sext GR8:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003726def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003727 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003728 [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003729def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003730 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003731 [(set GR32:$dst, (sext GR16:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003732def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003733 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003734 [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
Alkis Evlogimenosa7be9822004-02-17 09:14:23 +00003735
Dan Gohman11ba3b12008-07-30 18:09:17 +00003736// Use movzbl intead of movzbw; we don't care about the high 16 bits
3737// of the register here. This has a smaller encoding and avoids a
Sean Callanan108934c2009-12-18 00:01:26 +00003738// partial-register update. Actual movzbw included for the disassembler.
3739def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3740 "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3741def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3742 "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00003743def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
Chris Lattner172862a2009-10-19 19:51:42 +00003744 "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003745def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
Chris Lattner172862a2009-10-19 19:51:42 +00003746 "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003747def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003748 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003749 [(set GR32:$dst, (zext GR8:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003750def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003751 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003752 [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003753def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003754 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003755 [(set GR32:$dst, (zext GR16:$src))]>, TB;
Evan Cheng64d80e32007-07-19 01:14:50 +00003756def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003757 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00003758 [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
Evan Cheng7a7e8372005-12-14 02:22:27 +00003759
Dan Gohmanf451cb82010-02-10 16:03:48 +00003760// These are the same as the regular MOVZX32rr8 and MOVZX32rm8
Dan Gohman21e3dfb2009-04-13 16:09:41 +00003761// except that they use GR32_NOREX for the output operand register class
3762// instead of GR32. This allows them to operate on h registers on x86-64.
3763def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
3764 (outs GR32_NOREX:$dst), (ins GR8:$src),
3765 "movz{bl|x}\t{$src, $dst|$dst, $src} # NOREX",
3766 []>, TB;
Dan Gohman78e04d42009-04-30 03:11:48 +00003767let mayLoad = 1 in
Dan Gohman21e3dfb2009-04-13 16:09:41 +00003768def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
3769 (outs GR32_NOREX:$dst), (ins i8mem:$src),
3770 "movz{bl|x}\t{$src, $dst|$dst, $src} # NOREX",
3771 []>, TB;
3772
Chris Lattnerba7e7562008-01-10 07:59:24 +00003773let neverHasSideEffects = 1 in {
3774 let Defs = [AX], Uses = [AL] in
3775 def CBW : I<0x98, RawFrm, (outs), (ins),
3776 "{cbtw|cbw}", []>, OpSize; // AX = signext(AL)
3777 let Defs = [EAX], Uses = [AX] in
3778 def CWDE : I<0x98, RawFrm, (outs), (ins),
3779 "{cwtl|cwde}", []>; // EAX = signext(AX)
Evan Chengf91c1012006-05-31 22:05:11 +00003780
Chris Lattnerba7e7562008-01-10 07:59:24 +00003781 let Defs = [AX,DX], Uses = [AX] in
3782 def CWD : I<0x99, RawFrm, (outs), (ins),
3783 "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
3784 let Defs = [EAX,EDX], Uses = [EAX] in
3785 def CDQ : I<0x99, RawFrm, (outs), (ins),
3786 "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
3787}
Evan Cheng747a90d2006-02-21 02:24:38 +00003788
Evan Cheng747a90d2006-02-21 02:24:38 +00003789//===----------------------------------------------------------------------===//
3790// Alias Instructions
3791//===----------------------------------------------------------------------===//
3792
3793// Alias instructions that map movr0 to xor.
3794// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
Chris Lattner35e0e842010-02-05 21:21:06 +00003795// FIXME: Set encoding to pseudo.
Daniel Dunbar7417b762009-08-11 22:17:52 +00003796let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
3797 isCodeGenOnly = 1 in {
Chris Lattner35e0e842010-02-05 21:21:06 +00003798def MOV8r0 : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "",
Evan Cheng069287d2006-05-16 07:21:53 +00003799 [(set GR8:$dst, 0)]>;
Dan Gohmanf1b4d262010-01-12 04:42:54 +00003800
3801// We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller
3802// encoding and avoids a partial-register update sometimes, but doing so
3803// at isel time interferes with rematerialization in the current register
3804// allocator. For now, this is rewritten when the instruction is lowered
3805// to an MCInst.
3806def MOV16r0 : I<0x31, MRMInitReg, (outs GR16:$dst), (ins),
3807 "",
3808 [(set GR16:$dst, 0)]>, OpSize;
Chris Lattner6a381822009-12-23 01:30:26 +00003809
Chris Lattner35e0e842010-02-05 21:21:06 +00003810// FIXME: Set encoding to pseudo.
3811def MOV32r0 : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "",
Chris Lattnerac105c42009-12-23 01:46:40 +00003812 [(set GR32:$dst, 0)]>;
3813}
Chris Lattner6a381822009-12-23 01:30:26 +00003814
Evan Cheng510e4782006-01-09 23:10:28 +00003815//===----------------------------------------------------------------------===//
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +00003816// Thread Local Storage Instructions
3817//
3818
Rafael Espindola15f1b662009-04-24 12:59:40 +00003819// All calls clobber the non-callee saved registers. ESP is marked as
3820// a use to prevent stack-pointer assignments that appear immediately
3821// before calls from potentially appearing dead.
3822let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3823 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3824 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3825 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
Chris Lattner5c0b16d2009-06-20 20:38:48 +00003826 Uses = [ESP] in
3827def TLS_addr32 : I<0, Pseudo, (outs), (ins lea32mem:$sym),
3828 "leal\t$sym, %eax; "
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003829 "call\t___tls_get_addr@PLT",
Chris Lattner5c0b16d2009-06-20 20:38:48 +00003830 [(X86tlsaddr tls32addr:$sym)]>,
Rafael Espindola2ee3db32009-04-17 14:35:58 +00003831 Requires<[In32BitMode]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +00003832
Eric Christopher30ef0e52010-06-03 04:07:48 +00003833// FIXME: Not true for darwin
3834let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3835 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3836 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3837 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
3838 Uses = [ESP],
3839 usesCustomInserter = 1 in
3840def TLSCall_32 : I<0, Pseudo, (outs), (ins GR32:$sym),
3841 "# Fixme into a call",
3842 [(X86TLSCall GR32:$sym)]>,
3843 Requires<[In32BitMode]>;
3844
Daniel Dunbar0c420fc2009-08-11 22:24:40 +00003845let AddedComplexity = 5, isCodeGenOnly = 1 in
Nate Begeman51a04372009-01-26 01:24:32 +00003846def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3847 "movl\t%gs:$src, $dst",
3848 [(set GR32:$dst, (gsload addr:$src))]>, SegGS;
3849
Daniel Dunbar0c420fc2009-08-11 22:24:40 +00003850let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattner1777d0c2009-05-05 18:52:19 +00003851def FS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3852 "movl\t%fs:$src, $dst",
3853 [(set GR32:$dst, (fsload addr:$src))]>, SegFS;
3854
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +00003855//===----------------------------------------------------------------------===//
Anton Korobeynikov2365f512007-07-14 14:06:15 +00003856// EH Pseudo Instructions
3857//
3858let isTerminator = 1, isReturn = 1, isBarrier = 1,
Daniel Dunbar1ca3a0b2009-08-27 07:58:05 +00003859 hasCtrlDep = 1, isCodeGenOnly = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00003860def EH_RETURN : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
Dan Gohmanb1576f52007-07-31 20:11:57 +00003861 "ret\t#eh_return, addr: $addr",
Anton Korobeynikov2365f512007-07-14 14:06:15 +00003862 [(X86ehret GR32:$addr)]>;
3863
3864}
3865
3866//===----------------------------------------------------------------------===//
Andrew Lenharthab0b9492008-02-21 06:45:13 +00003867// Atomic support
3868//
Andrew Lenharthea7da502008-03-01 13:37:02 +00003869
Evan Chengbb6939d2008-04-19 01:20:30 +00003870// Atomic swap. These are just normal xchg instructions. But since a memory
3871// operand is referenced, the atomicity is ensured.
Dan Gohman165660e2008-08-06 15:52:50 +00003872let Constraints = "$val = $dst" in {
Sean Callanan108934c2009-12-18 00:01:26 +00003873def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst),
3874 (ins GR32:$val, i32mem:$ptr),
Evan Chengbb6939d2008-04-19 01:20:30 +00003875 "xchg{l}\t{$val, $ptr|$ptr, $val}",
3876 [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00003877def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst),
3878 (ins GR16:$val, i16mem:$ptr),
Evan Chengbb6939d2008-04-19 01:20:30 +00003879 "xchg{w}\t{$val, $ptr|$ptr, $val}",
3880 [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>,
3881 OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00003882def XCHG8rm : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
Evan Chengbb6939d2008-04-19 01:20:30 +00003883 "xchg{b}\t{$val, $ptr|$ptr, $val}",
3884 [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00003885
3886def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
3887 "xchg{l}\t{$val, $src|$src, $val}", []>;
3888def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
3889 "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
3890def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
3891 "xchg{b}\t{$val, $src|$src, $val}", []>;
Evan Chengbb6939d2008-04-19 01:20:30 +00003892}
3893
Sean Callanan108934c2009-12-18 00:01:26 +00003894def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
3895 "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3896def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
3897 "xchg{l}\t{$src, %eax|%eax, $src}", []>;
3898
Evan Cheng7e032802008-04-18 20:55:36 +00003899// Atomic compare and swap.
Andrew Lenharth26ed8692008-03-01 21:52:34 +00003900let Defs = [EAX, EFLAGS], Uses = [EAX] in {
Evan Cheng7e032802008-04-18 20:55:36 +00003901def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003902 "lock\n\t"
3903 "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
Evan Cheng32967d22008-03-04 03:20:06 +00003904 [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
Andrew Lenharthea7da502008-03-01 13:37:02 +00003905}
Dale Johannesen48c1bc22008-10-02 18:53:47 +00003906let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
Evan Chengb093bd02010-01-08 01:29:19 +00003907def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003908 "lock\n\t"
3909 "cmpxchg8b\t$ptr",
Andrew Lenharthd19189e2008-03-05 01:15:49 +00003910 [(X86cas8 addr:$ptr)]>, TB, LOCK;
3911}
Andrew Lenharth26ed8692008-03-01 21:52:34 +00003912
3913let Defs = [AX, EFLAGS], Uses = [AX] in {
Evan Cheng7e032802008-04-18 20:55:36 +00003914def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003915 "lock\n\t"
3916 "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
Evan Cheng32967d22008-03-04 03:20:06 +00003917 [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
Andrew Lenharthea7da502008-03-01 13:37:02 +00003918}
Andrew Lenharth26ed8692008-03-01 21:52:34 +00003919let Defs = [AL, EFLAGS], Uses = [AL] in {
Evan Cheng7e032802008-04-18 20:55:36 +00003920def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003921 "lock\n\t"
3922 "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
Evan Cheng32967d22008-03-04 03:20:06 +00003923 [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
Andrew Lenharthea7da502008-03-01 13:37:02 +00003924}
3925
Evan Cheng7e032802008-04-18 20:55:36 +00003926// Atomic exchange and add
3927let Constraints = "$val = $dst", Defs = [EFLAGS] in {
Sean Callanan108934c2009-12-18 00:01:26 +00003928def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003929 "lock\n\t"
3930 "xadd{l}\t{$val, $ptr|$ptr, $val}",
Mon P Wang28873102008-06-25 08:15:39 +00003931 [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
Evan Cheng7e032802008-04-18 20:55:36 +00003932 TB, LOCK;
Sean Callanan108934c2009-12-18 00:01:26 +00003933def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003934 "lock\n\t"
3935 "xadd{w}\t{$val, $ptr|$ptr, $val}",
Mon P Wang28873102008-06-25 08:15:39 +00003936 [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
Evan Cheng7e032802008-04-18 20:55:36 +00003937 TB, OpSize, LOCK;
Sean Callanan108934c2009-12-18 00:01:26 +00003938def LXADD8 : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
Dan Gohman4d47b9b2009-04-27 15:13:28 +00003939 "lock\n\t"
3940 "xadd{b}\t{$val, $ptr|$ptr, $val}",
Mon P Wang28873102008-06-25 08:15:39 +00003941 [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
Evan Cheng7e032802008-04-18 20:55:36 +00003942 TB, LOCK;
Andrew Lenharthea7da502008-03-01 13:37:02 +00003943}
3944
Sean Callanan108934c2009-12-18 00:01:26 +00003945def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3946 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3947def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3948 "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3949def XADD32rr : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
3950 "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
3951
Dan Gohman7f357ec2010-05-14 16:34:55 +00003952let mayLoad = 1, mayStore = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00003953def XADD8rm : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
3954 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3955def XADD16rm : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
3956 "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3957def XADD32rm : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3958 "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
Dan Gohman7f357ec2010-05-14 16:34:55 +00003959}
Sean Callanan108934c2009-12-18 00:01:26 +00003960
3961def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3962 "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
3963def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3964 "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3965def CMPXCHG32rr : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
3966 "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
3967
Dan Gohman7f357ec2010-05-14 16:34:55 +00003968let mayLoad = 1, mayStore = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00003969def CMPXCHG8rm : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
3970 "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
3971def CMPXCHG16rm : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
3972 "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3973def CMPXCHG32rm : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3974 "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
Dan Gohman7f357ec2010-05-14 16:34:55 +00003975}
Sean Callanan108934c2009-12-18 00:01:26 +00003976
Evan Chengb093bd02010-01-08 01:29:19 +00003977let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00003978def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
3979 "cmpxchg8b\t$dst", []>, TB;
3980
Evan Cheng37b73872009-07-30 08:33:02 +00003981// Optimized codegen when the non-memory output is not used.
3982// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
Dan Gohman7f357ec2010-05-14 16:34:55 +00003983let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
Evan Cheng37b73872009-07-30 08:33:02 +00003984def LOCK_ADD8mr : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
3985 "lock\n\t"
3986 "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3987def LOCK_ADD16mr : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3988 "lock\n\t"
3989 "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3990def LOCK_ADD32mr : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
3991 "lock\n\t"
3992 "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3993def LOCK_ADD8mi : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
3994 "lock\n\t"
3995 "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3996def LOCK_ADD16mi : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
3997 "lock\n\t"
3998 "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3999def LOCK_ADD32mi : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
4000 "lock\n\t"
4001 "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4002def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
4003 "lock\n\t"
4004 "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4005def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4006 "lock\n\t"
4007 "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4008
4009def LOCK_INC8m : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
4010 "lock\n\t"
4011 "inc{b}\t$dst", []>, LOCK;
4012def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
4013 "lock\n\t"
4014 "inc{w}\t$dst", []>, OpSize, LOCK;
4015def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
4016 "lock\n\t"
4017 "inc{l}\t$dst", []>, LOCK;
4018
4019def LOCK_SUB8mr : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
4020 "lock\n\t"
4021 "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4022def LOCK_SUB16mr : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
4023 "lock\n\t"
4024 "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4025def LOCK_SUB32mr : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
4026 "lock\n\t"
4027 "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4028def LOCK_SUB8mi : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2),
4029 "lock\n\t"
4030 "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4031def LOCK_SUB16mi : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2),
4032 "lock\n\t"
4033 "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4034def LOCK_SUB32mi : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2),
4035 "lock\n\t"
4036 "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
Sean Callanan108934c2009-12-18 00:01:26 +00004037def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
Evan Cheng37b73872009-07-30 08:33:02 +00004038 "lock\n\t"
4039 "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4040def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4041 "lock\n\t"
4042 "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4043
4044def LOCK_DEC8m : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
4045 "lock\n\t"
4046 "dec{b}\t$dst", []>, LOCK;
4047def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
4048 "lock\n\t"
4049 "dec{w}\t$dst", []>, OpSize, LOCK;
4050def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
4051 "lock\n\t"
4052 "dec{l}\t$dst", []>, LOCK;
Dan Gohmanbab42bd2009-10-20 18:14:49 +00004053}
Evan Cheng37b73872009-07-30 08:33:02 +00004054
Mon P Wang28873102008-06-25 08:15:39 +00004055// Atomic exchange, and, or, xor
Mon P Wang63307c32008-05-05 19:05:59 +00004056let Constraints = "$val = $dst", Defs = [EFLAGS],
Dan Gohman533297b2009-10-29 18:10:34 +00004057 usesCustomInserter = 1 in {
Dan Gohman9499b712008-05-12 20:22:45 +00004058def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004059 "#ATOMAND32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004060 [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004061def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004062 "#ATOMOR32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004063 [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004064def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004065 "#ATOMXOR32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004066 [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
Andrew Lenharth507a58a2008-06-14 05:48:15 +00004067def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004068 "#ATOMNAND32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004069 [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004070def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004071 "#ATOMMIN32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004072 [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004073def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004074 "#ATOMMAX32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004075 [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004076def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004077 "#ATOMUMIN32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004078 [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
Dan Gohman9499b712008-05-12 20:22:45 +00004079def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004080 "#ATOMUMAX32 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004081 [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004082
4083def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004084 "#ATOMAND16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004085 [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004086def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004087 "#ATOMOR16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004088 [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004089def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004090 "#ATOMXOR16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004091 [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004092def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004093 "#ATOMNAND16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004094 [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004095def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004096 "#ATOMMIN16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004097 [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004098def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004099 "#ATOMMAX16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004100 [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004101def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004102 "#ATOMUMIN16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004103 [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004104def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004105 "#ATOMUMAX16 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004106 [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004107
4108def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004109 "#ATOMAND8 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004110 [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004111def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004112 "#ATOMOR8 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004113 [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004114def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004115 "#ATOMXOR8 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004116 [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
Dale Johannesen140be2d2008-08-19 18:47:28 +00004117def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004118 "#ATOMNAND8 PSEUDO!",
Dale Johannesene00a8a22008-08-28 02:44:49 +00004119 [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
Mon P Wang63307c32008-05-05 19:05:59 +00004120}
4121
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004122let Constraints = "$val1 = $dst1, $val2 = $dst2",
4123 Defs = [EFLAGS, EAX, EBX, ECX, EDX],
4124 Uses = [EAX, EBX, ECX, EDX],
Dale Johannesen1b54c7f2008-10-03 19:41:08 +00004125 mayLoad = 1, mayStore = 1,
Dan Gohman533297b2009-10-29 18:10:34 +00004126 usesCustomInserter = 1 in {
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004127def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4128 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004129 "#ATOMAND6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004130def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4131 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004132 "#ATOMOR6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004133def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4134 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004135 "#ATOMXOR6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004136def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4137 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004138 "#ATOMNAND6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004139def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4140 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004141 "#ATOMADD6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004142def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4143 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004144 "#ATOMSUB6432 PSEUDO!", []>;
Dale Johannesen880ae362008-10-03 22:25:52 +00004145def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4146 (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
Nick Lewycky6ecf5ce2008-12-07 03:49:52 +00004147 "#ATOMSWAP6432 PSEUDO!", []>;
Dale Johannesen48c1bc22008-10-02 18:53:47 +00004148}
4149
Sean Callanan358f1ef2009-09-16 21:55:34 +00004150// Segmentation support instructions.
4151
4152def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
4153 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4154def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4155 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4156
4157// i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
4158def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
4159 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
4160def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4161 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004162
4163def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
4164 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4165def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4166 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4167def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4168 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB;
4169def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4170 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB;
4171
Sean Callanan95a5a7d2010-02-13 01:48:34 +00004172def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004173
4174def STRr : I<0x00, MRM1r, (outs GR16:$dst), (ins),
4175 "str{w}\t{$dst}", []>, TB;
4176def STRm : I<0x00, MRM1m, (outs i16mem:$dst), (ins),
4177 "str{w}\t{$dst}", []>, TB;
4178def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src),
4179 "ltr{w}\t{$src}", []>, TB;
4180def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src),
4181 "ltr{w}\t{$src}", []>, TB;
4182
4183def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins),
4184 "push{w}\t%fs", []>, OpSize, TB;
4185def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins),
4186 "push{l}\t%fs", []>, TB;
4187def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins),
4188 "push{w}\t%gs", []>, OpSize, TB;
4189def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins),
4190 "push{l}\t%gs", []>, TB;
4191
4192def POPFS16 : I<0xa1, RawFrm, (outs), (ins),
4193 "pop{w}\t%fs", []>, OpSize, TB;
4194def POPFS32 : I<0xa1, RawFrm, (outs), (ins),
4195 "pop{l}\t%fs", []>, TB;
4196def POPGS16 : I<0xa9, RawFrm, (outs), (ins),
4197 "pop{w}\t%gs", []>, OpSize, TB;
4198def POPGS32 : I<0xa9, RawFrm, (outs), (ins),
4199 "pop{l}\t%gs", []>, TB;
4200
4201def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4202 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4203def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4204 "lds{l}\t{$src, $dst|$dst, $src}", []>;
4205def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4206 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4207def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4208 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB;
4209def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4210 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4211def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4212 "les{l}\t{$src, $dst|$dst, $src}", []>;
4213def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4214 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4215def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4216 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4217def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4218 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4219def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4220 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4221
4222def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg),
4223 "verr\t$seg", []>, TB;
4224def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg),
4225 "verr\t$seg", []>, TB;
4226def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg),
4227 "verw\t$seg", []>, TB;
4228def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg),
4229 "verw\t$seg", []>, TB;
4230
4231// Descriptor-table support instructions
4232
4233def SGDTm : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
4234 "sgdt\t$dst", []>, TB;
4235def SIDTm : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
4236 "sidt\t$dst", []>, TB;
4237def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
4238 "sldt{w}\t$dst", []>, TB;
4239def SLDT16m : I<0x00, MRM0m, (outs i16mem:$dst), (ins),
4240 "sldt{w}\t$dst", []>, TB;
4241def LGDTm : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
4242 "lgdt\t$src", []>, TB;
4243def LIDTm : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
4244 "lidt\t$src", []>, TB;
4245def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
4246 "lldt{w}\t$src", []>, TB;
4247def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
4248 "lldt{w}\t$src", []>, TB;
Sean Callanan9a86f102009-09-16 22:59:28 +00004249
Kevin Enderby12ce0de2010-02-03 21:04:42 +00004250// Lock instruction prefix
4251def LOCK_PREFIX : I<0xF0, RawFrm, (outs), (ins), "lock", []>;
4252
4253// Repeat string operation instruction prefixes
4254// These uses the DF flag in the EFLAGS register to inc or dec ECX
4255let Defs = [ECX], Uses = [ECX,EFLAGS] in {
4256// Repeat (used with INS, OUTS, MOVS, LODS and STOS)
4257def REP_PREFIX : I<0xF3, RawFrm, (outs), (ins), "rep", []>;
4258// Repeat while not equal (used with CMPS and SCAS)
4259def REPNE_PREFIX : I<0xF2, RawFrm, (outs), (ins), "repne", []>;
4260}
4261
4262// Segment override instruction prefixes
4263def CS_PREFIX : I<0x2E, RawFrm, (outs), (ins), "cs", []>;
4264def SS_PREFIX : I<0x36, RawFrm, (outs), (ins), "ss", []>;
4265def DS_PREFIX : I<0x3E, RawFrm, (outs), (ins), "ds", []>;
4266def ES_PREFIX : I<0x26, RawFrm, (outs), (ins), "es", []>;
4267def FS_PREFIX : I<0x64, RawFrm, (outs), (ins), "fs", []>;
4268def GS_PREFIX : I<0x65, RawFrm, (outs), (ins), "gs", []>;
4269
Sean Callanan9a86f102009-09-16 22:59:28 +00004270// String manipulation instructions
4271
4272def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
4273def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00004274def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
4275
4276def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
4277def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
4278def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
4279
4280// CPU flow control instructions
4281
4282def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
4283def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
4284
4285// FPU control instructions
4286
4287def FNINIT : I<0xE3, RawFrm, (outs), (ins), "fninit", []>, DB;
4288
4289// Flag instructions
4290
4291def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
4292def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
4293def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
4294def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
4295def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
4296def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
4297def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
4298
4299def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
4300
4301// Table lookup instructions
4302
4303def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
4304
4305// Specialized register support
4306
4307def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
4308def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
4309def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
4310
4311def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins),
4312 "smsw{w}\t$dst", []>, OpSize, TB;
4313def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins),
4314 "smsw{l}\t$dst", []>, TB;
4315// For memory operands, there is only a 16-bit form
4316def SMSW16m : I<0x01, MRM4m, (outs i16mem:$dst), (ins),
4317 "smsw{w}\t$dst", []>, TB;
4318
4319def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
4320 "lmsw{w}\t$src", []>, TB;
4321def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
4322 "lmsw{w}\t$src", []>, TB;
4323
4324def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
4325
4326// Cache instructions
4327
4328def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
4329def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", []>, TB;
4330
4331// VMX instructions
4332
4333// 66 0F 38 80
Sean Callanan95a5a7d2010-02-13 01:48:34 +00004334def INVEPT : I<0x80, RawFrm, (outs), (ins), "invept", []>, OpSize, T8;
Sean Callanan108934c2009-12-18 00:01:26 +00004335// 66 0F 38 81
Sean Callanan95a5a7d2010-02-13 01:48:34 +00004336def INVVPID : I<0x81, RawFrm, (outs), (ins), "invvpid", []>, OpSize, T8;
Sean Callanan108934c2009-12-18 00:01:26 +00004337// 0F 01 C1
Chris Lattnerfdfeb692010-02-12 20:49:41 +00004338def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004339def VMCLEARm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4340 "vmclear\t$vmcs", []>, OpSize, TB;
4341// 0F 01 C2
Chris Lattnera599de22010-02-13 00:41:14 +00004342def VMLAUNCH : I<0x01, MRM_C2, (outs), (ins), "vmlaunch", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004343// 0F 01 C3
Chris Lattnera599de22010-02-13 00:41:14 +00004344def VMRESUME : I<0x01, MRM_C3, (outs), (ins), "vmresume", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004345def VMPTRLDm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4346 "vmptrld\t$vmcs", []>, TB;
4347def VMPTRSTm : I<0xC7, MRM7m, (outs i64mem:$vmcs), (ins),
4348 "vmptrst\t$vmcs", []>, TB;
4349def VMREAD64rm : I<0x78, MRMDestMem, (outs i64mem:$dst), (ins GR64:$src),
4350 "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4351def VMREAD64rr : I<0x78, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
4352 "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4353def VMREAD32rm : I<0x78, MRMDestMem, (outs i32mem:$dst), (ins GR32:$src),
4354 "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4355def VMREAD32rr : I<0x78, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4356 "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4357def VMWRITE64rm : I<0x79, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
4358 "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4359def VMWRITE64rr : I<0x79, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
4360 "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4361def VMWRITE32rm : I<0x79, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4362 "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4363def VMWRITE32rr : I<0x79, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4364 "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4365// 0F 01 C4
Chris Lattnera599de22010-02-13 00:41:14 +00004366def VMXOFF : I<0x01, MRM_C4, (outs), (ins), "vmxoff", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00004367def VMXON : I<0xC7, MRM6m, (outs), (ins i64mem:$vmxon),
Kevin Enderby0e822402010-03-08 22:17:26 +00004368 "vmxon\t{$vmxon}", []>, XS;
Sean Callanan358f1ef2009-09-16 21:55:34 +00004369
Andrew Lenharthab0b9492008-02-21 06:45:13 +00004370//===----------------------------------------------------------------------===//
Evan Cheng510e4782006-01-09 23:10:28 +00004371// Non-Instruction Patterns
4372//===----------------------------------------------------------------------===//
4373
Bill Wendling056292f2008-09-16 21:48:12 +00004374// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Evan Cheng71fb8342006-02-25 10:02:21 +00004375def : Pat<(i32 (X86Wrapper tconstpool :$dst)), (MOV32ri tconstpool :$dst)>;
Nate Begeman37efe672006-04-22 18:53:45 +00004376def : Pat<(i32 (X86Wrapper tjumptable :$dst)), (MOV32ri tjumptable :$dst)>;
Nate Begeman6795ebb2008-04-12 00:47:57 +00004377def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
Evan Cheng71fb8342006-02-25 10:02:21 +00004378def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
4379def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
Dan Gohmanf705adb2009-10-30 01:28:02 +00004380def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>;
Evan Cheng71fb8342006-02-25 10:02:21 +00004381
Evan Cheng069287d2006-05-16 07:21:53 +00004382def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
4383 (ADD32ri GR32:$src1, tconstpool:$src2)>;
4384def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
4385 (ADD32ri GR32:$src1, tjumptable:$src2)>;
4386def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
4387 (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
4388def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
4389 (ADD32ri GR32:$src1, texternalsym:$src2)>;
Dan Gohmanf705adb2009-10-30 01:28:02 +00004390def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)),
4391 (ADD32ri GR32:$src1, tblockaddress:$src2)>;
Evan Cheng71fb8342006-02-25 10:02:21 +00004392
Evan Chengfc8feb12006-05-19 07:30:36 +00004393def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
Evan Cheng71fb8342006-02-25 10:02:21 +00004394 (MOV32mi addr:$dst, tglobaladdr:$src)>;
Evan Chengfc8feb12006-05-19 07:30:36 +00004395def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
Evan Cheng71fb8342006-02-25 10:02:21 +00004396 (MOV32mi addr:$dst, texternalsym:$src)>;
Dan Gohmanf705adb2009-10-30 01:28:02 +00004397def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst),
4398 (MOV32mi addr:$dst, tblockaddress:$src)>;
Evan Cheng71fb8342006-02-25 10:02:21 +00004399
Evan Cheng510e4782006-01-09 23:10:28 +00004400// Calls
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +00004401// tailcall stuff
Evan Chengf48ef032010-03-14 03:48:46 +00004402def : Pat<(X86tcret GR32_TC:$dst, imm:$off),
4403 (TCRETURNri GR32_TC:$dst, imm:$off)>,
4404 Requires<[In32BitMode]>;
4405
Evan Chengcb0f06e2010-03-25 00:10:31 +00004406// FIXME: This is disabled for 32-bit PIC mode because the global base
4407// register which is part of the address mode may be assigned a
4408// callee-saved register.
Evan Chengf48ef032010-03-14 03:48:46 +00004409def : Pat<(X86tcret (load addr:$dst), imm:$off),
4410 (TCRETURNmi addr:$dst, imm:$off)>,
Evan Chengcb0f06e2010-03-25 00:10:31 +00004411 Requires<[In32BitMode, IsNotPIC]>;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +00004412
4413def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
Evan Chengf48ef032010-03-14 03:48:46 +00004414 (TCRETURNdi texternalsym:$dst, imm:$off)>,
4415 Requires<[In32BitMode]>;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +00004416
4417def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
Evan Chengf48ef032010-03-14 03:48:46 +00004418 (TCRETURNdi texternalsym:$dst, imm:$off)>,
4419 Requires<[In32BitMode]>;
Evan Chengfea89c12006-04-27 08:40:39 +00004420
Dan Gohmancadb2262009-08-02 16:10:01 +00004421// Normal calls, with various flavors of addresses.
Evan Cheng25ab6902006-09-08 06:48:29 +00004422def : Pat<(X86call (i32 tglobaladdr:$dst)),
Evan Cheng510e4782006-01-09 23:10:28 +00004423 (CALLpcrel32 tglobaladdr:$dst)>;
Evan Cheng25ab6902006-09-08 06:48:29 +00004424def : Pat<(X86call (i32 texternalsym:$dst)),
Evan Cheng8700e142006-01-11 06:09:51 +00004425 (CALLpcrel32 texternalsym:$dst)>;
Evan Chengd7f666a2009-05-20 04:53:57 +00004426def : Pat<(X86call (i32 imm:$dst)),
4427 (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
Evan Cheng510e4782006-01-09 23:10:28 +00004428
4429// X86 specific add which produces a flag.
Evan Cheng069287d2006-05-16 07:21:53 +00004430def : Pat<(addc GR32:$src1, GR32:$src2),
4431 (ADD32rr GR32:$src1, GR32:$src2)>;
4432def : Pat<(addc GR32:$src1, (load addr:$src2)),
4433 (ADD32rm GR32:$src1, addr:$src2)>;
4434def : Pat<(addc GR32:$src1, imm:$src2),
4435 (ADD32ri GR32:$src1, imm:$src2)>;
4436def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
4437 (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
Evan Cheng510e4782006-01-09 23:10:28 +00004438
Evan Cheng069287d2006-05-16 07:21:53 +00004439def : Pat<(subc GR32:$src1, GR32:$src2),
4440 (SUB32rr GR32:$src1, GR32:$src2)>;
4441def : Pat<(subc GR32:$src1, (load addr:$src2)),
4442 (SUB32rm GR32:$src1, addr:$src2)>;
4443def : Pat<(subc GR32:$src1, imm:$src2),
4444 (SUB32ri GR32:$src1, imm:$src2)>;
4445def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
4446 (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
Evan Cheng510e4782006-01-09 23:10:28 +00004447
Chris Lattnerffc0b262006-09-07 20:33:45 +00004448// Comparisons.
4449
4450// TEST R,R is smaller than CMP R,0
Chris Lattnere3486a42010-03-19 00:01:11 +00004451def : Pat<(X86cmp GR8:$src1, 0),
Chris Lattnerffc0b262006-09-07 20:33:45 +00004452 (TEST8rr GR8:$src1, GR8:$src1)>;
Chris Lattnere3486a42010-03-19 00:01:11 +00004453def : Pat<(X86cmp GR16:$src1, 0),
Chris Lattnerffc0b262006-09-07 20:33:45 +00004454 (TEST16rr GR16:$src1, GR16:$src1)>;
Chris Lattnere3486a42010-03-19 00:01:11 +00004455def : Pat<(X86cmp GR32:$src1, 0),
Chris Lattnerffc0b262006-09-07 20:33:45 +00004456 (TEST32rr GR32:$src1, GR32:$src1)>;
4457
Dan Gohmanfbb74862009-01-07 01:00:24 +00004458// Conditional moves with folded loads with operands swapped and conditions
4459// inverted.
4460def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS),
4461 (CMOVAE16rm GR16:$src2, addr:$src1)>;
4462def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS),
4463 (CMOVAE32rm GR32:$src2, addr:$src1)>;
4464def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS),
4465 (CMOVB16rm GR16:$src2, addr:$src1)>;
4466def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS),
4467 (CMOVB32rm GR32:$src2, addr:$src1)>;
4468def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS),
4469 (CMOVNE16rm GR16:$src2, addr:$src1)>;
4470def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS),
4471 (CMOVNE32rm GR32:$src2, addr:$src1)>;
4472def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS),
4473 (CMOVE16rm GR16:$src2, addr:$src1)>;
4474def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS),
4475 (CMOVE32rm GR32:$src2, addr:$src1)>;
4476def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS),
4477 (CMOVA16rm GR16:$src2, addr:$src1)>;
4478def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS),
4479 (CMOVA32rm GR32:$src2, addr:$src1)>;
4480def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS),
4481 (CMOVBE16rm GR16:$src2, addr:$src1)>;
4482def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS),
4483 (CMOVBE32rm GR32:$src2, addr:$src1)>;
4484def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS),
4485 (CMOVGE16rm GR16:$src2, addr:$src1)>;
4486def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS),
4487 (CMOVGE32rm GR32:$src2, addr:$src1)>;
4488def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS),
4489 (CMOVL16rm GR16:$src2, addr:$src1)>;
4490def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS),
4491 (CMOVL32rm GR32:$src2, addr:$src1)>;
4492def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS),
4493 (CMOVG16rm GR16:$src2, addr:$src1)>;
4494def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS),
4495 (CMOVG32rm GR32:$src2, addr:$src1)>;
4496def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS),
4497 (CMOVLE16rm GR16:$src2, addr:$src1)>;
4498def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS),
4499 (CMOVLE32rm GR32:$src2, addr:$src1)>;
4500def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS),
4501 (CMOVNP16rm GR16:$src2, addr:$src1)>;
4502def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS),
4503 (CMOVNP32rm GR32:$src2, addr:$src1)>;
4504def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS),
4505 (CMOVP16rm GR16:$src2, addr:$src1)>;
4506def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS),
4507 (CMOVP32rm GR32:$src2, addr:$src1)>;
4508def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS),
4509 (CMOVNS16rm GR16:$src2, addr:$src1)>;
4510def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS),
4511 (CMOVNS32rm GR32:$src2, addr:$src1)>;
4512def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS),
4513 (CMOVS16rm GR16:$src2, addr:$src1)>;
4514def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS),
4515 (CMOVS32rm GR32:$src2, addr:$src1)>;
4516def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS),
4517 (CMOVNO16rm GR16:$src2, addr:$src1)>;
4518def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS),
4519 (CMOVNO32rm GR32:$src2, addr:$src1)>;
4520def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS),
4521 (CMOVO16rm GR16:$src2, addr:$src1)>;
4522def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS),
4523 (CMOVO32rm GR32:$src2, addr:$src1)>;
4524
Duncan Sandsf9c98e62008-01-23 20:39:46 +00004525// zextload bool -> zextload byte
Evan Chenge5d93432006-01-17 07:02:46 +00004526def : Pat<(zextloadi8i1 addr:$src), (MOV8rm addr:$src)>;
Evan Cheng510e4782006-01-09 23:10:28 +00004527def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
4528def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
4529
4530// extload bool -> extload byte
Evan Cheng47137242006-05-05 08:23:07 +00004531def : Pat<(extloadi8i1 addr:$src), (MOV8rm addr:$src)>;
Dan Gohmanaf70e5c2009-08-26 14:59:13 +00004532def : Pat<(extloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
Evan Cheng47137242006-05-05 08:23:07 +00004533def : Pat<(extloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
Dan Gohmanaf70e5c2009-08-26 14:59:13 +00004534def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;
Evan Cheng47137242006-05-05 08:23:07 +00004535def : Pat<(extloadi32i8 addr:$src), (MOVZX32rm8 addr:$src)>;
4536def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
Evan Cheng510e4782006-01-09 23:10:28 +00004537
Dan Gohmanaf70e5c2009-08-26 14:59:13 +00004538// anyext. Define these to do an explicit zero-extend to
4539// avoid partial-register updates.
4540def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8 GR8 :$src)>;
4541def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8 GR8 :$src)>;
Evan Cheng5528e7b2010-04-21 01:47:12 +00004542
Evan Cheng2bce5f4b2010-04-28 08:30:49 +00004543// Except for i16 -> i32 since isel expect i16 ops to be promoted to i32.
Evan Cheng5528e7b2010-04-21 01:47:12 +00004544def : Pat<(i32 (anyext GR16:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004545 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR16:$src, sub_16bit)>;
Evan Cheng5528e7b2010-04-21 01:47:12 +00004546
Evan Cheng510e4782006-01-09 23:10:28 +00004547
Evan Chengcfa260b2006-01-06 02:31:59 +00004548//===----------------------------------------------------------------------===//
4549// Some peepholes
4550//===----------------------------------------------------------------------===//
4551
Dan Gohman63f97202008-10-17 01:33:43 +00004552// Odd encoding trick: -128 fits into an 8-bit immediate field while
4553// +128 doesn't, so in this special case use a sub instead of an add.
4554def : Pat<(add GR16:$src1, 128),
4555 (SUB16ri8 GR16:$src1, -128)>;
4556def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst),
4557 (SUB16mi8 addr:$dst, -128)>;
4558def : Pat<(add GR32:$src1, 128),
4559 (SUB32ri8 GR32:$src1, -128)>;
4560def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst),
4561 (SUB32mi8 addr:$dst, -128)>;
4562
Dan Gohman11ba3b12008-07-30 18:09:17 +00004563// r & (2^16-1) ==> movz
4564def : Pat<(and GR32:$src1, 0xffff),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004565 (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, sub_16bit))>;
Dan Gohman8a1510d2008-08-06 18:27:21 +00004566// r & (2^8-1) ==> movz
4567def : Pat<(and GR32:$src1, 0xff),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004568 (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src1,
4569 GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004570 sub_8bit))>,
Dan Gohman8a1510d2008-08-06 18:27:21 +00004571 Requires<[In32BitMode]>;
4572// r & (2^8-1) ==> movz
4573def : Pat<(and GR16:$src1, 0xff),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004574 (MOVZX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src1,
4575 GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004576 sub_8bit))>,
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004577 Requires<[In32BitMode]>;
4578
4579// sext_inreg patterns
4580def : Pat<(sext_inreg GR32:$src, i16),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004581 (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, sub_16bit))>;
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004582def : Pat<(sext_inreg GR32:$src, i8),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004583 (MOVSX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
4584 GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004585 sub_8bit))>,
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004586 Requires<[In32BitMode]>;
4587def : Pat<(sext_inreg GR16:$src, i8),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004588 (MOVSX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src,
4589 GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004590 sub_8bit))>,
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004591 Requires<[In32BitMode]>;
4592
4593// trunc patterns
4594def : Pat<(i16 (trunc GR32:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004595 (EXTRACT_SUBREG GR32:$src, sub_16bit)>;
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004596def : Pat<(i8 (trunc GR32:$src)),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004597 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004598 sub_8bit)>,
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00004599 Requires<[In32BitMode]>;
4600def : Pat<(i8 (trunc GR16:$src)),
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004601 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004602 sub_8bit)>,
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004603 Requires<[In32BitMode]>;
4604
4605// h-register tricks
4606def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))),
Evan Cheng1c45acf2010-04-27 21:46:03 +00004607 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004608 sub_8bit_hi)>,
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004609 Requires<[In32BitMode]>;
4610def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))),
Evan Cheng1c45acf2010-04-27 21:46:03 +00004611 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004612 sub_8bit_hi)>,
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004613 Requires<[In32BitMode]>;
Dan Gohman7e0d64a2010-01-11 17:21:05 +00004614def : Pat<(srl GR16:$src, (i8 8)),
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004615 (EXTRACT_SUBREG
4616 (MOVZX32rr8
Anton Korobeynikov3a639a02009-11-02 00:11:39 +00004617 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004618 sub_8bit_hi)),
4619 sub_16bit)>,
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004620 Requires<[In32BitMode]>;
Evan Chengcb219f02009-05-29 01:44:43 +00004621def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
Sean Callanan108934c2009-12-18 00:01:26 +00004622 (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src,
4623 GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004624 sub_8bit_hi))>,
Evan Chengcb219f02009-05-29 01:44:43 +00004625 Requires<[In32BitMode]>;
Dan Gohmanaf70e5c2009-08-26 14:59:13 +00004626def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
Sean Callanan108934c2009-12-18 00:01:26 +00004627 (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src,
4628 GR16_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004629 sub_8bit_hi))>,
Dan Gohmanaf70e5c2009-08-26 14:59:13 +00004630 Requires<[In32BitMode]>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +00004631def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
Sean Callanan108934c2009-12-18 00:01:26 +00004632 (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
4633 GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004634 sub_8bit_hi))>,
Dan Gohman8a1510d2008-08-06 18:27:21 +00004635 Requires<[In32BitMode]>;
Evan Cheng2bce5f4b2010-04-28 08:30:49 +00004636def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
4637 (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src,
4638 GR32_ABCD)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00004639 sub_8bit_hi))>,
Evan Cheng2bce5f4b2010-04-28 08:30:49 +00004640 Requires<[In32BitMode]>;
Dan Gohman11ba3b12008-07-30 18:09:17 +00004641
Evan Chengcfa260b2006-01-06 02:31:59 +00004642// (shl x, 1) ==> (add x, x)
Evan Cheng069287d2006-05-16 07:21:53 +00004643def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr GR8 :$src1, GR8 :$src1)>;
4644def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
4645def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
Evan Cheng68b951a2006-01-19 01:56:29 +00004646
Evan Chengeb9f8922008-08-30 02:03:58 +00004647// (shl x (and y, 31)) ==> (shl x, y)
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004648def : Pat<(shl GR8:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004649 (SHL8rCL GR8:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004650def : Pat<(shl GR16:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004651 (SHL16rCL GR16:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004652def : Pat<(shl GR32:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004653 (SHL32rCL GR32:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004654def : Pat<(store (shl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004655 (SHL8mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004656def : Pat<(store (shl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004657 (SHL16mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004658def : Pat<(store (shl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004659 (SHL32mCL addr:$dst)>;
4660
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004661def : Pat<(srl GR8:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004662 (SHR8rCL GR8:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004663def : Pat<(srl GR16:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004664 (SHR16rCL GR16:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004665def : Pat<(srl GR32:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004666 (SHR32rCL GR32:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004667def : Pat<(store (srl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004668 (SHR8mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004669def : Pat<(store (srl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004670 (SHR16mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004671def : Pat<(store (srl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004672 (SHR32mCL addr:$dst)>;
4673
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004674def : Pat<(sra GR8:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004675 (SAR8rCL GR8:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004676def : Pat<(sra GR16:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004677 (SAR16rCL GR16:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004678def : Pat<(sra GR32:$src1, (and CL, 31)),
Evan Chengeb9f8922008-08-30 02:03:58 +00004679 (SAR32rCL GR32:$src1)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004680def : Pat<(store (sra (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004681 (SAR8mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004682def : Pat<(store (sra (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004683 (SAR16mCL addr:$dst)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00004684def : Pat<(store (sra (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
Evan Chengeb9f8922008-08-30 02:03:58 +00004685 (SAR32mCL addr:$dst)>;
4686
Evan Cheng2e489c42009-12-16 00:53:11 +00004687// (anyext (setcc_carry)) -> (setcc_carry)
4688def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
Evan Chengad9c0a32009-12-15 00:53:42 +00004689 (SETB_C16r)>;
Evan Cheng2e489c42009-12-16 00:53:11 +00004690def : Pat<(i32 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
Evan Chengad9c0a32009-12-15 00:53:42 +00004691 (SETB_C32r)>;
Evan Chenge5b51ac2010-04-17 06:13:15 +00004692def : Pat<(i32 (anyext (i16 (X86setcc_c X86_COND_B, EFLAGS)))),
4693 (SETB_C32r)>;
Evan Chengad9c0a32009-12-15 00:53:42 +00004694
Evan Cheng199c4242010-01-11 22:03:29 +00004695// (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
Evan Cheng3bda2012010-01-12 18:31:19 +00004696let AddedComplexity = 5 in { // Try this before the selecting to OR
Chris Lattnera0f70172010-03-24 00:15:23 +00004697def : Pat<(or_is_add GR16:$src1, imm:$src2),
Evan Cheng4b0345b2010-01-11 17:03:47 +00004698 (ADD16ri GR16:$src1, imm:$src2)>;
Chris Lattnera0f70172010-03-24 00:15:23 +00004699def : Pat<(or_is_add GR32:$src1, imm:$src2),
Evan Cheng4b0345b2010-01-11 17:03:47 +00004700 (ADD32ri GR32:$src1, imm:$src2)>;
Chris Lattnera0f70172010-03-24 00:15:23 +00004701def : Pat<(or_is_add GR16:$src1, i16immSExt8:$src2),
Evan Cheng4b0345b2010-01-11 17:03:47 +00004702 (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattnera0f70172010-03-24 00:15:23 +00004703def : Pat<(or_is_add GR32:$src1, i32immSExt8:$src2),
Evan Cheng4b0345b2010-01-11 17:03:47 +00004704 (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
Chris Lattnera0f70172010-03-24 00:15:23 +00004705def : Pat<(or_is_add GR16:$src1, GR16:$src2),
Evan Cheng199c4242010-01-11 22:03:29 +00004706 (ADD16rr GR16:$src1, GR16:$src2)>;
Chris Lattnera0f70172010-03-24 00:15:23 +00004707def : Pat<(or_is_add GR32:$src1, GR32:$src2),
Evan Cheng199c4242010-01-11 22:03:29 +00004708 (ADD32rr GR32:$src1, GR32:$src2)>;
Evan Cheng3bda2012010-01-12 18:31:19 +00004709} // AddedComplexity
Evan Cheng4b0345b2010-01-11 17:03:47 +00004710
Evan Cheng4e4c71e2006-02-21 20:00:20 +00004711//===----------------------------------------------------------------------===//
Dan Gohman076aee32009-03-04 19:44:21 +00004712// EFLAGS-defining Patterns
Bill Wendlingd350e022008-12-12 21:15:41 +00004713//===----------------------------------------------------------------------===//
4714
Chris Lattnerec856802010-03-27 00:45:04 +00004715// add reg, reg
4716def : Pat<(add GR8 :$src1, GR8 :$src2), (ADD8rr GR8 :$src1, GR8 :$src2)>;
4717def : Pat<(add GR16:$src1, GR16:$src2), (ADD16rr GR16:$src1, GR16:$src2)>;
4718def : Pat<(add GR32:$src1, GR32:$src2), (ADD32rr GR32:$src1, GR32:$src2)>;
Bill Wendlingd350e022008-12-12 21:15:41 +00004719
Chris Lattnerec856802010-03-27 00:45:04 +00004720// add reg, mem
4721def : Pat<(add GR8:$src1, (loadi8 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004722 (ADD8rm GR8:$src1, addr:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004723def : Pat<(add GR16:$src1, (loadi16 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004724 (ADD16rm GR16:$src1, addr:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004725def : Pat<(add GR32:$src1, (loadi32 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004726 (ADD32rm GR32:$src1, addr:$src2)>;
4727
Chris Lattnerec856802010-03-27 00:45:04 +00004728// add reg, imm
4729def : Pat<(add GR8 :$src1, imm:$src2), (ADD8ri GR8:$src1 , imm:$src2)>;
4730def : Pat<(add GR16:$src1, imm:$src2), (ADD16ri GR16:$src1, imm:$src2)>;
4731def : Pat<(add GR32:$src1, imm:$src2), (ADD32ri GR32:$src1, imm:$src2)>;
4732def : Pat<(add GR16:$src1, i16immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004733 (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004734def : Pat<(add GR32:$src1, i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004735 (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4736
Chris Lattnerec856802010-03-27 00:45:04 +00004737// sub reg, reg
4738def : Pat<(sub GR8 :$src1, GR8 :$src2), (SUB8rr GR8 :$src1, GR8 :$src2)>;
4739def : Pat<(sub GR16:$src1, GR16:$src2), (SUB16rr GR16:$src1, GR16:$src2)>;
4740def : Pat<(sub GR32:$src1, GR32:$src2), (SUB32rr GR32:$src1, GR32:$src2)>;
Bill Wendlingd350e022008-12-12 21:15:41 +00004741
Chris Lattnerec856802010-03-27 00:45:04 +00004742// sub reg, mem
4743def : Pat<(sub GR8:$src1, (loadi8 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004744 (SUB8rm GR8:$src1, addr:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004745def : Pat<(sub GR16:$src1, (loadi16 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004746 (SUB16rm GR16:$src1, addr:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004747def : Pat<(sub GR32:$src1, (loadi32 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004748 (SUB32rm GR32:$src1, addr:$src2)>;
4749
Chris Lattnerec856802010-03-27 00:45:04 +00004750// sub reg, imm
4751def : Pat<(sub GR8:$src1, imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004752 (SUB8ri GR8:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004753def : Pat<(sub GR16:$src1, imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004754 (SUB16ri GR16:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004755def : Pat<(sub GR32:$src1, imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004756 (SUB32ri GR32:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004757def : Pat<(sub GR16:$src1, i16immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004758 (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004759def : Pat<(sub GR32:$src1, i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004760 (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4761
Chris Lattnerec856802010-03-27 00:45:04 +00004762// mul reg, reg
4763def : Pat<(mul GR16:$src1, GR16:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004764 (IMUL16rr GR16:$src1, GR16:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004765def : Pat<(mul GR32:$src1, GR32:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004766 (IMUL32rr GR32:$src1, GR32:$src2)>;
4767
Chris Lattnerec856802010-03-27 00:45:04 +00004768// mul reg, mem
4769def : Pat<(mul GR16:$src1, (loadi16 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004770 (IMUL16rm GR16:$src1, addr:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004771def : Pat<(mul GR32:$src1, (loadi32 addr:$src2)),
Bill Wendlingd350e022008-12-12 21:15:41 +00004772 (IMUL32rm GR32:$src1, addr:$src2)>;
4773
Chris Lattnerec856802010-03-27 00:45:04 +00004774// mul reg, imm
4775def : Pat<(mul GR16:$src1, imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004776 (IMUL16rri GR16:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004777def : Pat<(mul GR32:$src1, imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004778 (IMUL32rri GR32:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004779def : Pat<(mul GR16:$src1, i16immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004780 (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004781def : Pat<(mul GR32:$src1, i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004782 (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>;
4783
Chris Lattnerec856802010-03-27 00:45:04 +00004784// reg = mul mem, imm
4785def : Pat<(mul (loadi16 addr:$src1), imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004786 (IMUL16rmi addr:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004787def : Pat<(mul (loadi32 addr:$src1), imm:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004788 (IMUL32rmi addr:$src1, imm:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004789def : Pat<(mul (loadi16 addr:$src1), i16immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004790 (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>;
Chris Lattnerec856802010-03-27 00:45:04 +00004791def : Pat<(mul (loadi32 addr:$src1), i32immSExt8:$src2),
Bill Wendlingd350e022008-12-12 21:15:41 +00004792 (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>;
4793
Dan Gohman076aee32009-03-04 19:44:21 +00004794// Optimize multiply by 2 with EFLAGS result.
Evan Cheng6a86bd72009-01-27 03:30:42 +00004795let AddedComplexity = 2 in {
Chris Lattnerbaba4bb2010-03-27 02:47:14 +00004796def : Pat<(X86smul_flag GR16:$src1, 2), (ADD16rr GR16:$src1, GR16:$src1)>;
4797def : Pat<(X86smul_flag GR32:$src1, 2), (ADD32rr GR32:$src1, GR32:$src1)>;
Evan Cheng6a86bd72009-01-27 03:30:42 +00004798}
4799
Chris Lattner589ad5d2010-03-25 05:44:01 +00004800// Patterns for nodes that do not produce flags, for instructions that do.
Chris Lattnerc54a2f12010-03-24 01:02:12 +00004801
Chris Lattner589ad5d2010-03-25 05:44:01 +00004802// Increment reg.
4803def : Pat<(add GR8:$src , 1), (INC8r GR8:$src)>;
4804def : Pat<(add GR16:$src, 1), (INC16r GR16:$src)>, Requires<[In32BitMode]>;
4805def : Pat<(add GR32:$src, 1), (INC32r GR32:$src)>, Requires<[In32BitMode]>;
Dan Gohman076aee32009-03-04 19:44:21 +00004806
Chris Lattner589ad5d2010-03-25 05:44:01 +00004807// Decrement reg.
4808def : Pat<(add GR8:$src , -1), (DEC8r GR8:$src)>;
4809def : Pat<(add GR16:$src, -1), (DEC16r GR16:$src)>, Requires<[In32BitMode]>;
4810def : Pat<(add GR32:$src, -1), (DEC32r GR32:$src)>, Requires<[In32BitMode]>;
Dan Gohman076aee32009-03-04 19:44:21 +00004811
Chris Lattner589ad5d2010-03-25 05:44:01 +00004812// or reg/reg.
4813def : Pat<(or GR8 :$src1, GR8 :$src2), (OR8rr GR8 :$src1, GR8 :$src2)>;
4814def : Pat<(or GR16:$src1, GR16:$src2), (OR16rr GR16:$src1, GR16:$src2)>;
4815def : Pat<(or GR32:$src1, GR32:$src2), (OR32rr GR32:$src1, GR32:$src2)>;
Dan Gohman076aee32009-03-04 19:44:21 +00004816
Chris Lattner589ad5d2010-03-25 05:44:01 +00004817// or reg/mem
4818def : Pat<(or GR8:$src1, (loadi8 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004819 (OR8rm GR8:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004820def : Pat<(or GR16:$src1, (loadi16 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004821 (OR16rm GR16:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004822def : Pat<(or GR32:$src1, (loadi32 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004823 (OR32rm GR32:$src1, addr:$src2)>;
4824
Chris Lattner589ad5d2010-03-25 05:44:01 +00004825// or reg/imm
4826def : Pat<(or GR8:$src1 , imm:$src2), (OR8ri GR8 :$src1, imm:$src2)>;
4827def : Pat<(or GR16:$src1, imm:$src2), (OR16ri GR16:$src1, imm:$src2)>;
4828def : Pat<(or GR32:$src1, imm:$src2), (OR32ri GR32:$src1, imm:$src2)>;
4829def : Pat<(or GR16:$src1, i16immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004830 (OR16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004831def : Pat<(or GR32:$src1, i32immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004832 (OR32ri8 GR32:$src1, i32immSExt8:$src2)>;
Dan Gohmane220c4b2009-09-18 19:59:53 +00004833
Chris Lattner589ad5d2010-03-25 05:44:01 +00004834// xor reg/reg
4835def : Pat<(xor GR8 :$src1, GR8 :$src2), (XOR8rr GR8 :$src1, GR8 :$src2)>;
4836def : Pat<(xor GR16:$src1, GR16:$src2), (XOR16rr GR16:$src1, GR16:$src2)>;
4837def : Pat<(xor GR32:$src1, GR32:$src2), (XOR32rr GR32:$src1, GR32:$src2)>;
Dan Gohmane220c4b2009-09-18 19:59:53 +00004838
Chris Lattner589ad5d2010-03-25 05:44:01 +00004839// xor reg/mem
4840def : Pat<(xor GR8:$src1, (loadi8 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004841 (XOR8rm GR8:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004842def : Pat<(xor GR16:$src1, (loadi16 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004843 (XOR16rm GR16:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004844def : Pat<(xor GR32:$src1, (loadi32 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004845 (XOR32rm GR32:$src1, addr:$src2)>;
4846
Chris Lattner589ad5d2010-03-25 05:44:01 +00004847// xor reg/imm
4848def : Pat<(xor GR8:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004849 (XOR8ri GR8:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004850def : Pat<(xor GR16:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004851 (XOR16ri GR16:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004852def : Pat<(xor GR32:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004853 (XOR32ri GR32:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004854def : Pat<(xor GR16:$src1, i16immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004855 (XOR16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004856def : Pat<(xor GR32:$src1, i32immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004857 (XOR32ri8 GR32:$src1, i32immSExt8:$src2)>;
4858
Chris Lattner589ad5d2010-03-25 05:44:01 +00004859// and reg/reg
4860def : Pat<(and GR8 :$src1, GR8 :$src2), (AND8rr GR8 :$src1, GR8 :$src2)>;
4861def : Pat<(and GR16:$src1, GR16:$src2), (AND16rr GR16:$src1, GR16:$src2)>;
4862def : Pat<(and GR32:$src1, GR32:$src2), (AND32rr GR32:$src1, GR32:$src2)>;
Dan Gohmane220c4b2009-09-18 19:59:53 +00004863
Chris Lattner589ad5d2010-03-25 05:44:01 +00004864// and reg/mem
4865def : Pat<(and GR8:$src1, (loadi8 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004866 (AND8rm GR8:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004867def : Pat<(and GR16:$src1, (loadi16 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004868 (AND16rm GR16:$src1, addr:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004869def : Pat<(and GR32:$src1, (loadi32 addr:$src2)),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004870 (AND32rm GR32:$src1, addr:$src2)>;
4871
Chris Lattner589ad5d2010-03-25 05:44:01 +00004872// and reg/imm
4873def : Pat<(and GR8:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004874 (AND8ri GR8:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004875def : Pat<(and GR16:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004876 (AND16ri GR16:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004877def : Pat<(and GR32:$src1, imm:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004878 (AND32ri GR32:$src1, imm:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004879def : Pat<(and GR16:$src1, i16immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004880 (AND16ri8 GR16:$src1, i16immSExt8:$src2)>;
Chris Lattner589ad5d2010-03-25 05:44:01 +00004881def : Pat<(and GR32:$src1, i32immSExt8:$src2),
Dan Gohmane220c4b2009-09-18 19:59:53 +00004882 (AND32ri8 GR32:$src1, i32immSExt8:$src2)>;
4883
Bill Wendlingd350e022008-12-12 21:15:41 +00004884//===----------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +00004885// Floating Point Stack Support
4886//===----------------------------------------------------------------------===//
4887
4888include "X86InstrFPStack.td"
4889
4890//===----------------------------------------------------------------------===//
Evan Chengc64a1a92007-07-31 08:04:03 +00004891// X86-64 Support
4892//===----------------------------------------------------------------------===//
4893
Chris Lattner36fe6d22008-01-10 05:50:42 +00004894include "X86Instr64bit.td"
Evan Chengc64a1a92007-07-31 08:04:03 +00004895
4896//===----------------------------------------------------------------------===//
David Greene51898d72010-02-09 23:52:19 +00004897// SIMD support (SSE, MMX and AVX)
4898//===----------------------------------------------------------------------===//
4899
4900include "X86InstrFragmentsSIMD.td"
4901
4902//===----------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +00004903// XMM Floating point support (requires SSE / SSE2)
4904//===----------------------------------------------------------------------===//
4905
4906include "X86InstrSSE.td"
Evan Cheng80f54042008-04-25 18:19:54 +00004907
4908//===----------------------------------------------------------------------===//
4909// MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
4910//===----------------------------------------------------------------------===//
4911
4912include "X86InstrMMX.td"