blob: 08e1dd1e060df0a58508c0c068d8278c22514ec1 [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 Chengbd780d22009-02-10 21:39:44 +0000190 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
191 "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,
210 hasCtrlDep = 1 in {
211def 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 &&
438 N->getOpcode() != TargetInstrInfo::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}", []>;
896def RCL64m1 : RI<0xD1, MRM2m, (outs i64mem:$dst), (ins i64mem:$src),
897 "rcl{q}\t{1, $dst|$dst, 1}", []>;
898let Uses = [CL] in {
899def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
900 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
901def RCL64mCL : RI<0xD3, MRM2m, (outs i64mem:$dst), (ins i64mem:$src),
902 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
903}
904def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
905 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000906def RCL64mi : RIi8<0xC1, MRM2m, (outs i64mem:$dst),
907 (ins i64mem:$src, i8imm:$cnt),
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000908 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
909
910def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
911 "rcr{q}\t{1, $dst|$dst, 1}", []>;
912def RCR64m1 : RI<0xD1, MRM3m, (outs i64mem:$dst), (ins i64mem:$src),
913 "rcr{q}\t{1, $dst|$dst, 1}", []>;
914let Uses = [CL] in {
915def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
916 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
917def RCR64mCL : RI<0xD3, MRM3m, (outs i64mem:$dst), (ins i64mem:$src),
918 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
919}
920def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
921 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000922def RCR64mi : RIi8<0xC1, MRM3m, (outs i64mem:$dst),
923 (ins i64mem:$src, i8imm:$cnt),
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000924 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
925}
926
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000927let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000928let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000929def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000930 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000931 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000932def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst),
933 (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000935 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000936def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
939} // isTwoAddress
940
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000941let Uses = [CL] in
Sean Callanan2c48df22009-12-18 00:01:26 +0000942def ROL64mCL : RI<0xD3, MRM0m, (outs), (ins i64mem:$dst),
943 "rol{q}\t{%cl, $dst|$dst, %CL}",
944 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000945def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000947 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000948def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000950 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
951
952let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000953let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000954def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000956 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +0000957def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst),
958 (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000961def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
964} // isTwoAddress
965
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000966let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000967def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000969 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000970def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000973def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
976
977// Double shift instructions (generalizations of rotate)
978let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000979let Uses = [CL] in {
Sean Callanan2c48df22009-12-18 00:01:26 +0000980def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst),
981 (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000982 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000983 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>,
984 TB;
985def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst),
986 (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000987 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
Sean Callanan2c48df22009-12-18 00:01:26 +0000988 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>,
989 TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000990}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991
992let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
993def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Sean Callanan2c48df22009-12-18 00:01:26 +0000994 (outs GR64:$dst),
995 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000996 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
997 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
998 (i8 imm:$src3)))]>,
999 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Sean Callanan2c48df22009-12-18 00:01:26 +00001001 (outs GR64:$dst),
1002 (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001003 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1004 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
1005 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006 TB;
1007} // isCommutable
1008} // isTwoAddress
1009
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001010let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001011def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001012 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1013 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
1014 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +00001015def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001016 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
1017 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
1018 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001019}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001021 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001022 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1023 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
1024 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001025 TB;
1026def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001027 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +00001028 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
1029 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
1030 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 TB;
Evan Cheng55687072007-09-14 21:48:26 +00001032} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033
1034//===----------------------------------------------------------------------===//
1035// Logical Instructions...
1036//
1037
Evan Cheng5b51c242009-01-21 19:45:31 +00001038let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +00001039def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +00001041def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001042 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
1043
Evan Cheng55687072007-09-14 21:48:26 +00001044let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +00001045def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
1046 "and{q}\t{$src, %rax|%rax, $src}", []>;
1047
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048let isTwoAddress = 1 in {
1049let isCommutable = 1 in
1050def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001051 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001052 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001053 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
1054 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001055def AND64rr_REV : RI<0x23, MRMSrcReg, (outs GR64:$dst),
1056 (ins GR64:$src1, GR64:$src2),
1057 "and{q}\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001059 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001060 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001061 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
1062 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +00001064 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001065 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001066 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
1067 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001068def AND64ri32 : RIi32<0x81, MRM4r,
1069 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1070 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001071 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
1072 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073} // isTwoAddress
1074
1075def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001076 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001078 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
1079 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +00001081 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001082 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001083 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
1084 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001085def AND64mi32 : RIi32<0x81, MRM4m,
1086 (outs), (ins i64mem:$dst, i64i32imm:$src),
1087 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001088 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1089 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090
1091let isTwoAddress = 1 in {
1092let isCommutable = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +00001093def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst),
1094 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001096 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001097 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001098def OR64rr_REV : RI<0x0B, MRMSrcReg, (outs GR64:$dst),
1099 (ins GR64:$src1, GR64:$src2),
1100 "or{q}\t{$src2, $dst|$dst, $src2}", []>;
1101def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst),
1102 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001103 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001104 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
1105 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001106def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst),
1107 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001108 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001109 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
Evan Cheng4621d272010-01-11 17:03:47 +00001110 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001111def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst),
1112 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001113 "or{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng44a441c2010-01-12 18:31:19 +00001114 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
Evan Cheng4621d272010-01-11 17:03:47 +00001115 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116} // isTwoAddress
1117
Evan Chengb783fa32007-07-19 01:14:50 +00001118def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001119 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001120 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1121 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001122def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001123 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001124 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1125 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001126def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1127 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001128 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1129 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130
Sean Callanan8562bef2009-09-11 19:01:56 +00001131def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
1132 "or{q}\t{$src, %rax|%rax, $src}", []>;
1133
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +00001135let isCommutable = 1 in
Sean Callanan2c48df22009-12-18 00:01:26 +00001136def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst),
1137 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001138 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001139 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
1140 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001141def XOR64rr_REV : RI<0x33, MRMSrcReg, (outs GR64:$dst),
1142 (ins GR64:$src1, GR64:$src2),
1143 "xor{q}\t{$src2, $dst|$dst, $src2}", []>;
1144def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst),
1145 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001146 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001147 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
1148 (implicit EFLAGS)]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001149def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst),
1150 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001151 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001152 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1153 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +00001155 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001156 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001157 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1158 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001159} // isTwoAddress
1160
Evan Chengb783fa32007-07-19 01:14:50 +00001161def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001163 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1164 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001165def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001166 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001167 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1168 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001169def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1170 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001171 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1172 (implicit EFLAGS)]>;
Sean Callanan794457a2009-09-10 19:52:26 +00001173
1174def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1175 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1176
Evan Cheng55687072007-09-14 21:48:26 +00001177} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001178
1179//===----------------------------------------------------------------------===//
1180// Comparison Instructions...
1181//
1182
1183// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001184let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001185def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1186 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001188def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001189 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001190 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1191 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001192def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001194 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1195 (implicit EFLAGS)]>;
1196def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1197 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001198 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001199 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1200 (implicit EFLAGS)]>;
1201def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1202 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001203 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001204 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1205 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206
Sean Callanan251676e2009-09-02 00:55:49 +00001207
1208def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1209 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001210def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001212 [(X86cmp GR64:$src1, GR64:$src2),
1213 (implicit EFLAGS)]>;
Sean Callanan11490dc2009-09-16 21:11:23 +00001214def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1215 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001216def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001217 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001218 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1219 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001220def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001221 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001222 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1223 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001224def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1225 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1226 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1227 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001228def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001229 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001230 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001231 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001232def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001233 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001234 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001235 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001236def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1237 (ins i64mem:$src1, i64i32imm:$src2),
1238 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1239 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1240 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001241} // Defs = [EFLAGS]
1242
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001243// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001244// TODO: BTC, BTR, and BTS
1245let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001246def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001247 "bt{q}\t{$src2, $src1|$src1, $src2}",
1248 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001249 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001250
1251// Unlike with the register+register form, the memory+register form of the
1252// bt instruction does not ignore the high bits of the index. From ISel's
1253// perspective, this is pretty bizarre. Disable these instructions for now.
Sean Callanan2c48df22009-12-18 00:01:26 +00001254def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1255 "bt{q}\t{$src2, $src1|$src1, $src2}",
Dan Gohman85a228c2009-01-13 23:23:30 +00001256// [(X86bt (loadi64 addr:$src1), GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001257// (implicit EFLAGS)]
1258 []
1259 >, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001260
1261def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1262 "bt{q}\t{$src2, $src1|$src1, $src2}",
1263 [(X86bt GR64:$src1, i64immSExt8:$src2),
1264 (implicit EFLAGS)]>, TB;
1265// Note that these instructions don't need FastBTMem because that
1266// only applies when the other operand is in a register. When it's
1267// an immediate, bt is still fast.
1268def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1269 "bt{q}\t{$src2, $src1|$src1, $src2}",
1270 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1271 (implicit EFLAGS)]>, TB;
Sean Callanan2c48df22009-12-18 00:01:26 +00001272
1273def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1274 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1275def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1276 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1277def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1278 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1279def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1280 "btc{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1281
1282def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1283 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1284def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1285 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1286def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1287 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1288def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1289 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1290
1291def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1292 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1293def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1294 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1295def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1296 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
1297def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1298 "bts{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001299} // Defs = [EFLAGS]
1300
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001302let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001303let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001304def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001305 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001306 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001307 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001308 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001310 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001311 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001313 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001314def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001315 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001316 "cmove{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001318 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001320 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001321 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001323 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001324def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001325 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001326 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001327 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001328 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001330 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001331 "cmova{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001332 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001333 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001334def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001335 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001336 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001338 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001339def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001340 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001341 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001343 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001344def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001345 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001346 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001347 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001348 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001350 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001351 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001352 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001353 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001354def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001355 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001356 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001357 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001358 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001360 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001361 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001362 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001363 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001365 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001366 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001368 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001369def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001370 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001371 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001372 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001373 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001374def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1375 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001376 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001377 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1378 X86_COND_O, EFLAGS))]>, TB;
1379def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1380 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001381 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001382 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1383 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001384} // isCommutable = 1
1385
1386def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1387 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001388 "cmovb{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001389 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1390 X86_COND_B, EFLAGS))]>, TB;
1391def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1392 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001393 "cmovae{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001394 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1395 X86_COND_AE, EFLAGS))]>, TB;
1396def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1397 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001398 "cmove{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001399 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1400 X86_COND_E, EFLAGS))]>, TB;
1401def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1402 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001403 "cmovne{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001404 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1405 X86_COND_NE, EFLAGS))]>, TB;
1406def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1407 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001408 "cmovbe{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001409 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1410 X86_COND_BE, EFLAGS))]>, TB;
1411def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1412 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001413 "cmova{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001414 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1415 X86_COND_A, EFLAGS))]>, TB;
1416def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1417 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001418 "cmovl{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001419 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1420 X86_COND_L, EFLAGS))]>, TB;
1421def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1422 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001423 "cmovge{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001424 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1425 X86_COND_GE, EFLAGS))]>, TB;
1426def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1427 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001428 "cmovle{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001429 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1430 X86_COND_LE, EFLAGS))]>, TB;
1431def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1432 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001433 "cmovg{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001434 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1435 X86_COND_G, EFLAGS))]>, TB;
1436def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1437 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001438 "cmovs{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001439 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1440 X86_COND_S, EFLAGS))]>, TB;
1441def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1442 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001443 "cmovns{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001444 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1445 X86_COND_NS, EFLAGS))]>, TB;
1446def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1447 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001448 "cmovp{q}\t{$src2, $dst|$dst, $src2}",
Evan Cheng926658c2007-10-05 23:13:21 +00001449 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1450 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001452 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001453 "cmovnp{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001455 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001456def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1457 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001458 "cmovo{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001459 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1460 X86_COND_O, EFLAGS))]>, TB;
1461def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1462 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Sean Callanan2c48df22009-12-18 00:01:26 +00001463 "cmovno{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman12fd4d72009-01-07 00:35:10 +00001464 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1465 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001466} // isTwoAddress
1467
Evan Cheng834ae6b2009-12-15 00:53:42 +00001468// Use sbb to materialize carry flag into a GPR.
1469let Defs = [EFLAGS], Uses = [EFLAGS], isCodeGenOnly = 1 in
Evan Cheng4136d8d2009-12-15 06:49:02 +00001470def SETB_C64r : RI<0x19, MRMInitReg, (outs GR64:$dst), (ins),
Evan Cheng834ae6b2009-12-15 00:53:42 +00001471 "sbb{q}\t$dst, $dst",
Evan Chengedeb1692009-12-16 00:53:11 +00001472 [(set GR64:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
Evan Cheng834ae6b2009-12-15 00:53:42 +00001473
Evan Chengedeb1692009-12-16 00:53:11 +00001474def : Pat<(i64 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
Evan Cheng834ae6b2009-12-15 00:53:42 +00001475 (SETB_C64r)>;
1476
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001477//===----------------------------------------------------------------------===//
1478// Conversion Instructions...
1479//
1480
1481// f64 -> signed i64
Sean Callanan2c48df22009-12-18 00:01:26 +00001482def CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
1483 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
1484def CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
1485 "cvtsd2si{q}\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001486def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001487 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001488 [(set GR64:$dst,
1489 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001490def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst),
1491 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001492 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001493 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1494 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001495def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001496 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001497 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001498def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001499 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001500 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001501def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001502 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001503 [(set GR64:$dst,
1504 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001505def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst),
1506 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001507 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001508 [(set GR64:$dst,
1509 (int_x86_sse2_cvttsd2si64
1510 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001511
1512// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001513def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001514 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001515 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001516def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001517 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001519
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520let isTwoAddress = 1 in {
1521def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001522 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001523 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001524 [(set VR128:$dst,
1525 (int_x86_sse2_cvtsi642sd VR128:$src1,
1526 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001528 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001529 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001530 [(set VR128:$dst,
1531 (int_x86_sse2_cvtsi642sd VR128:$src1,
1532 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533} // isTwoAddress
1534
1535// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001536def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001537 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001539def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001540 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001541 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001542
1543let isTwoAddress = 1 in {
1544 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1545 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1546 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1547 [(set VR128:$dst,
1548 (int_x86_sse_cvtsi642ss VR128:$src1,
1549 GR64:$src2))]>;
1550 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
Sean Callanan2c48df22009-12-18 00:01:26 +00001551 (outs VR128:$dst),
1552 (ins VR128:$src1, i64mem:$src2),
Evan Cheng1d5832e2008-01-11 07:37:44 +00001553 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1554 [(set VR128:$dst,
1555 (int_x86_sse_cvtsi642ss VR128:$src1,
1556 (loadi64 addr:$src2)))]>;
1557}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001558
1559// f32 -> signed i64
Sean Callanan2c48df22009-12-18 00:01:26 +00001560def CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
1561 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
1562def CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
1563 "cvtss2si{q}\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001564def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001565 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001566 [(set GR64:$dst,
1567 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001568def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001569 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001570 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1571 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001572def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001573 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001574 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001575def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001576 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001577 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001578def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001579 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001580 [(set GR64:$dst,
1581 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001582def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst),
1583 (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001584 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001585 [(set GR64:$dst,
1586 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001587
1588// Descriptor-table support instructions
1589
1590// LLDT is not interpreted specially in 64-bit mode because there is no sign
1591// extension.
1592def SLDT64r : RI<0x00, MRM0r, (outs GR64:$dst), (ins),
1593 "sldt{q}\t$dst", []>, TB;
1594def SLDT64m : RI<0x00, MRM0m, (outs i16mem:$dst), (ins),
1595 "sldt{q}\t$dst", []>, TB;
Bill Wendling6227d462007-07-23 03:07:27 +00001596
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001597//===----------------------------------------------------------------------===//
1598// Alias Instructions
1599//===----------------------------------------------------------------------===//
1600
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001601// We want to rewrite MOV64r0 in terms of MOV32r0, because it's sometimes a
1602// smaller encoding, but doing so at isel time interferes with rematerialization
1603// in the current register allocator. For now, this is rewritten when the
1604// instruction is lowered to an MCInst.
Chris Lattner17f62252009-07-14 20:19:57 +00001605// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001606// when we have a better way to specify isel priority.
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001607let Defs = [EFLAGS],
1608 AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
1609def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1610 "",
1611 [(set GR64:$dst, 0)]>;
Chris Lattner17f62252009-07-14 20:19:57 +00001612
Dan Gohmanb9e1c8d2010-01-12 04:42:54 +00001613// Materialize i64 constant where top 32-bits are zero. This could theoretically
1614// use MOV32ri with a SUBREG_TO_REG to represent the zero-extension, however
1615// that would make it more difficult to rematerialize.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001616let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001617def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +00001618 "", [(set GR64:$dst, i64immZExt32:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001619
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001620//===----------------------------------------------------------------------===//
1621// Thread Local Storage Instructions
1622//===----------------------------------------------------------------------===//
1623
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001624// All calls clobber the non-callee saved registers. RSP is marked as
1625// a use to prevent stack-pointer assignments that appear immediately
1626// before calls from potentially appearing dead.
1627let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1628 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1629 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1630 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1631 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1632 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001633def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001634 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001635 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001636 ".word\t0x6666; "
1637 "rex64; "
1638 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001639 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001640 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001641
Daniel Dunbar75a07302009-08-11 22:24:40 +00001642let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001643def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1644 "movq\t%gs:$src, $dst",
1645 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1646
Daniel Dunbar75a07302009-08-11 22:24:40 +00001647let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001648def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1649 "movq\t%fs:$src, $dst",
1650 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1651
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001652//===----------------------------------------------------------------------===//
1653// Atomic Instructions
1654//===----------------------------------------------------------------------===//
1655
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001656let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001657def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001658 "lock\n\t"
1659 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001660 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1661}
1662
Dan Gohmana41a1c092008-08-06 15:52:50 +00001663let Constraints = "$val = $dst" in {
1664let Defs = [EFLAGS] in
Sean Callanan2c48df22009-12-18 00:01:26 +00001665def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins GR64:$val,i64mem:$ptr),
Dan Gohman70a8a112009-04-27 15:13:28 +00001666 "lock\n\t"
1667 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001668 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001669 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001670
Sean Callanan2c48df22009-12-18 00:01:26 +00001671def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),
1672 (ins GR64:$val,i64mem:$ptr),
1673 "xchg{q}\t{$val, $ptr|$ptr, $val}",
Evan Chenga1e80602008-04-19 02:05:42 +00001674 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Sean Callanan2c48df22009-12-18 00:01:26 +00001675
1676def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
1677 "xchg{q}\t{$val, $src|$src, $val}", []>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001678}
1679
Sean Callanan2c48df22009-12-18 00:01:26 +00001680def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1681 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1682def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1683 "xadd{q}\t{$src, $dst|$dst, $src}", []>, TB;
1684
1685def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
1686 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1687def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1688 "cmpxchg{q}\t{$src, $dst|$dst, $src}", []>, TB;
1689
Evan Cheng3896a6f2010-01-08 01:29:19 +00001690let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
Sean Callanan2c48df22009-12-18 00:01:26 +00001691def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
1692 "cmpxchg16b\t$dst", []>, TB;
1693
1694def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
1695 "xchg{q}\t{$src, %rax|%rax, $src}", []>;
1696
Evan Chengb723fb52009-07-30 08:33:02 +00001697// Optimized codegen when the non-memory output is not used.
Edwin Törökce819f12009-10-19 11:00:58 +00001698let Defs = [EFLAGS] in {
Evan Chengb723fb52009-07-30 08:33:02 +00001699// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1700def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1701 "lock\n\t"
1702 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1703def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1704 (ins i64mem:$dst, i64i8imm :$src2),
1705 "lock\n\t"
1706 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1707def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1708 (ins i64mem:$dst, i64i32imm :$src2),
1709 "lock\n\t"
1710 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1711def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1712 "lock\n\t"
1713 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1714def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1715 (ins i64mem:$dst, i64i8imm :$src2),
1716 "lock\n\t"
1717 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1718def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1719 (ins i64mem:$dst, i64i32imm:$src2),
1720 "lock\n\t"
1721 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1722def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1723 "lock\n\t"
1724 "inc{q}\t$dst", []>, LOCK;
1725def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1726 "lock\n\t"
1727 "dec{q}\t$dst", []>, LOCK;
Edwin Törökce819f12009-10-19 11:00:58 +00001728}
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001729// Atomic exchange, and, or, xor
1730let Constraints = "$val = $dst", Defs = [EFLAGS],
Dan Gohman30afe012009-10-29 18:10:34 +00001731 usesCustomInserter = 1 in {
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001732def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001733 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001734 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001735def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001736 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001737 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001738def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001739 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001740 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001741def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001742 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001743 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001744def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001745 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001746 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001747def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001748 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001749 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001750def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001751 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001752 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001753def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001754 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001755 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001756}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001757
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001758// Segmentation support instructions
1759
1760// i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1761def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1762 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1763def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1764 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callanan23f33d72009-09-16 22:59:28 +00001765
Sean Callanan2c48df22009-12-18 00:01:26 +00001766def LSL64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1767 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1768def LSL64rr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1769 "lsl{q}\t{$src, $dst|$dst, $src}", []>, TB;
1770
1771def SWPGS : I<0x01, RawFrm, (outs), (ins), "swpgs", []>, TB;
1772
1773def PUSHFS64 : I<0xa0, RawFrm, (outs), (ins),
1774 "push{q}\t%fs", []>, TB;
1775def PUSHGS64 : I<0xa8, RawFrm, (outs), (ins),
1776 "push{q}\t%gs", []>, TB;
1777
1778def POPFS64 : I<0xa1, RawFrm, (outs), (ins),
1779 "pop{q}\t%fs", []>, TB;
1780def POPGS64 : I<0xa9, RawFrm, (outs), (ins),
1781 "pop{q}\t%gs", []>, TB;
1782
1783def LSS64rm : RI<0xb2, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1784 "lss{q}\t{$src, $dst|$dst, $src}", []>, TB;
1785def LFS64rm : RI<0xb4, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1786 "lfs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1787def LGS64rm : RI<0xb5, MRMSrcMem, (outs GR64:$dst), (ins opaque80mem:$src),
1788 "lgs{q}\t{$src, $dst|$dst, $src}", []>, TB;
1789
1790// Specialized register support
1791
1792// no m form encodable; use SMSW16m
1793def SMSW64r : RI<0x01, MRM4r, (outs GR64:$dst), (ins),
1794 "smsw{q}\t$dst", []>, TB;
1795
Sean Callanan23f33d72009-09-16 22:59:28 +00001796// String manipulation instructions
1797
1798def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001799
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001800//===----------------------------------------------------------------------===//
1801// Non-Instruction Patterns
1802//===----------------------------------------------------------------------===//
1803
Chris Lattner0d2dad62009-07-11 22:50:33 +00001804// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1805// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1806// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001807def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001808 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001809def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001810 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001811def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001812 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001813def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001814 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001815def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1816 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001817
Chris Lattnerc04cd042009-07-11 23:17:29 +00001818// In static codegen with small code model, we can get the address of a label
1819// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1820// the MOV64ri64i32 should accept these.
1821def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1822 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1823def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1824 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1825def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1826 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1827def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1828 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001829def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1830 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001831
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001832// In kernel code model, we can get the address of a label
1833// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1834// the MOV64ri32 should accept these.
1835def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1836 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1837def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1838 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1839def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1840 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1841def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1842 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001843def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1844 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001845
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001846// If we have small model and -static mode, it is safe to store global addresses
1847// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001848// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001849def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1850 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001851 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001852def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1853 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001854 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001855def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1856 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001857 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001858def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1859 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001860 Requires<[NearData, IsStatic]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001861def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1862 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1863 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864
1865// Calls
1866// Direct PC relative function call for small code model. 32-bit displacement
1867// sign extended to 64-bit.
1868def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001869 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001870def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001871 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1872
1873def : Pat<(X86call (i64 tglobaladdr:$dst)),
1874 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1875def : Pat<(X86call (i64 texternalsym:$dst)),
1876 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001877
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001878// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001879def : Pat<(X86tcret GR64:$dst, imm:$off),
1880 (TCRETURNri64 GR64:$dst, imm:$off)>;
1881
1882def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
Dan Gohman66fe2bc2009-11-30 23:33:37 +00001883 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001884
1885def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1886 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1887
Dan Gohmanec596042007-09-17 14:35:24 +00001888// Comparisons.
1889
1890// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001891def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001892 (TEST64rr GR64:$src1, GR64:$src1)>;
1893
Dan Gohman0a3c5222009-01-07 01:00:24 +00001894// Conditional moves with folded loads with operands swapped and conditions
1895// inverted.
1896def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1897 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1898def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1899 (CMOVB64rm GR64:$src2, addr:$src1)>;
1900def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1901 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1902def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1903 (CMOVE64rm GR64:$src2, addr:$src1)>;
1904def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1905 (CMOVA64rm GR64:$src2, addr:$src1)>;
1906def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1907 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1908def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1909 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1910def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1911 (CMOVL64rm GR64:$src2, addr:$src1)>;
1912def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1913 (CMOVG64rm GR64:$src2, addr:$src1)>;
1914def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1915 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1916def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1917 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1918def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1919 (CMOVP64rm GR64:$src2, addr:$src1)>;
1920def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1921 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1922def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1923 (CMOVS64rm GR64:$src2, addr:$src1)>;
1924def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1925 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1926def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1927 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001928
Duncan Sands082524c2008-01-23 20:39:46 +00001929// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001930def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1931
1932// extload
Sean Callanan2c48df22009-12-18 00:01:26 +00001933// When extloading from 16-bit and smaller memory locations into 64-bit
1934// registers, use zero-extending loads so that the entire 64-bit register is
1935// defined, avoiding partial-register updates.
Dan Gohmanab460da2008-08-27 17:33:15 +00001936def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1937def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1938def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1939// For other extloads, use subregs, since the high contents of the register are
1940// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001941def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001942 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001943 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001944
Dan Gohman9959b052009-08-26 14:59:13 +00001945// anyext. Define these to do an explicit zero-extend to
1946// avoid partial-register updates.
1947def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1948def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1949def : Pat<(i64 (anyext GR32:$src)),
1950 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001951
1952//===----------------------------------------------------------------------===//
1953// Some peepholes
1954//===----------------------------------------------------------------------===//
1955
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001956// Odd encoding trick: -128 fits into an 8-bit immediate field while
1957// +128 doesn't, so in this special case use a sub instead of an add.
1958def : Pat<(add GR64:$src1, 128),
1959 (SUB64ri8 GR64:$src1, -128)>;
1960def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1961 (SUB64mi8 addr:$dst, -128)>;
1962
1963// The same trick applies for 32-bit immediate fields in 64-bit
1964// instructions.
1965def : Pat<(add GR64:$src1, 0x0000000080000000),
1966 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1967def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1968 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1969
Dan Gohman072641f2010-01-11 17:58:34 +00001970// Use a 32-bit and with implicit zero-extension instead of a 64-bit and if it
1971// has an immediate with at least 32 bits of leading zeros, to avoid needing to
1972// materialize that immediate in a register first.
1973def : Pat<(and GR64:$src, i64immZExt32:$imm),
1974 (SUBREG_TO_REG
1975 (i64 0),
1976 (AND32ri
1977 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit),
1978 imm:$imm),
1979 x86_subreg_32bit)>;
1980
Dan Gohman47a419d2008-08-07 02:54:50 +00001981// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001982def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001983 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001984// r & (2^16-1) ==> movz
1985def : Pat<(and GR64:$src, 0xffff),
1986 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1987// r & (2^8-1) ==> movz
1988def : Pat<(and GR64:$src, 0xff),
1989 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001990// r & (2^8-1) ==> movz
1991def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001992 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001993 Requires<[In64BitMode]>;
1994// r & (2^8-1) ==> movz
1995def : Pat<(and GR16:$src1, 0xff),
1996 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1997 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001998
Dan Gohmandd612bb2008-08-20 21:27:32 +00001999// sext_inreg patterns
2000def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00002001 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002002def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00002003 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002004def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00002005 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002006def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00002007 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002008 Requires<[In64BitMode]>;
2009def : Pat<(sext_inreg GR16:$src, i8),
2010 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
2011 Requires<[In64BitMode]>;
2012
2013// trunc patterns
2014def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002015 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002016def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002017 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002018def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002019 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00002020def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002021 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002022 Requires<[In64BitMode]>;
2023def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00002024 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
2025 Requires<[In64BitMode]>;
2026
2027// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00002028// For now, be conservative on x86-64 and use an h-register extract only if the
2029// value is immediately zero-extended or stored, which are somewhat common
2030// cases. This uses a bunch of code to prevent a register requiring a REX prefix
2031// from being allocated in the same instruction as the h register, as there's
2032// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00002033
2034// h-register extract and zero-extend.
2035def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
2036 (SUBREG_TO_REG
2037 (i64 0),
2038 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002039 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002040 x86_subreg_8bit_hi)),
2041 x86_subreg_32bit)>;
2042def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
2043 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002044 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002045 x86_subreg_8bit_hi))>,
2046 Requires<[In64BitMode]>;
Dan Gohman5d8f9df2010-01-11 17:21:05 +00002047def : Pat<(srl GR16:$src, (i8 8)),
Dan Gohman744d4622009-04-13 16:09:41 +00002048 (EXTRACT_SUBREG
2049 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002050 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002051 x86_subreg_8bit_hi)),
2052 x86_subreg_16bit)>,
2053 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00002054def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
2055 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002056 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00002057 x86_subreg_8bit_hi))>,
2058 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00002059def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
2060 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002061 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00002062 x86_subreg_8bit_hi))>,
2063 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00002064def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
2065 (SUBREG_TO_REG
2066 (i64 0),
2067 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002068 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00002069 x86_subreg_8bit_hi)),
2070 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00002071def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
2072 (SUBREG_TO_REG
2073 (i64 0),
2074 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002075 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00002076 x86_subreg_8bit_hi)),
2077 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00002078
2079// h-register extract and store.
2080def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
2081 (MOV8mr_NOREX
2082 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002083 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002084 x86_subreg_8bit_hi))>;
2085def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
2086 (MOV8mr_NOREX
2087 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002088 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002089 x86_subreg_8bit_hi))>,
2090 Requires<[In64BitMode]>;
2091def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
2092 (MOV8mr_NOREX
2093 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00002094 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00002095 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00002096 Requires<[In64BitMode]>;
2097
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002098// (shl x, 1) ==> (add x, x)
2099def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
2100
Evan Cheng76a64c72008-08-30 02:03:58 +00002101// (shl x (and y, 63)) ==> (shl x, y)
2102def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
2103 (SHL64rCL GR64:$src1)>;
2104def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2105 (SHL64mCL addr:$dst)>;
2106
2107def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
2108 (SHR64rCL GR64:$src1)>;
2109def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2110 (SHR64mCL addr:$dst)>;
2111
2112def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
2113 (SAR64rCL GR64:$src1)>;
2114def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
2115 (SAR64mCL addr:$dst)>;
2116
Evan Cheng10957b82010-01-04 21:22:48 +00002117// Double shift patterns
Dan Gohman921581d2008-10-17 01:23:35 +00002118def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
2119 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
2120
2121def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
2122 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
2123 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
2124
Dan Gohman921581d2008-10-17 01:23:35 +00002125def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
2126 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
2127
2128def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
2129 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
2130 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
2131
Evan Cheng503d9c52010-01-11 22:03:29 +00002132// (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
Evan Cheng44a441c2010-01-12 18:31:19 +00002133let AddedComplexity = 5 in { // Try this before the selecting to OR
Evan Cheng4621d272010-01-11 17:03:47 +00002134def : Pat<(parallel (or_is_add GR64:$src1, i64immSExt8:$src2),
2135 (implicit EFLAGS)),
2136 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
2137def : Pat<(parallel (or_is_add GR64:$src1, i64immSExt32:$src2),
2138 (implicit EFLAGS)),
2139 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Evan Cheng503d9c52010-01-11 22:03:29 +00002140def : Pat<(parallel (or_is_add GR64:$src1, GR64:$src2),
2141 (implicit EFLAGS)),
2142 (ADD64rr GR64:$src1, GR64:$src2)>;
Evan Cheng44a441c2010-01-12 18:31:19 +00002143} // AddedComplexity
Evan Cheng4621d272010-01-11 17:03:47 +00002144
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002145// X86 specific add which produces a flag.
2146def : Pat<(addc GR64:$src1, GR64:$src2),
2147 (ADD64rr GR64:$src1, GR64:$src2)>;
2148def : Pat<(addc GR64:$src1, (load addr:$src2)),
2149 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002150def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
2151 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00002152def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
2153 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002154
2155def : Pat<(subc GR64:$src1, GR64:$src2),
2156 (SUB64rr GR64:$src1, GR64:$src2)>;
2157def : Pat<(subc GR64:$src1, (load addr:$src2)),
2158 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002159def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
2160 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00002161def : Pat<(subc GR64:$src1, imm:$src2),
2162 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002163
Bill Wendlingf5399032008-12-12 21:15:41 +00002164//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00002165// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00002166//===----------------------------------------------------------------------===//
2167
Dan Gohman99a12192009-03-04 19:44:21 +00002168// Register-Register Addition with EFLAGS result
2169def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002170 (implicit EFLAGS)),
2171 (ADD64rr GR64:$src1, GR64:$src2)>;
2172
Dan Gohman99a12192009-03-04 19:44:21 +00002173// Register-Integer Addition with EFLAGS result
2174def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002175 (implicit EFLAGS)),
2176 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002177def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002178 (implicit EFLAGS)),
2179 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002180
Dan Gohman99a12192009-03-04 19:44:21 +00002181// Register-Memory Addition with EFLAGS result
2182def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002183 (implicit EFLAGS)),
2184 (ADD64rm GR64:$src1, addr:$src2)>;
2185
Dan Gohman99a12192009-03-04 19:44:21 +00002186// Memory-Register Addition with EFLAGS result
2187def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002188 addr:$dst),
2189 (implicit EFLAGS)),
2190 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002191def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002192 addr:$dst),
2193 (implicit EFLAGS)),
2194 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002195def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst),
2196 i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002197 addr:$dst),
2198 (implicit EFLAGS)),
2199 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002200
Dan Gohman99a12192009-03-04 19:44:21 +00002201// Register-Register Subtraction with EFLAGS result
2202def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002203 (implicit EFLAGS)),
2204 (SUB64rr GR64:$src1, GR64:$src2)>;
2205
Dan Gohman99a12192009-03-04 19:44:21 +00002206// Register-Memory Subtraction with EFLAGS result
2207def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002208 (implicit EFLAGS)),
2209 (SUB64rm GR64:$src1, addr:$src2)>;
2210
Dan Gohman99a12192009-03-04 19:44:21 +00002211// Register-Integer Subtraction with EFLAGS result
2212def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002213 (implicit EFLAGS)),
2214 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002215def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002216 (implicit EFLAGS)),
2217 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002218
Dan Gohman99a12192009-03-04 19:44:21 +00002219// Memory-Register Subtraction with EFLAGS result
2220def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002221 addr:$dst),
2222 (implicit EFLAGS)),
2223 (SUB64mr addr:$dst, GR64:$src2)>;
2224
Dan Gohman99a12192009-03-04 19:44:21 +00002225// Memory-Integer Subtraction with EFLAGS result
Sean Callanan2c48df22009-12-18 00:01:26 +00002226def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst),
2227 i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002228 addr:$dst),
2229 (implicit EFLAGS)),
2230 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002231def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst),
2232 i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002233 addr:$dst),
2234 (implicit EFLAGS)),
2235 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002236
Dan Gohman99a12192009-03-04 19:44:21 +00002237// Register-Register Signed Integer Multiplication with EFLAGS result
2238def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002239 (implicit EFLAGS)),
2240 (IMUL64rr GR64:$src1, GR64:$src2)>;
2241
Dan Gohman99a12192009-03-04 19:44:21 +00002242// Register-Memory Signed Integer Multiplication with EFLAGS result
2243def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002244 (implicit EFLAGS)),
2245 (IMUL64rm GR64:$src1, addr:$src2)>;
2246
Dan Gohman99a12192009-03-04 19:44:21 +00002247// Register-Integer Signed Integer Multiplication with EFLAGS result
2248def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002249 (implicit EFLAGS)),
2250 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002251def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002252 (implicit EFLAGS)),
2253 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002254
Dan Gohman99a12192009-03-04 19:44:21 +00002255// Memory-Integer Signed Integer Multiplication with EFLAGS result
2256def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002257 (implicit EFLAGS)),
2258 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002259def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002260 (implicit EFLAGS)),
2261 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002262
Dan Gohman99a12192009-03-04 19:44:21 +00002263// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00002264def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
2265 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2266def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
2267 (implicit EFLAGS)),
2268 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2269def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
2270 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2271def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
2272 (implicit EFLAGS)),
2273 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2274
2275def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
2276 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2277def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
2278 (implicit EFLAGS)),
2279 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2280def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
2281 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2282def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2283 (implicit EFLAGS)),
2284 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2285
Dan Gohman99a12192009-03-04 19:44:21 +00002286def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2287 (INC64r GR64:$src)>;
2288def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2289 (implicit EFLAGS)),
2290 (INC64m addr:$dst)>;
2291def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2292 (DEC64r GR64:$src)>;
2293def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2294 (implicit EFLAGS)),
2295 (DEC64m addr:$dst)>;
2296
Dan Gohman12e03292009-09-18 19:59:53 +00002297// Register-Register Logical Or with EFLAGS result
2298def : Pat<(parallel (X86or_flag GR64:$src1, GR64:$src2),
2299 (implicit EFLAGS)),
2300 (OR64rr GR64:$src1, GR64:$src2)>;
2301
2302// Register-Integer Logical Or with EFLAGS result
2303def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt8:$src2),
2304 (implicit EFLAGS)),
2305 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2306def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt32:$src2),
2307 (implicit EFLAGS)),
2308 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2309
2310// Register-Memory Logical Or with EFLAGS result
2311def : Pat<(parallel (X86or_flag GR64:$src1, (loadi64 addr:$src2)),
2312 (implicit EFLAGS)),
2313 (OR64rm GR64:$src1, addr:$src2)>;
2314
2315// Memory-Register Logical Or with EFLAGS result
2316def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), GR64:$src2),
2317 addr:$dst),
2318 (implicit EFLAGS)),
2319 (OR64mr addr:$dst, GR64:$src2)>;
2320def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2321 addr:$dst),
2322 (implicit EFLAGS)),
2323 (OR64mi8 addr:$dst, i64immSExt8:$src2)>;
2324def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt32:$src2),
2325 addr:$dst),
2326 (implicit EFLAGS)),
2327 (OR64mi32 addr:$dst, i64immSExt32:$src2)>;
2328
2329// Register-Register Logical XOr with EFLAGS result
2330def : Pat<(parallel (X86xor_flag GR64:$src1, GR64:$src2),
2331 (implicit EFLAGS)),
2332 (XOR64rr GR64:$src1, GR64:$src2)>;
2333
2334// Register-Integer Logical XOr with EFLAGS result
2335def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt8:$src2),
2336 (implicit EFLAGS)),
2337 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2338def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt32:$src2),
2339 (implicit EFLAGS)),
2340 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2341
2342// Register-Memory Logical XOr with EFLAGS result
2343def : Pat<(parallel (X86xor_flag GR64:$src1, (loadi64 addr:$src2)),
2344 (implicit EFLAGS)),
2345 (XOR64rm GR64:$src1, addr:$src2)>;
2346
2347// Memory-Register Logical XOr with EFLAGS result
2348def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), GR64:$src2),
2349 addr:$dst),
2350 (implicit EFLAGS)),
2351 (XOR64mr addr:$dst, GR64:$src2)>;
2352def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2353 addr:$dst),
2354 (implicit EFLAGS)),
2355 (XOR64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002356def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst),
2357 i64immSExt32:$src2),
Dan Gohman12e03292009-09-18 19:59:53 +00002358 addr:$dst),
2359 (implicit EFLAGS)),
2360 (XOR64mi32 addr:$dst, i64immSExt32:$src2)>;
2361
2362// Register-Register Logical And with EFLAGS result
2363def : Pat<(parallel (X86and_flag GR64:$src1, GR64:$src2),
2364 (implicit EFLAGS)),
2365 (AND64rr GR64:$src1, GR64:$src2)>;
2366
2367// Register-Integer Logical And with EFLAGS result
2368def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt8:$src2),
2369 (implicit EFLAGS)),
2370 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2371def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt32:$src2),
2372 (implicit EFLAGS)),
2373 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2374
2375// Register-Memory Logical And with EFLAGS result
2376def : Pat<(parallel (X86and_flag GR64:$src1, (loadi64 addr:$src2)),
2377 (implicit EFLAGS)),
2378 (AND64rm GR64:$src1, addr:$src2)>;
2379
2380// Memory-Register Logical And with EFLAGS result
2381def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), GR64:$src2),
2382 addr:$dst),
2383 (implicit EFLAGS)),
2384 (AND64mr addr:$dst, GR64:$src2)>;
2385def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2386 addr:$dst),
2387 (implicit EFLAGS)),
2388 (AND64mi8 addr:$dst, i64immSExt8:$src2)>;
Sean Callanan2c48df22009-12-18 00:01:26 +00002389def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst),
2390 i64immSExt32:$src2),
Dan Gohman12e03292009-09-18 19:59:53 +00002391 addr:$dst),
2392 (implicit EFLAGS)),
2393 (AND64mi32 addr:$dst, i64immSExt32:$src2)>;
2394
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002395//===----------------------------------------------------------------------===//
2396// X86-64 SSE Instructions
2397//===----------------------------------------------------------------------===//
2398
2399// Move instructions...
2400
Evan Chengb783fa32007-07-19 01:14:50 +00002401def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002402 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002403 [(set VR128:$dst,
2404 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002405def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002406 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002407 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2408 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002409
Evan Chengb783fa32007-07-19 01:14:50 +00002410def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002411 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002412 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002413def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002414 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002415 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2416
Evan Chengb783fa32007-07-19 01:14:50 +00002417def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002418 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002419 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002420def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002421 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002422 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002423
2424//===----------------------------------------------------------------------===//
2425// X86-64 SSE4.1 Instructions
2426//===----------------------------------------------------------------------===//
2427
Nate Begeman4294c1f2008-02-12 22:51:28 +00002428/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2429multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002430 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002431 (ins VR128:$src1, i32i8imm:$src2),
2432 !strconcat(OpcodeStr,
2433 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2434 [(set GR64:$dst,
2435 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002436 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002437 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2438 !strconcat(OpcodeStr,
2439 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2440 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2441 addr:$dst)]>, OpSize, REX_W;
2442}
2443
2444defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2445
2446let isTwoAddress = 1 in {
2447 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002448 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002449 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2450 !strconcat(OpcodeStr,
2451 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2452 [(set VR128:$dst,
2453 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2454 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002455 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002456 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2457 !strconcat(OpcodeStr,
2458 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2459 [(set VR128:$dst,
2460 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2461 imm:$src3)))]>, OpSize, REX_W;
2462 }
2463}
2464
2465defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002466
2467// -disable-16bit support.
2468def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2469 (MOV16mi addr:$dst, imm:$src)>;
2470def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2471 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2472def : Pat<(i64 (sextloadi16 addr:$dst)),
2473 (MOVSX64rm16 addr:$dst)>;
2474def : Pat<(i64 (zextloadi16 addr:$dst)),
2475 (MOVZX64rm16 addr:$dst)>;
2476def : Pat<(i64 (extloadi16 addr:$dst)),
2477 (MOVZX64rm16 addr:$dst)>;