blob: 4ea3739629a9817a92d1615c217e51cee7ab2319 [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
Chris Lattner357a0ca2009-06-20 19:34:09 +000022
23// 64-bits but only 32 bits are significant, and those bits are treated as being
24// pc relative.
25def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27}
28
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// 64-bits but only 8 bits are significant.
Daniel Dunbaraa097b62009-08-10 21:06:41 +000031def i64i8imm : Operand<i64> {
32 let ParserMatchClass = ImmSExt8AsmOperand;
33}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034
35def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000036 let PrintMethod = "printlea64mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000037 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000038 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}
40
41def lea64_32mem : Operand<i32> {
42 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000043 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000044 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000045 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}
47
48//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000049// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050//
51def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Dan Gohman0c0d7412009-08-02 16:09:17 +000052 [add, sub, mul, X86mul_imm, shl, or, frameindex,
Chris Lattnerc04cd042009-07-11 23:17:29 +000053 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Chris Lattnerf1940742009-06-20 20:38:48 +000055def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
56 [tglobaltlsaddr], []>;
57
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000059// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060//
61
Dan Gohmand16fdc02008-12-19 18:25:21 +000062def i64immSExt8 : PatLeaf<(i64 imm), [{
63 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
64 // sign extended field.
65 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
66}]>;
67
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068def i64immSExt32 : PatLeaf<(i64 imm), [{
69 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
70 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000071 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072}]>;
73
74def i64immZExt32 : PatLeaf<(i64 imm), [{
75 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
76 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000077 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078}]>;
79
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
81def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
82def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
83
84def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
85def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
86def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
87def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
88
89def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
90def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
91def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
92def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
93
94//===----------------------------------------------------------------------===//
95// Instruction list...
96//
97
Dan Gohman01c9f772008-10-01 18:28:06 +000098// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
99// a stack adjustment and the codegen must know that they may modify the stack
100// pointer before prolog-epilog rewriting occurs.
101// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
102// sub / add which can clobber EFLAGS.
103let Defs = [RSP, EFLAGS], Uses = [RSP] in {
104def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
105 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000106 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000107 Requires<[In64BitMode]>;
108def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
109 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000110 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000111 Requires<[In64BitMode]>;
112}
113
Sean Callanan2c48df22009-12-18 00:01:26 +0000114// Interrupt Instructions
115def IRET64 : RI<0xcf, RawFrm, (outs), (ins), "iret{q}", []>;
116
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000117//===----------------------------------------------------------------------===//
118// Call Instructions...
119//
Evan Cheng37e7c752007-07-21 00:34:19 +0000120let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000121 // All calls clobber the non-callee saved registers. RSP is marked as
122 // a use to prevent stack-pointer assignments that appear immediately
123 // before calls from potentially appearing dead. Uses for argument
124 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000125 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000126 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
128 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000129 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
130 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000131
132 // NOTE: this pattern doesn't match "X86call imm", because we do not know
133 // that the offset between an arbitrary immediate and the call will fit in
134 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000135 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000136 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
Sean Callanan2c48df22009-12-18 00:01:26 +0000137 "call{q}\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000138 Requires<[In64BitMode, NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000139 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Sean Callanan2c48df22009-12-18 00:01:26 +0000140 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000141 Requires<[NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000142 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Sean Callanan2c48df22009-12-18 00:01:26 +0000143 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000144 Requires<[NotWin64]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000145
146 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
147 "lcall{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148 }
149
Sean Callanan2c48df22009-12-18 00:01:26 +0000150 // FIXME: We need to teach codegen about single list of call-clobbered
151 // registers.
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000152let isCall = 1 in
153 // All calls clobber the non-callee saved registers. RSP is marked as
154 // a use to prevent stack-pointer assignments that appear immediately
155 // before calls from potentially appearing dead. Uses for argument
156 // registers are added manually.
157 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
158 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
159 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
160 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
161 Uses = [RSP] in {
162 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000163 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
164 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000165 Requires<[IsWin64]>;
166 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
167 "call\t{*}$dst",
168 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000169 def WINCALL64m : I<0xFF, MRM2m, (outs),
170 (ins i64mem:$dst, variable_ops), "call\t{*}$dst",
171 [(X86call (loadi64 addr:$dst))]>,
172 Requires<[IsWin64]>;
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000173 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000174
175
176let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000177def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
178 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000179 "#TC_RETURN $dst $offset",
180 []>;
181
182let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000183def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
184 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000185 "#TC_RETURN $dst $offset",
186 []>;
187
188
189let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Cheng213b5be2010-01-31 07:28:44 +0000190 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst, variable_ops),
Evan Chengbd780d22009-02-10 21:39:44 +0000191 "jmp{q}\t{*}$dst # TAILCALL",
192 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000193
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000195let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000196 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
197 "jmp{q}\t$dst", []>;
Dan Gohman91888f02007-07-31 20:11:57 +0000198 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000200 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 [(brind (loadi64 addr:$dst))]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000202 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
203 "ljmp{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204}
205
206//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000207// EH Pseudo Instructions
208//
209let isTerminator = 1, isReturn = 1, isBarrier = 1,
Daniel Dunbarac4fab62010-01-22 20:16:37 +0000210 hasCtrlDep = 1, isCodeGenOnly = 1 in {
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000211def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
212 "ret\t#eh_return, addr: $addr",
213 [(X86ehret GR64:$addr)]>;
214
215}
216
217//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218// Miscellaneous Instructions...
219//
Sean Callanan2c48df22009-12-18 00:01:26 +0000220
221def POPCNT64rr : RI<0xB8, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
222 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
223def POPCNT64rm : RI<0xB8, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
224 "popcnt{q}\t{$src, $dst|$dst, $src}", []>, XS;
225
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000226let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000228 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000229let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000230let mayLoad = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000232 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000233def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
234def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
235}
236let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000238 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000239def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
240def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
241}
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000242}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243
Bill Wendling4c2638c2009-06-15 19:39:04 +0000244let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
245def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000246 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000247def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000248 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000249def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000250 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000251}
252
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000253let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +0000254def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf{q}", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000255let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +0000256def PUSHFQ64 : I<0x9C, RawFrm, (outs), (ins), "pushf{q}", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000257
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000259 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000260 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
262
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000263let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000264def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000265 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 [(set GR64:$dst, lea64addr:$src)]>;
267
268let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000269def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000270 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272
Evan Cheng48679f42007-12-14 02:13:44 +0000273// Bit scan instructions.
274let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000275def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000276 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000277 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000278def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000279 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000280 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
281 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000282
Evan Cheng4e33de92007-12-14 18:49:43 +0000283def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000284 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000285 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000286def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000287 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000288 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
289 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000290} // Defs = [EFLAGS]
291
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000293let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000294def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000295 [(X86rep_movs i64)]>, REP;
296let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000297def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000298 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299
Sean Callanan481f06d2009-09-12 00:37:19 +0000300def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scas{q}", []>;
301
Sean Callanan25220d62009-09-12 02:25:20 +0000302def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmps{q}", []>;
303
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000304// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000305def SYSEXIT64 : RI<0x35, RawFrm,
306 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000307
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308//===----------------------------------------------------------------------===//
309// Move Instructions...
310//
311
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000312let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000313def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000314 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315
Evan Chengd2b9d302008-06-25 01:16:38 +0000316let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000317def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000318 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000320def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000321 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000323}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324
Sean Callanan2c48df22009-12-18 00:01:26 +0000325def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
326 "mov{q}\t{$src, $dst|$dst, $src}", []>;
327
Evan Cheng3c1a4c52009-11-17 00:55:55 +0000328let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000329def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR64:$dst, (load addr:$src))]>;
332
Evan Chengb783fa32007-07-19 01:14:50 +0000333def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000334 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000336def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000337 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 [(store i64immSExt32:$src, addr:$dst)]>;
339
Sean Callanan2c48df22009-12-18 00:01:26 +0000340def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
Sean Callanan70953a52009-09-10 18:33:42 +0000341 "mov{q}\t{$src, %rax|%rax, $src}", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000342def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
Sean Callanan70953a52009-09-10 18:33:42 +0000343 "mov{q}\t{$src, %rax|%rax, $src}", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000344def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
Sean Callanan70953a52009-09-10 18:33:42 +0000345 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000346def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
Sean Callanan70953a52009-09-10 18:33:42 +0000347 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
348
Sean Callananad87a3a2009-09-15 18:47:29 +0000349// Moves to and from segment registers
350def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
Sean Callanan2c48df22009-12-18 00:01:26 +0000351 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Sean Callananad87a3a2009-09-15 18:47:29 +0000352def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
Sean Callanan2c48df22009-12-18 00:01:26 +0000353 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Sean Callananad87a3a2009-09-15 18:47:29 +0000354def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
Sean Callanan2c48df22009-12-18 00:01:26 +0000355 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Sean Callananad87a3a2009-09-15 18:47:29 +0000356def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
Sean Callanan2c48df22009-12-18 00:01:26 +0000357 "mov{q}\t{$src, $dst|$dst, $src}", []>;
358
359// Moves to and from debug registers
360def MOV64rd : I<0x21, MRMDestReg, (outs GR64:$dst), (ins DEBUG_REG:$src),
361 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
362def MOV64dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR64:$src),
363 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
364
365// Moves to and from control registers
366def MOV64rc : I<0x20, MRMDestReg, (outs GR64:$dst), (ins CONTROL_REG_64:$src),
367 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
368def MOV64cr : I<0x22, MRMSrcReg, (outs CONTROL_REG_64:$dst), (ins GR64:$src),
369 "mov{q}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callananad87a3a2009-09-15 18:47:29 +0000370
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000371// Sign/Zero extenders
372
Dan Gohmanedde1992009-04-13 15:13:28 +0000373// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
374// operand, which makes it a rare instruction with an 8-bit register
375// operand that can never access an h register. If support for h registers
376// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000377def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000378 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000380def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000381 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000383def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000384 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000386def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000387 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000389def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000390 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000392def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
395
Sean Callanan2c48df22009-12-18 00:01:26 +0000396// movzbq and movzwq encodings for the disassembler
397def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
398 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
399def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
400 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
401def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
402 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
403def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
404 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
405
Dan Gohman9203ab42008-07-30 18:09:17 +0000406// Use movzbl instead of movzbq when the destination is a register; it's
407// equivalent due to implicit zero-extending, and it has a smaller encoding.
408def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000409 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000410def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000411 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000412// Use movzwl instead of movzwq when the destination is a register; it's
413// equivalent due to implicit zero-extending, and it has a smaller encoding.
414def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000415 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000416def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000417 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418
Dan Gohman47a419d2008-08-07 02:54:50 +0000419// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000420// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
421// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
422// zero-extension, however this isn't possible when the 32-bit value is
423// defined by a truncate or is copied from something where the high bits aren't
424// necessarily all zero. In such cases, we fall back to these explicit zext
425// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000426def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000427 "", [(set GR64:$dst, (zext GR32:$src))]>;
Dan Gohman47a419d2008-08-07 02:54:50 +0000428def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000429 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
Dan Gohman47a419d2008-08-07 02:54:50 +0000430
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000431// Any instruction that defines a 32-bit result leaves the high half of the
Dan Gohman5d38ee42009-09-15 00:14:11 +0000432// register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
433// be copying from a truncate. And x86's cmov doesn't do anything if the
434// condition is false. But any other 32-bit operation will zero-extend
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000435// up to 64 bits.
436def def32 : PatLeaf<(i32 GR32:$src), [{
437 return N->getOpcode() != ISD::TRUNCATE &&
Chris Lattner4052b292010-02-09 19:54:29 +0000438 N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
Dan Gohman5d38ee42009-09-15 00:14:11 +0000439 N->getOpcode() != ISD::CopyFromReg &&
440 N->getOpcode() != X86ISD::CMOV;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000441}]>;
442
443// In the case of a 32-bit def that is known to implicitly zero-extend,
444// we can use a SUBREG_TO_REG.
445def : Pat<(i64 (zext def32:$src)),
446 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
447
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000448let neverHasSideEffects = 1 in {
449 let Defs = [RAX], Uses = [EAX] in
450 def CDQE : RI<0x98, RawFrm, (outs), (ins),
451 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000453 let Defs = [RAX,RDX], Uses = [RAX] in
454 def CQO : RI<0x99, RawFrm, (outs), (ins),
455 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
456}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457
458//===----------------------------------------------------------------------===//
459// Arithmetic Instructions...
460//
461
Evan Cheng55687072007-09-14 21:48:26 +0000462let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000463
464def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
465 "add{q}\t{$src, %rax|%rax, $src}", []>;
466
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467let isTwoAddress = 1 in {
468let isConvertibleToThreeAddress = 1 in {
469let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000470// Register-Register Addition
Sean Callanan2c48df22009-12-18 00:01:26 +0000471def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst),
472 (ins GR64:$src1, GR64:$src2),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000473 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000474 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000475 (implicit EFLAGS)]>;
476
477// Register-Integer Addition
Sean Callanan2c48df22009-12-18 00:01:26 +0000478def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst),
479 (ins GR64:$src1, i64i8imm:$src2),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000480 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000481 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
482 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000483def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst),
484 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000485 "add{q}\t{$src2, $dst|$dst, $src2}",
486 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
487 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488} // isConvertibleToThreeAddress
489
Bill Wendlingae034ed2008-12-12 00:56:36 +0000490// Register-Memory Addition
Sean Callanan2c48df22009-12-18 00:01:26 +0000491def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst),
492 (ins GR64:$src1, i64mem:$src2),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000493 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000494 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000495 (implicit EFLAGS)]>;
Sean Callanan7e7df0e2009-09-15 20:53:57 +0000496
Sean Callanan84df9312009-09-15 21:43:27 +0000497// Register-Register Addition - Equivalent to the normal rr form (ADD64rr), but
498// differently encoded.
Sean Callanan2c48df22009-12-18 00:01:26 +0000499def ADD64mrmrr : RI<0x03, MRMSrcReg, (outs GR64:$dst),
500 (ins GR64:$src1, GR64:$src2),
Sean Callanan7e7df0e2009-09-15 20:53:57 +0000501 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
502
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503} // isTwoAddress
504
Bill Wendlingae034ed2008-12-12 00:56:36 +0000505// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000506def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000507 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000508 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
509 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000510def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000511 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000512 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
513 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000514def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
515 "add{q}\t{$src2, $dst|$dst, $src2}",
516 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
517 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
Evan Cheng259471d2007-10-05 17:59:57 +0000519let Uses = [EFLAGS] in {
Sean Callanan8562bef2009-09-11 19:01:56 +0000520
521def ADC64i32 : RI<0x15, RawFrm, (outs), (ins i32imm:$src),
522 "adc{q}\t{$src, %rax|%rax, $src}", []>;
523
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524let isTwoAddress = 1 in {
525let isCommutable = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +0000526def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst),
527 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000528 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000529 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530
Sean Callanan2c48df22009-12-18 00:01:26 +0000531def ADC64rr_REV : RI<0x13, MRMSrcReg , (outs GR32:$dst),
532 (ins GR64:$src1, GR64:$src2),
533 "adc{q}\t{$src2, $dst|$dst, $src2}", []>;
534
535def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst),
536 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000537 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000538 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
Sean Callanan2c48df22009-12-18 00:01:26 +0000540def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst),
541 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000542 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000543 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000544def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst),
545 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000546 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000547 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548} // isTwoAddress
549
Evan Chengb783fa32007-07-19 01:14:50 +0000550def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000551 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000552 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000553def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000554 "adc{q}\t{$src2, $dst|$dst, $src2}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000555 [(store (adde (load addr:$dst), i64immSExt8:$src2),
556 addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000557def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
558 "adc{q}\t{$src2, $dst|$dst, $src2}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000559 [(store (adde (load addr:$dst), i64immSExt8:$src2),
560 addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000561} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562
563let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000564// Register-Register Subtraction
Sean Callanan2c48df22009-12-18 00:01:26 +0000565def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst),
566 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000567 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000568 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
569 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000570
Sean Callanan2c48df22009-12-18 00:01:26 +0000571def SUB64rr_REV : RI<0x2B, MRMSrcReg, (outs GR64:$dst),
572 (ins GR64:$src1, GR64:$src2),
573 "sub{q}\t{$src2, $dst|$dst, $src2}", []>;
574
Bill Wendlingae034ed2008-12-12 00:56:36 +0000575// Register-Memory Subtraction
Sean Callanan2c48df22009-12-18 00:01:26 +0000576def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst),
577 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000578 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000579 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
580 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000581
582// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000583def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
584 (ins GR64:$src1, i64i8imm:$src2),
585 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000586 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
587 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000588def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
589 (ins GR64:$src1, i64i32imm:$src2),
590 "sub{q}\t{$src2, $dst|$dst, $src2}",
591 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
592 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593} // isTwoAddress
594
Sean Callanan8562bef2009-09-11 19:01:56 +0000595def SUB64i32 : RI<0x2D, RawFrm, (outs), (ins i32imm:$src),
596 "sub{q}\t{$src, %rax|%rax, $src}", []>;
597
Bill Wendlingae034ed2008-12-12 00:56:36 +0000598// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000599def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000601 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
602 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000603
604// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000605def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000606 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000607 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000608 addr:$dst),
609 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000610def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
611 "sub{q}\t{$src2, $dst|$dst, $src2}",
612 [(store (sub (load addr:$dst), i64immSExt32:$src2),
613 addr:$dst),
614 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615
Evan Cheng259471d2007-10-05 17:59:57 +0000616let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617let isTwoAddress = 1 in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000618def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst),
619 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000620 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000621 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622
Sean Callanan2c48df22009-12-18 00:01:26 +0000623def SBB64rr_REV : RI<0x1B, MRMSrcReg, (outs GR64:$dst),
624 (ins GR64:$src1, GR64:$src2),
625 "sbb{q}\t{$src2, $dst|$dst, $src2}", []>;
626
627def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst),
628 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000629 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000630 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631
Sean Callanan2c48df22009-12-18 00:01:26 +0000632def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst),
633 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000634 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000635 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000636def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst),
637 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000638 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000639 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640} // isTwoAddress
641
Sean Callanan8562bef2009-09-11 19:01:56 +0000642def SBB64i32 : RI<0x1D, RawFrm, (outs), (ins i32imm:$src),
643 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
644
Evan Chengb783fa32007-07-19 01:14:50 +0000645def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000646 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000647 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000648def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000649 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000650 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000651def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
652 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000653 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000654} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000655} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656
657// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000658let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000659def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000660 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000661let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000662def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000663 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664
665// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000666def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000667 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000668let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000669def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000670 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
671}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672
Evan Cheng55687072007-09-14 21:48:26 +0000673let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674let isTwoAddress = 1 in {
675let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000676// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000677def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
678 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000680 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
681 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000682
Bill Wendlingf5399032008-12-12 21:15:41 +0000683// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000684def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
685 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000687 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
688 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689} // isTwoAddress
690
691// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000692
Bill Wendlingf5399032008-12-12 21:15:41 +0000693// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000695 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000697 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
698 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000699def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
700 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
701 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
702 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
703 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000704
Bill Wendlingf5399032008-12-12 21:15:41 +0000705// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000706def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000707 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000709 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000710 i64immSExt8:$src2)),
711 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000712def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
713 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
714 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
715 [(set GR64:$dst, (mul (load addr:$src1),
716 i64immSExt32:$src2)),
717 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000718} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000719
720// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000721let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000722// RDX:RAX/r64 = RAX,RDX
723def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000724 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725// Signed division / remainder
Sean Callanan2c48df22009-12-18 00:01:26 +0000726// RDX:RAX/r64 = RAX,RDX
727def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000728 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000729let mayLoad = 1 in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000730// RDX:RAX/[mem64] = RAX,RDX
731def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000732 "div{q}\t$src", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000733// RDX:RAX/[mem64] = RAX,RDX
734def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000735 "idiv{q}\t$src", []>;
736}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000737}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738
739// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000740let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000742def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000743 [(set GR64:$dst, (ineg GR64:$src)),
744 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000745def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000746 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
747 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748
749let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000750def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000751 [(set GR64:$dst, (add GR64:$src, 1)),
752 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000753def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000754 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
755 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756
757let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000758def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000759 [(set GR64:$dst, (add GR64:$src, -1)),
760 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000761def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000762 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
763 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764
765// In 64-bit mode, single byte INC and DEC cannot be encoded.
766let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
767// Can transform into LEA.
Sean Callanan2c48df22009-12-18 00:01:26 +0000768def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src),
769 "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000770 [(set GR16:$dst, (add GR16:$src, 1)),
771 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772 OpSize, Requires<[In64BitMode]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000773def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src),
774 "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000775 [(set GR32:$dst, (add GR32:$src, 1)),
776 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 Requires<[In64BitMode]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000778def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src),
779 "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000780 [(set GR16:$dst, (add GR16:$src, -1)),
781 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 OpSize, Requires<[In64BitMode]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000783def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src),
784 "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000785 [(set GR32:$dst, (add GR32:$src, -1)),
786 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000787 Requires<[In64BitMode]>;
788} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000789
790// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
791// how to unfold them.
792let isTwoAddress = 0, CodeSize = 2 in {
793 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000794 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
795 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000796 OpSize, Requires<[In64BitMode]>;
797 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000798 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
799 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000800 Requires<[In64BitMode]>;
801 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000802 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
803 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000804 OpSize, Requires<[In64BitMode]>;
805 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000806 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
807 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000808 Requires<[In64BitMode]>;
809}
Evan Cheng55687072007-09-14 21:48:26 +0000810} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811
812
Evan Cheng55687072007-09-14 21:48:26 +0000813let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814// Shift instructions
815let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000816let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000817def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000818 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000819 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000820let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Sean Callanan2c48df22009-12-18 00:01:26 +0000821def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst),
822 (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000823 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Sean Callananca503e02009-09-16 02:28:43 +0000825// NOTE: We don't include patterns for shifts of a register by one, because
826// 'add reg,reg' is cheaper.
827def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
Sean Callanan2c48df22009-12-18 00:01:26 +0000828 "shl{q}\t$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829} // isTwoAddress
830
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000831let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000832def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000833 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000834 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000835def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000836 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000838def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000839 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
841
842let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000843let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000844def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000845 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000846 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000847def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000848 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000850def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000851 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000852 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
853} // isTwoAddress
854
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000855let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000856def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000857 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000858 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000859def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000860 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000862def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000863 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
865
866let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000867let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000868def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000869 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000870 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000871def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst),
872 (ins GR64:$src1, i8imm:$src2),
873 "sar{q}\t{$src2, $dst|$dst, $src2}",
874 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000875def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000876 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
878} // isTwoAddress
879
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000880let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000881def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000882 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000883 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000884def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000887def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
890
891// Rotate instructions
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000892
893let isTwoAddress = 1 in {
894def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
895 "rcl{q}\t{1, $dst|$dst, 1}", []>;
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000896def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
897 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000898
899def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
900 "rcr{q}\t{1, $dst|$dst, 1}", []>;
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000901def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
902 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
Daniel Dunbara9dde432010-02-12 01:22:03 +0000903
904let Uses = [CL] in {
905def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
906 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
907def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
908 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
909}
910}
911
912let isTwoAddress = 0 in {
913def RCL64m1 : RI<0xD1, MRM2m, (outs), (ins i64mem:$dst),
914 "rcl{q}\t{1, $dst|$dst, 1}", []>;
915def RCL64mi : RIi8<0xC1, MRM2m, (outs), (ins i64mem:$dst, i8imm:$cnt),
916 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
917def RCR64m1 : RI<0xD1, MRM3m, (outs), (ins i64mem:$dst),
918 "rcr{q}\t{1, $dst|$dst, 1}", []>;
919def RCR64mi : RIi8<0xC1, MRM3m, (outs), (ins i64mem:$dst, i8imm:$cnt),
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000920 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
Daniel Dunbara9dde432010-02-12 01:22:03 +0000921
922let Uses = [CL] in {
923def RCL64mCL : RI<0xD3, MRM2m, (outs), (ins i64mem:$dst),
924 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
925def RCR64mCL : RI<0xD3, MRM3m, (outs), (ins i64mem:$dst),
926 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
927}
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000928}
929
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000931let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000932def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000933 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000934 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000935def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
936 (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000939def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
942} // isTwoAddress
943
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000944let Uses = [CL] in
Sean Callanan2c48df22009-12-18 00:01:26 +0000945def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
946 "rol{q}\t{%cl, $dst|$dst, %CL}",
947 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000948def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000950 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000951def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000952 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
954
955let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000956let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000957def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000958 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000959 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000960def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
961 (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000964def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
967} // isTwoAddress
968
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000969let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000970def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000972 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000973def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000976def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000977 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
979
980// Double shift instructions (generalizations of rotate)
981let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000982let Uses = [CL] in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000983def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
984 (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000985 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000986 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
987 TB;
988def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
989 (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000990 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000991 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
992 TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000993}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994
995let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
996def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Sean Callanan2c48df22009-12-18 00:01:26 +0000997 (outs GR64:$dst),
998 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000999 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1000 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
1001 (i8 imm:$src3)))]>,
1002 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Sean Callanan2c48df22009-12-18 00:01:26 +00001004 (outs GR64:$dst),
1005 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001006 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1007 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1008 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001009 TB;
1010} // isCommutable
1011} // isTwoAddress
1012
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001013let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001014def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001015 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1016 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1017 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +00001018def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001019 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1020 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1021 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001022}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001024 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001025 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1026 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1027 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028 TB;
1029def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001030 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001031 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1032 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1033 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034 TB;
Evan Cheng55687072007-09-14 21:48:26 +00001035} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036
1037//===----------------------------------------------------------------------===//
1038// Logical Instructions...
1039//
1040
Evan Cheng5b51c242009-01-21 19:45:31 +00001041let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +00001042def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +00001044def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1046
Evan Cheng55687072007-09-14 21:48:26 +00001047let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +00001048def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
1049 "and{q}\t{$src, %rax|%rax, $src}", []>;
1050
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051let isTwoAddress = 1 in {
1052let isCommutable = 1 in
1053def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001054 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001055 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001056 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
1057 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001058def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst),
1059 (ins GR64:$src1, GR64:$src2),
1060 "and{q}\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001062 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001064 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
1065 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +00001067 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001068 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001069 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
1070 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001071def AND64ri32 : RIi32<0x81, MRM4r,
1072 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1073 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001074 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
1075 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076} // isTwoAddress
1077
1078def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001079 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001080 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001081 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1082 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +00001084 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001085 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001086 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1087 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001088def AND64mi32 : RIi32<0x81, MRM4m,
1089 (outs), (ins i64mem:$dst, i64i32imm:$src),
1090 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001091 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1092 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093
1094let isTwoAddress = 1 in {
1095let isCommutable = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +00001096def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst),
1097 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001099 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001100 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001101def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst),
1102 (ins GR64:$src1, GR64:$src2),
1103 "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1104def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1105 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001106 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001107 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
1108 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001109def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst),
1110 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001111 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001112 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
Evan Cheng4621d272010-01-11 17:03:47 +00001113 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001114def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1115 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001116 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001117 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
Evan Cheng4621d272010-01-11 17:03:47 +00001118 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119} // isTwoAddress
1120
Evan Chengb783fa32007-07-19 01:14:50 +00001121def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001122 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001123 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1124 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001125def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001127 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1128 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001129def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1130 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001131 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1132 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133
Sean Callanan8562bef2009-09-11 19:01:56 +00001134def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
1135 "or{q}\t{$src, %rax|%rax, $src}", []>;
1136
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001137let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +00001138let isCommutable = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +00001139def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst),
1140 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001141 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001142 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
1143 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001144def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst),
1145 (ins GR64:$src1, GR64:$src2),
1146 "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1147def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst),
1148 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001149 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001150 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
1151 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001152def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst),
1153 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001154 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001155 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1156 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001157def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +00001158 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001159 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001160 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1161 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001162} // isTwoAddress
1163
Evan Chengb783fa32007-07-19 01:14:50 +00001164def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001165 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001166 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1167 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001168def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001169 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001170 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1171 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001172def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1173 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001174 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1175 (implicit EFLAGS)]>;
Sean Callanan794457a2009-09-10 19:52:26 +00001176
1177def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1178 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1179
Evan Cheng55687072007-09-14 21:48:26 +00001180} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181
1182//===----------------------------------------------------------------------===//
1183// Comparison Instructions...
1184//
1185
1186// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001187let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001188def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1189 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001191def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001192 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001193 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1194 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001195def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001196 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001197 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1198 (implicit EFLAGS)]>;
1199def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1200 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001202 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1203 (implicit EFLAGS)]>;
1204def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1205 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001206 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001207 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1208 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209
Sean Callanan251676e2009-09-02 00:55:49 +00001210
1211def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1212 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001213def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001214 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001215 [(X86cmp GR64:$src1, GR64:$src2),
1216 (implicit EFLAGS)]>;
Sean Callanan11490dc2009-09-16 21:11:23 +00001217def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1218 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001219def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001220 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001221 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1222 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001223def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001224 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001225 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1226 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001227def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1228 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1229 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1230 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001231def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001232 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001233 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001234 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001235def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001236 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001237 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001238 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001239def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1240 (ins i64mem:$src1, i64i32imm:$src2),
1241 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1242 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1243 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001244} // Defs = [EFLAGS]
1245
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001246// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001247// TODO: BTC, BTR, and BTS
1248let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001249def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001250 "bt{q}\t{$src2, $src1|$src1, $src2}",
1251 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001252 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001253
1254// Unlike with the register+register form, the memory+register form of the
1255// bt instruction does not ignore the high bits of the index. From ISel's
1256// perspective, this is pretty bizarre. Disable these instructions for now.
Sean Callanan2c48df22009-12-18 00:01:26 +00001257def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1258 "bt{q}\t{$src2, $src1|$src1, $src2}",
Dan Gohman85a228c2009-01-13 23:23:30 +00001259// [(X86bt (loadi64 addr:$src1), GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001260// (implicit EFLAGS)]
1261 []
1262 >, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001263
1264def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1265 "bt{q}\t{$src2, $src1|$src1, $src2}",
1266 [(X86bt GR64:$src1, i64immSExt8:$src2),
1267 (implicit EFLAGS)]>, TB;
1268// Note that these instructions don't need FastBTMem because that
1269// only applies when the other operand is in a register. When it's
1270// an immediate, bt is still fast.
1271def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1272 "bt{q}\t{$src2, $src1|$src1, $src2}",
1273 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1274 (implicit EFLAGS)]>, TB;
Sean Callanan2c48df22009-12-18 00:01:26 +00001275
1276def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1277 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1278def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1279 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1280def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1281 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1282def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1283 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1284
1285def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1286 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1287def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1288 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1289def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1290 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1291def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1292 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1293
1294def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1295 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1296def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1297 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1298def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1299 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1300def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1301 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001302} // Defs = [EFLAGS]
1303
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001304// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001305let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001306let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001307def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001308 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001309 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001311 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001313 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001314 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001315 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001316 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001318 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001319 "cmove{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001321 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001323 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001324 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001326 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001327def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001328 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001329 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001330 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001331 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001332def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001333 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001334 "cmova{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001335 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001336 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001338 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001339 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001340 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001341 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001343 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001344 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001345 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001346 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001347def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001348 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001349 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001350 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001351 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001352def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001353 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001354 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001355 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001356 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001357def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001358 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001359 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001360 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001361 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001362def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001363 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001364 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001365 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001366 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001368 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001369 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001370 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001371 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001372def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001373 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001374 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001375 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001376 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001377def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1378 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001379 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001380 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1381 X86_COND_O, EFLAGS))]>, TB;
1382def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1383 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001384 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001385 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1386 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001387} // isCommutable = 1
1388
1389def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1390 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001391 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001392 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1393 X86_COND_B, EFLAGS))]>, TB;
1394def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1395 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001396 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001397 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1398 X86_COND_AE, EFLAGS))]>, TB;
1399def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1400 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001401 "cmove{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001402 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1403 X86_COND_E, EFLAGS))]>, TB;
1404def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1405 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001406 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001407 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1408 X86_COND_NE, EFLAGS))]>, TB;
1409def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1410 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001411 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001412 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1413 X86_COND_BE, EFLAGS))]>, TB;
1414def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1415 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001416 "cmova{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001417 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1418 X86_COND_A, EFLAGS))]>, TB;
1419def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1420 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001421 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001422 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1423 X86_COND_L, EFLAGS))]>, TB;
1424def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1425 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001426 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001427 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1428 X86_COND_GE, EFLAGS))]>, TB;
1429def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1430 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001431 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001432 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1433 X86_COND_LE, EFLAGS))]>, TB;
1434def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1435 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001436 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001437 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1438 X86_COND_G, EFLAGS))]>, TB;
1439def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1440 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001441 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001442 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1443 X86_COND_S, EFLAGS))]>, TB;
1444def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1445 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001446 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001447 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1448 X86_COND_NS, EFLAGS))]>, TB;
1449def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1450 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001451 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001452 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1453 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001455 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001456 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001457 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001458 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001459def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1460 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001461 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001462 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1463 X86_COND_O, EFLAGS))]>, TB;
1464def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1465 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001466 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001467 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1468 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001469} // isTwoAddress
1470
Evan Cheng834ae6b2009-12-15 00:53:42 +00001471// Use sbb to materialize carry flag into a GPR.
Chris Lattnerb67327b2010-02-05 21:13:48 +00001472// FIXME: This are pseudo ops that should be replaced with Pat<> patterns.
1473// However, Pat<> can't replicate the destination reg into the inputs of the
1474// result.
1475// FIXME: Change this to have encoding Pseudo when X86MCCodeEmitter replaces
1476// X86CodeEmitter.
Evan Cheng834ae6b2009-12-15 00:53:42 +00001477let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
Chris Lattnerb67327b2010-02-05 21:13:48 +00001478def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins), "",
Evan Chengedeb1692009-12-16 00:53:11 +00001479 [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
Evan Cheng834ae6b2009-12-15 00:53:42 +00001480
Evan Chengedeb1692009-12-16 00:53:11 +00001481def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
Evan Cheng834ae6b2009-12-15 00:53:42 +00001482 (SETB_C64r)>;
1483
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484//===----------------------------------------------------------------------===//
1485// Conversion Instructions...
1486//
1487
1488// f64 -> signed i64
Sean Callanan2c48df22009-12-18 00:01:26 +00001489def CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1490 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1491def CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1492 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001493def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001494 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001495 [(set GR64:$dst,
1496 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001497def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst),
1498 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001499 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001500 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1501 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001502def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001503 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001504 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001505def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001506 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001507 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001508def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001509 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001510 [(set GR64:$dst,
1511 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001512def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst),
1513 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001514 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001515 [(set GR64:$dst,
1516 (int_x86_sse2_cvttsd2si64
1517 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518
1519// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001520def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001521 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001523def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001524 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001525 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001526
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527let isTwoAddress = 1 in {
1528def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001529 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001530 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001531 [(set VR128:$dst,
1532 (int_x86_sse2_cvtsi642sd VR128:$src1,
1533 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001534def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001535 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001536 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001537 [(set VR128:$dst,
1538 (int_x86_sse2_cvtsi642sd VR128:$src1,
1539 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001540} // isTwoAddress
1541
1542// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001543def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001544 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001545 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001546def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001547 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001548 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001549
1550let isTwoAddress = 1 in {
1551 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1552 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1553 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1554 [(set VR128:$dst,
1555 (int_x86_sse_cvtsi642ss VR128:$src1,
1556 GR64:$src2))]>;
1557 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
Sean Callanan2c48df22009-12-18 00:01:26 +00001558 (outs VR128:$dst),
1559 (ins VR128:$src1, i64mem:$src2),
Evan Cheng1d5832e2008-01-11 07:37:44 +00001560 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1561 [(set VR128:$dst,
1562 (int_x86_sse_cvtsi642ss VR128:$src1,
1563 (loadi64 addr:$src2)))]>;
1564}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001565
1566// f32 -> signed i64
Sean Callanan2c48df22009-12-18 00:01:26 +00001567def CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1568 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1569def CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1570 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001571def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001572 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001573 [(set GR64:$dst,
1574 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001575def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001576 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001577 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1578 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001579def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001580 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001581 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001582def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001583 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001584 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001585def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001586 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001587 [(set GR64:$dst,
1588 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001589def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst),
1590 (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001591 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001592 [(set GR64:$dst,
1593 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001594
1595// Descriptor-table support instructions
1596
1597// LLDT is not interpreted specially in 64-bit mode because there is no sign
1598// extension.
1599def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1600 "sldt{q}\t$dst", []>, TB;
1601def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1602 "sldt{q}\t$dst", []>, TB;
Bill Wendling6227d462007-07-23 03:07:27 +00001603
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001604//===----------------------------------------------------------------------===//
1605// Alias Instructions
1606//===----------------------------------------------------------------------===//
1607
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001608// We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1609// smaller encoding, but doing so at isel time interferes with rematerialization
1610// in the current register allocator. For now, this is rewritten when the
1611// instruction is lowered to an MCInst.
Chris Lattner17f62252009-07-14 20:19:57 +00001612// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001613// when we have a better way to specify isel priority.
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001614let Defs = [EFLAGS],
1615 AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Chris Lattner8042d5d2010-02-05 21:34:18 +00001616def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins), "",
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001617 [(set GR64:$dst, 0)]>;
Chris Lattner17f62252009-07-14 20:19:57 +00001618
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001619// Materialize i64 constant where top 32-bits are zero. This could theoretically
1620// use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1621// that would make it more difficult to rematerialize.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001622let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001623def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +00001624 "", [(set GR64:$dst, i64immZExt32:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001625
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001626//===----------------------------------------------------------------------===//
1627// Thread Local Storage Instructions
1628//===----------------------------------------------------------------------===//
1629
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001630// All calls clobber the non-callee saved registers. RSP is marked as
1631// a use to prevent stack-pointer assignments that appear immediately
1632// before calls from potentially appearing dead.
1633let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1634 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1635 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1636 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1637 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1638 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001639def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001640 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001641 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001642 ".word\t0x6666; "
1643 "rex64; "
1644 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001645 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001646 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001647
Daniel Dunbar75a07302009-08-11 22:24:40 +00001648let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001649def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1650 "movq\t%gs:$src, $dst",
1651 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1652
Daniel Dunbar75a07302009-08-11 22:24:40 +00001653let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001654def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1655 "movq\t%fs:$src, $dst",
1656 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1657
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001658//===----------------------------------------------------------------------===//
1659// Atomic Instructions
1660//===----------------------------------------------------------------------===//
1661
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001662let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001663def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001664 "lock\n\t"
1665 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001666 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1667}
1668
Dan Gohmana41a1c092008-08-06 15:52:50 +00001669let Constraints = "$val = $dst" in {
1670let Defs = [EFLAGS] in
Sean Callanan2c48df22009-12-18 00:01:26 +00001671def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
Dan Gohman70a8a112009-04-27 15:13:28 +00001672 "lock\n\t"
1673 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001674 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001675 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001676
Sean Callanan2c48df22009-12-18 00:01:26 +00001677def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),
1678 (ins GR64:$val,i64mem:$ptr),
1679 "xchg{q}\t{$val, $ptr|$ptr, $val}",
Evan Chenga1e80602008-04-19 02:05:42 +00001680 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001681
1682def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1683 "xchg{q}\t{$val, $src|$src, $val}", []>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001684}
1685
Sean Callanan2c48df22009-12-18 00:01:26 +00001686def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1687 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1688def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1689 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1690
1691def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1692 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1693def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1694 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1695
Evan Cheng3896a6f2010-01-08 01:29:19 +00001696let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
Sean Callanan2c48df22009-12-18 00:01:26 +00001697def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1698 "cmpxchg16b\t$dst", []>, TB;
1699
1700def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1701 "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1702
Evan Chengb723fb52009-07-30 08:33:02 +00001703// Optimized codegen when the non-memory output is not used.
Edwin Törökce819f12009-10-19 11:00:58 +00001704let Defs = [EFLAGS] in {
Evan Chengb723fb52009-07-30 08:33:02 +00001705// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1706def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1707 "lock\n\t"
1708 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1709def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1710 (ins i64mem:$dst, i64i8imm :$src2),
1711 "lock\n\t"
1712 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1713def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1714 (ins i64mem:$dst, i64i32imm :$src2),
1715 "lock\n\t"
1716 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1717def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1718 "lock\n\t"
1719 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1720def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1721 (ins i64mem:$dst, i64i8imm :$src2),
1722 "lock\n\t"
1723 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1724def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1725 (ins i64mem:$dst, i64i32imm:$src2),
1726 "lock\n\t"
1727 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1728def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1729 "lock\n\t"
1730 "inc{q}\t$dst", []>, LOCK;
1731def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1732 "lock\n\t"
1733 "dec{q}\t$dst", []>, LOCK;
Edwin Törökce819f12009-10-19 11:00:58 +00001734}
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001735// Atomic exchange, and, or, xor
1736let Constraints = "$val = $dst", Defs = [EFLAGS],
Dan Gohman30afe012009-10-29 18:10:34 +00001737 usesCustomInserter = 1 in {
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001738def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001739 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001740 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001741def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001742 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001743 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001744def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001745 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001746 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001747def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001748 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001749 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001750def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001751 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001752 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001753def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001754 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001755 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001756def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001757 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001758 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001759def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001760 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001761 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001762}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001763
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001764// Segmentation support instructions
1765
1766// i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1767def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1768 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1769def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1770 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callanan23f33d72009-09-16 22:59:28 +00001771
Sean Callanan2c48df22009-12-18 00:01:26 +00001772def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1773 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1774def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1775 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1776
Chris Lattner26e5c7a2010-02-13 00:41:14 +00001777def SWAPGS : I<0x01, MRM_F8, (outs), (ins), "swapgs", []>, TB;
Sean Callanan2c48df22009-12-18 00:01:26 +00001778
1779def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
1780 "push{q}\t%fs", []>, TB;
1781def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
1782 "push{q}\t%gs", []>, TB;
1783
1784def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
1785 "pop{q}\t%fs", []>, TB;
1786def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
1787 "pop{q}\t%gs", []>, TB;
1788
1789def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1790 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
1791def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1792 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1793def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1794 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1795
1796// Specialized register support
1797
1798// no m form encodable; use SMSW16m
1799def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
1800 "smsw{q}\t$dst", []>, TB;
1801
Sean Callanan23f33d72009-09-16 22:59:28 +00001802// String manipulation instructions
1803
1804def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001805
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001806//===----------------------------------------------------------------------===//
1807// Non-Instruction Patterns
1808//===----------------------------------------------------------------------===//
1809
Chris Lattner0d2dad62009-07-11 22:50:33 +00001810// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1811// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1812// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001813def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001814 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001815def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001816 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001817def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001818 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001819def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001820 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001821def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1822 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001823
Chris Lattnerc04cd042009-07-11 23:17:29 +00001824// In static codegen with small code model, we can get the address of a label
1825// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1826// the MOV64ri64i32 should accept these.
1827def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1828 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1829def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1830 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1831def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1832 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1833def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1834 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001835def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1836 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001837
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001838// In kernel code model, we can get the address of a label
1839// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1840// the MOV64ri32 should accept these.
1841def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1842 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1843def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1844 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1845def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1846 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1847def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1848 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001849def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1850 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001851
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001852// If we have small model and -static mode, it is safe to store global addresses
1853// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001854// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001855def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1856 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001857 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001858def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1859 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001860 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001861def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1862 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001863 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1865 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001866 Requires<[NearData, IsStatic]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001867def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1868 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1869 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001870
1871// Calls
1872// Direct PC relative function call for small code model. 32-bit displacement
1873// sign extended to 64-bit.
1874def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001875 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001876def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001877 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1878
1879def : Pat<(X86call (i64 tglobaladdr:$dst)),
1880 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1881def : Pat<(X86call (i64 texternalsym:$dst)),
1882 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001883
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001884// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001885def : Pat<(X86tcret GR64:$dst, imm:$off),
1886 (TCRETURNri64 GR64:$dst, imm:$off)>;
1887
1888def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
Dan Gohman66fe2bc2009-11-30 23:33:37 +00001889 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001890
1891def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1892 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1893
Dan Gohmanec596042007-09-17 14:35:24 +00001894// Comparisons.
1895
1896// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001897def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001898 (TEST64rr GR64:$src1, GR64:$src1)>;
1899
Dan Gohman0a3c5222009-01-07 01:00:24 +00001900// Conditional moves with folded loads with operands swapped and conditions
1901// inverted.
1902def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1903 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1904def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1905 (CMOVB64rm GR64:$src2, addr:$src1)>;
1906def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1907 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1908def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1909 (CMOVE64rm GR64:$src2, addr:$src1)>;
1910def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1911 (CMOVA64rm GR64:$src2, addr:$src1)>;
1912def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1913 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1914def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1915 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1916def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1917 (CMOVL64rm GR64:$src2, addr:$src1)>;
1918def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1919 (CMOVG64rm GR64:$src2, addr:$src1)>;
1920def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1921 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1922def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1923 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1924def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1925 (CMOVP64rm GR64:$src2, addr:$src1)>;
1926def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1927 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1928def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1929 (CMOVS64rm GR64:$src2, addr:$src1)>;
1930def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1931 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1932def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1933 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001934
Duncan Sands082524c2008-01-23 20:39:46 +00001935// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001936def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1937
1938// extload
Sean Callanan2c48df22009-12-18 00:01:26 +00001939// When extloading from 16-bit and smaller memory locations into 64-bit
1940// registers, use zero-extending loads so that the entire 64-bit register is
1941// defined, avoiding partial-register updates.
Dan Gohmanab460da2008-08-27 17:33:15 +00001942def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1943def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1944def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1945// For other extloads, use subregs, since the high contents of the register are
1946// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001947def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001948 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001949 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001950
Dan Gohman9959b052009-08-26 14:59:13 +00001951// anyext. Define these to do an explicit zero-extend to
1952// avoid partial-register updates.
1953def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1954def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1955def : Pat<(i64 (anyext GR32:$src)),
1956 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001957
1958//===----------------------------------------------------------------------===//
1959// Some peepholes
1960//===----------------------------------------------------------------------===//
1961
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001962// Odd encoding trick: -128 fits into an 8-bit immediate field while
1963// +128 doesn't, so in this special case use a sub instead of an add.
1964def : Pat<(add GR64:$src1, 128),
1965 (SUB64ri8 GR64:$src1, -128)>;
1966def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1967 (SUB64mi8 addr:$dst, -128)>;
1968
1969// The same trick applies for 32-bit immediate fields in 64-bit
1970// instructions.
1971def : Pat<(add GR64:$src1, 0x0000000080000000),
1972 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1973def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1974 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1975
Dan Gohman072641f2010-01-11 17:58:34 +00001976// Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
1977// has an immediate with at least 32 bits of leading zeros, to avoid needing to
1978// materialize that immediate in a register first.
1979def : Pat<(and GR64:$src, i64immZExt32:$imm),
1980 (SUBREG_TO_REG
1981 (i64 0),
1982 (AND32ri
1983 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit),
1984 imm:$imm),
1985 x86_subreg_32bit)>;
1986
Dan Gohman47a419d2008-08-07 02:54:50 +00001987// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001988def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001989 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001990// r & (2^16-1) ==> movz
1991def : Pat<(and GR64:$src, 0xffff),
1992 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1993// r & (2^8-1) ==> movz
1994def : Pat<(and GR64:$src, 0xff),
1995 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001996// r & (2^8-1) ==> movz
1997def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001998 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001999 Requires<[In64BitMode]>;
2000// r & (2^8-1) ==> movz
2001def : Pat<(and GR16:$src1, 0xff),
2002 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
2003 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00002004
Dan Gohmandd612bb2008-08-20 21:27:32 +00002005// sext_inreg patterns
2006def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00002007 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002008def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00002009 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002010def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00002011 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002012def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00002013 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002014 Requires<[In64BitMode]>;
2015def : Pat<(sext_inreg GR16:$src, i8),
2016 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
2017 Requires<[In64BitMode]>;
2018
2019// trunc patterns
2020def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002021 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002022def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002023 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002024def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002025 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002026def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002027 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002028 Requires<[In64BitMode]>;
2029def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002030 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
2031 Requires<[In64BitMode]>;
2032
2033// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00002034// For now, be conservative on x86-64 and use an h-register extract only if the
2035// value is immediately zero-extended or stored, which are somewhat common
2036// cases. This uses a bunch of code to prevent a register requiring a REX prefix
2037// from being allocated in the same instruction as the h register, as there's
2038// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00002039
2040// h-register extract and zero-extend.
2041def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
2042 (SUBREG_TO_REG
2043 (i64 0),
2044 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002045 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002046 x86_subreg_8bit_hi)),
2047 x86_subreg_32bit)>;
2048def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2049 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002050 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002051 x86_subreg_8bit_hi))>,
2052 Requires<[In64BitMode]>;
Dan Gohman5d8f9df2010-01-11 17:21:05 +00002053def : Pat<(srl GR16:$src, (i8 8)),
Dan Gohman744d4622009-04-13 16:09:41 +00002054 (EXTRACT_SUBREG
2055 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002056 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002057 x86_subreg_8bit_hi)),
2058 x86_subreg_16bit)>,
2059 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00002060def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2061 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002062 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00002063 x86_subreg_8bit_hi))>,
2064 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00002065def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2066 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002067 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00002068 x86_subreg_8bit_hi))>,
2069 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00002070def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2071 (SUBREG_TO_REG
2072 (i64 0),
2073 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002074 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00002075 x86_subreg_8bit_hi)),
2076 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00002077def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2078 (SUBREG_TO_REG
2079 (i64 0),
2080 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002081 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00002082 x86_subreg_8bit_hi)),
2083 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00002084
2085// h-register extract and store.
2086def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2087 (MOV8mr_NOREX
2088 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002089 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002090 x86_subreg_8bit_hi))>;
2091def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2092 (MOV8mr_NOREX
2093 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002094 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002095 x86_subreg_8bit_hi))>,
2096 Requires<[In64BitMode]>;
2097def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2098 (MOV8mr_NOREX
2099 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002100 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002101 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002102 Requires<[In64BitMode]>;
2103
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002104// (shl x, 1) ==> (add x, x)
2105def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2106
Evan Cheng76a64c72008-08-30 02:03:58 +00002107// (shl x (and y, 63)) ==> (shl x, y)
2108def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
2109 (SHL64rCL GR64:$src1)>;
2110def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2111 (SHL64mCL addr:$dst)>;
2112
2113def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
2114 (SHR64rCL GR64:$src1)>;
2115def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2116 (SHR64mCL addr:$dst)>;
2117
2118def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
2119 (SAR64rCL GR64:$src1)>;
2120def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2121 (SAR64mCL addr:$dst)>;
2122
Evan Cheng10957b82010-01-04 21:22:48 +00002123// Double shift patterns
Dan Gohman921581d2008-10-17 01:23:35 +00002124def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
2125 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
2126
2127def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
2128 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
2129 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
2130
Dan Gohman921581d2008-10-17 01:23:35 +00002131def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
2132 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
2133
2134def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
2135 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
2136 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
2137
Evan Cheng503d9c52010-01-11 22:03:29 +00002138// (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
Evan Cheng44a441c2010-01-12 18:31:19 +00002139let AddedComplexity = 5 in { // Try this before the selecting to OR
Evan Cheng4621d272010-01-11 17:03:47 +00002140def : Pat<(parallel (or_is_add GR64:$src1, i64immSExt8:$src2),
2141 (implicit EFLAGS)),
2142 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2143def : Pat<(parallel (or_is_add GR64:$src1, i64immSExt32:$src2),
2144 (implicit EFLAGS)),
2145 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Evan Cheng503d9c52010-01-11 22:03:29 +00002146def : Pat<(parallel (or_is_add GR64:$src1, GR64:$src2),
2147 (implicit EFLAGS)),
2148 (ADD64rr GR64:$src1, GR64:$src2)>;
Evan Cheng44a441c2010-01-12 18:31:19 +00002149} // AddedComplexity
Evan Cheng4621d272010-01-11 17:03:47 +00002150
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002151// X86 specific add which produces a flag.
2152def : Pat<(addc GR64:$src1, GR64:$src2),
2153 (ADD64rr GR64:$src1, GR64:$src2)>;
2154def : Pat<(addc GR64:$src1, (load addr:$src2)),
2155 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002156def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2157 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00002158def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2159 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002160
2161def : Pat<(subc GR64:$src1, GR64:$src2),
2162 (SUB64rr GR64:$src1, GR64:$src2)>;
2163def : Pat<(subc GR64:$src1, (load addr:$src2)),
2164 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002165def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2166 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00002167def : Pat<(subc GR64:$src1, imm:$src2),
2168 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002169
Bill Wendlingf5399032008-12-12 21:15:41 +00002170//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00002171// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00002172//===----------------------------------------------------------------------===//
2173
Dan Gohman99a12192009-03-04 19:44:21 +00002174// Register-Register Addition with EFLAGS result
2175def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002176 (implicit EFLAGS)),
2177 (ADD64rr GR64:$src1, GR64:$src2)>;
2178
Dan Gohman99a12192009-03-04 19:44:21 +00002179// Register-Integer Addition with EFLAGS result
2180def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002181 (implicit EFLAGS)),
2182 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002183def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002184 (implicit EFLAGS)),
2185 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002186
Dan Gohman99a12192009-03-04 19:44:21 +00002187// Register-Memory Addition with EFLAGS result
2188def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002189 (implicit EFLAGS)),
2190 (ADD64rm GR64:$src1, addr:$src2)>;
2191
Dan Gohman99a12192009-03-04 19:44:21 +00002192// Memory-Register Addition with EFLAGS result
2193def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002194 addr:$dst),
2195 (implicit EFLAGS)),
2196 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002197def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002198 addr:$dst),
2199 (implicit EFLAGS)),
2200 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002201def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst),
2202 i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002203 addr:$dst),
2204 (implicit EFLAGS)),
2205 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002206
Dan Gohman99a12192009-03-04 19:44:21 +00002207// Register-Register Subtraction with EFLAGS result
2208def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002209 (implicit EFLAGS)),
2210 (SUB64rr GR64:$src1, GR64:$src2)>;
2211
Dan Gohman99a12192009-03-04 19:44:21 +00002212// Register-Memory Subtraction with EFLAGS result
2213def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002214 (implicit EFLAGS)),
2215 (SUB64rm GR64:$src1, addr:$src2)>;
2216
Dan Gohman99a12192009-03-04 19:44:21 +00002217// Register-Integer Subtraction with EFLAGS result
2218def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002219 (implicit EFLAGS)),
2220 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002221def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002222 (implicit EFLAGS)),
2223 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002224
Dan Gohman99a12192009-03-04 19:44:21 +00002225// Memory-Register Subtraction with EFLAGS result
2226def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002227 addr:$dst),
2228 (implicit EFLAGS)),
2229 (SUB64mr addr:$dst, GR64:$src2)>;
2230
Dan Gohman99a12192009-03-04 19:44:21 +00002231// Memory-Integer Subtraction with EFLAGS result
Sean Callanan2c48df22009-12-18 00:01:26 +00002232def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst),
2233 i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002234 addr:$dst),
2235 (implicit EFLAGS)),
2236 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002237def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst),
2238 i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002239 addr:$dst),
2240 (implicit EFLAGS)),
2241 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002242
Dan Gohman99a12192009-03-04 19:44:21 +00002243// Register-Register Signed Integer Multiplication with EFLAGS result
2244def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002245 (implicit EFLAGS)),
2246 (IMUL64rr GR64:$src1, GR64:$src2)>;
2247
Dan Gohman99a12192009-03-04 19:44:21 +00002248// Register-Memory Signed Integer Multiplication with EFLAGS result
2249def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002250 (implicit EFLAGS)),
2251 (IMUL64rm GR64:$src1, addr:$src2)>;
2252
Dan Gohman99a12192009-03-04 19:44:21 +00002253// Register-Integer Signed Integer Multiplication with EFLAGS result
2254def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002255 (implicit EFLAGS)),
2256 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002257def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002258 (implicit EFLAGS)),
2259 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002260
Dan Gohman99a12192009-03-04 19:44:21 +00002261// Memory-Integer Signed Integer Multiplication with EFLAGS result
2262def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002263 (implicit EFLAGS)),
2264 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002265def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002266 (implicit EFLAGS)),
2267 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002268
Dan Gohman99a12192009-03-04 19:44:21 +00002269// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00002270def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
2271 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2272def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
2273 (implicit EFLAGS)),
2274 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2275def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
2276 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2277def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
2278 (implicit EFLAGS)),
2279 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2280
2281def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
2282 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2283def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
2284 (implicit EFLAGS)),
2285 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2286def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
2287 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2288def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2289 (implicit EFLAGS)),
2290 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2291
Dan Gohman99a12192009-03-04 19:44:21 +00002292def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2293 (INC64r GR64:$src)>;
2294def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2295 (implicit EFLAGS)),
2296 (INC64m addr:$dst)>;
2297def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2298 (DEC64r GR64:$src)>;
2299def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2300 (implicit EFLAGS)),
2301 (DEC64m addr:$dst)>;
2302
Dan Gohman12e03292009-09-18 19:59:53 +00002303// Register-Register Logical Or with EFLAGS result
2304def : Pat<(parallel (X86or_flag GR64:$src1, GR64:$src2),
2305 (implicit EFLAGS)),
2306 (OR64rr GR64:$src1, GR64:$src2)>;
2307
2308// Register-Integer Logical Or with EFLAGS result
2309def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt8:$src2),
2310 (implicit EFLAGS)),
2311 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2312def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt32:$src2),
2313 (implicit EFLAGS)),
2314 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2315
2316// Register-Memory Logical Or with EFLAGS result
2317def : Pat<(parallel (X86or_flag GR64:$src1, (loadi64 addr:$src2)),
2318 (implicit EFLAGS)),
2319 (OR64rm GR64:$src1, addr:$src2)>;
2320
2321// Memory-Register Logical Or with EFLAGS result
2322def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), GR64:$src2),
2323 addr:$dst),
2324 (implicit EFLAGS)),
2325 (OR64mr addr:$dst, GR64:$src2)>;
2326def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2327 addr:$dst),
2328 (implicit EFLAGS)),
2329 (OR64mi8 addr:$dst, i64immSExt8:$src2)>;
2330def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt32:$src2),
2331 addr:$dst),
2332 (implicit EFLAGS)),
2333 (OR64mi32 addr:$dst, i64immSExt32:$src2)>;
2334
2335// Register-Register Logical XOr with EFLAGS result
2336def : Pat<(parallel (X86xor_flag GR64:$src1, GR64:$src2),
2337 (implicit EFLAGS)),
2338 (XOR64rr GR64:$src1, GR64:$src2)>;
2339
2340// Register-Integer Logical XOr with EFLAGS result
2341def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt8:$src2),
2342 (implicit EFLAGS)),
2343 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2344def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt32:$src2),
2345 (implicit EFLAGS)),
2346 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2347
2348// Register-Memory Logical XOr with EFLAGS result
2349def : Pat<(parallel (X86xor_flag GR64:$src1, (loadi64 addr:$src2)),
2350 (implicit EFLAGS)),
2351 (XOR64rm GR64:$src1, addr:$src2)>;
2352
2353// Memory-Register Logical XOr with EFLAGS result
2354def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), GR64:$src2),
2355 addr:$dst),
2356 (implicit EFLAGS)),
2357 (XOR64mr addr:$dst, GR64:$src2)>;
2358def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2359 addr:$dst),
2360 (implicit EFLAGS)),
2361 (XOR64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002362def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst),
2363 i64immSExt32:$src2),
Dan Gohman12e03292009-09-18 19:59:53 +00002364 addr:$dst),
2365 (implicit EFLAGS)),
2366 (XOR64mi32 addr:$dst, i64immSExt32:$src2)>;
2367
2368// Register-Register Logical And with EFLAGS result
2369def : Pat<(parallel (X86and_flag GR64:$src1, GR64:$src2),
2370 (implicit EFLAGS)),
2371 (AND64rr GR64:$src1, GR64:$src2)>;
2372
2373// Register-Integer Logical And with EFLAGS result
2374def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt8:$src2),
2375 (implicit EFLAGS)),
2376 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2377def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt32:$src2),
2378 (implicit EFLAGS)),
2379 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2380
2381// Register-Memory Logical And with EFLAGS result
2382def : Pat<(parallel (X86and_flag GR64:$src1, (loadi64 addr:$src2)),
2383 (implicit EFLAGS)),
2384 (AND64rm GR64:$src1, addr:$src2)>;
2385
2386// Memory-Register Logical And with EFLAGS result
2387def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), GR64:$src2),
2388 addr:$dst),
2389 (implicit EFLAGS)),
2390 (AND64mr addr:$dst, GR64:$src2)>;
2391def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2392 addr:$dst),
2393 (implicit EFLAGS)),
2394 (AND64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002395def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst),
2396 i64immSExt32:$src2),
Dan Gohman12e03292009-09-18 19:59:53 +00002397 addr:$dst),
2398 (implicit EFLAGS)),
2399 (AND64mi32 addr:$dst, i64immSExt32:$src2)>;
2400
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002401//===----------------------------------------------------------------------===//
2402// X86-64 SSE Instructions
2403//===----------------------------------------------------------------------===//
2404
2405// Move instructions...
2406
Evan Chengb783fa32007-07-19 01:14:50 +00002407def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002408 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002409 [(set VR128:$dst,
2410 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002411def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002412 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002413 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2414 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002415
Evan Chengb783fa32007-07-19 01:14:50 +00002416def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002417 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002418 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002419def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002420 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002421 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2422
Evan Chengb783fa32007-07-19 01:14:50 +00002423def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002424 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002425 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002426def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002427 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002428 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002429
2430//===----------------------------------------------------------------------===//
2431// X86-64 SSE4.1 Instructions
2432//===----------------------------------------------------------------------===//
2433
Nate Begeman4294c1f2008-02-12 22:51:28 +00002434/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2435multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002436 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002437 (ins VR128:$src1, i32i8imm:$src2),
2438 !strconcat(OpcodeStr,
2439 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2440 [(set GR64:$dst,
2441 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002442 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002443 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2444 !strconcat(OpcodeStr,
2445 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2446 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2447 addr:$dst)]>, OpSize, REX_W;
2448}
2449
2450defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2451
2452let isTwoAddress = 1 in {
2453 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002454 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002455 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2456 !strconcat(OpcodeStr,
2457 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2458 [(set VR128:$dst,
2459 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2460 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002461 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002462 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2463 !strconcat(OpcodeStr,
2464 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2465 [(set VR128:$dst,
2466 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2467 imm:$src3)))]>, OpSize, REX_W;
2468 }
2469}
2470
2471defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002472
2473// -disable-16bit support.
2474def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2475 (MOV16mi addr:$dst, imm:$src)>;
2476def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2477 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2478def : Pat<(i64 (sextloadi16 addr:$dst)),
2479 (MOVSX64rm16 addr:$dst)>;
2480def : Pat<(i64 (zextloadi16 addr:$dst)),
2481 (MOVZX64rm16 addr:$dst)>;
2482def : Pat<(i64 (extloadi16 addr:$dst)),
2483 (MOVZX64rm16 addr:$dst)>;