blob: f165336fdb042d795c51cbf86e6e05453a7edefe [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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114//===----------------------------------------------------------------------===//
115// Call Instructions...
116//
Evan Cheng37e7c752007-07-21 00:34:19 +0000117let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000118 // All calls clobber the non-callee saved registers. RSP is marked as
119 // a use to prevent stack-pointer assignments that appear immediately
120 // before calls from potentially appearing dead. Uses for argument
121 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000123 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
125 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000126 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
127 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000128
129 // NOTE: this pattern doesn't match "X86call imm", because we do not know
130 // that the offset between an arbitrary immediate and the call will fit in
131 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000132 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000133 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
134 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000135 Requires<[In64BitMode, NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000136 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000137 "call\t{*}$dst", [(X86call GR64:$dst)]>,
138 Requires<[NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000139 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000140 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
141 Requires<[NotWin64]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000142
143 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
144 "lcall{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 }
146
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000147 // FIXME: We need to teach codegen about single list of call-clobbered registers.
148let isCall = 1 in
149 // All calls clobber the non-callee saved registers. RSP is marked as
150 // a use to prevent stack-pointer assignments that appear immediately
151 // before calls from potentially appearing dead. Uses for argument
152 // registers are added manually.
153 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
154 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
155 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
156 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
157 Uses = [RSP] in {
158 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000159 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
160 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000161 Requires<[IsWin64]>;
162 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
163 "call\t{*}$dst",
164 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
165 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
166 "call\t{*}$dst",
167 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
168 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000169
170
171let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000172def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
173 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000174 "#TC_RETURN $dst $offset",
175 []>;
176
177let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000178def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
179 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000180 "#TC_RETURN $dst $offset",
181 []>;
182
183
184let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000185 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
186 "jmp{q}\t{*}$dst # TAILCALL",
187 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000188
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000190let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000191 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000193 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 [(brind (loadi64 addr:$dst))]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000195 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
196 "ljmp{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197}
198
199//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000200// EH Pseudo Instructions
201//
202let isTerminator = 1, isReturn = 1, isBarrier = 1,
203 hasCtrlDep = 1 in {
204def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
205 "ret\t#eh_return, addr: $addr",
206 [(X86ehret GR64:$addr)]>;
207
208}
209
210//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211// Miscellaneous Instructions...
212//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000213let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000215 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000216let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000217let mayLoad = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000219 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000220def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
221def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
222}
223let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000225 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000226def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
227def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
228}
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000229}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Bill Wendling4c2638c2009-06-15 19:39:04 +0000231let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
232def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000233 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000234def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000235 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000236def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000237 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000238}
239
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000240let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000241def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000242let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000243def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000244
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000246 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000247 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
249
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000250let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000251def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000252 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253 [(set GR64:$dst, lea64addr:$src)]>;
254
255let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000256def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000257 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259
Evan Cheng48679f42007-12-14 02:13:44 +0000260// Bit scan instructions.
261let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000262def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000263 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000264 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000265def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000266 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000267 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
268 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000269
Evan Cheng4e33de92007-12-14 18:49:43 +0000270def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000271 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000272 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000273def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000274 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000275 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
276 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000277} // Defs = [EFLAGS]
278
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000280let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000281def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000282 [(X86rep_movs i64)]>, REP;
283let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000284def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000285 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286
Sean Callanan481f06d2009-09-12 00:37:19 +0000287def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scas{q}", []>;
288
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000289// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000290def SYSEXIT64 : RI<0x35, RawFrm,
291 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000292
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293//===----------------------------------------------------------------------===//
294// Move Instructions...
295//
296
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000297let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300
Evan Chengd2b9d302008-06-25 01:16:38 +0000301let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000302def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000303 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000305def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000306 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000308}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309
Dan Gohman5574cc72008-12-03 18:15:48 +0000310let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000311def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000312 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313 [(set GR64:$dst, (load addr:$src))]>;
314
Evan Chengb783fa32007-07-19 01:14:50 +0000315def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000316 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000318def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000319 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320 [(store i64immSExt32:$src, addr:$dst)]>;
321
Sean Callanan70953a52009-09-10 18:33:42 +0000322def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins i8imm:$src),
323 "mov{q}\t{$src, %rax|%rax, $src}", []>;
324def MOV64o32a : RIi32<0xA1, RawFrm, (outs), (ins i32imm:$src),
325 "mov{q}\t{$src, %rax|%rax, $src}", []>;
326def MOV64ao8 : RIi8<0xA2, RawFrm, (outs i8imm:$dst), (ins),
327 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
328def MOV64ao32 : RIi32<0xA3, RawFrm, (outs i32imm:$dst), (ins),
329 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
330
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331// Sign/Zero extenders
332
Dan Gohmanedde1992009-04-13 15:13:28 +0000333// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
334// operand, which makes it a rare instruction with an 8-bit register
335// operand that can never access an h register. If support for h registers
336// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000337def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000338 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000340def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000343def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000346def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000347 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000349def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000350 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000352def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000353 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
355
Dan Gohman9203ab42008-07-30 18:09:17 +0000356// Use movzbl instead of movzbq when the destination is a register; it's
357// equivalent due to implicit zero-extending, and it has a smaller encoding.
358def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
359 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
360 [(set GR64:$dst, (zext GR8:$src))]>, TB;
361def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
362 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
363 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
364// Use movzwl instead of movzwq when the destination is a register; it's
365// equivalent due to implicit zero-extending, and it has a smaller encoding.
366def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
367 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
368 [(set GR64:$dst, (zext GR16:$src))]>, TB;
369def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
370 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
371 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372
Dan Gohman47a419d2008-08-07 02:54:50 +0000373// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000374// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
375// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
376// zero-extension, however this isn't possible when the 32-bit value is
377// defined by a truncate or is copied from something where the high bits aren't
378// necessarily all zero. In such cases, we fall back to these explicit zext
379// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000380def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
381 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
382 [(set GR64:$dst, (zext GR32:$src))]>;
383def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
384 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
385 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
386
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000387// Any instruction that defines a 32-bit result leaves the high half of the
388// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
389// be copying from a truncate, but any other 32-bit operation will zero-extend
390// up to 64 bits.
391def def32 : PatLeaf<(i32 GR32:$src), [{
392 return N->getOpcode() != ISD::TRUNCATE &&
393 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
394 N->getOpcode() != ISD::CopyFromReg;
395}]>;
396
397// In the case of a 32-bit def that is known to implicitly zero-extend,
398// we can use a SUBREG_TO_REG.
399def : Pat<(i64 (zext def32:$src)),
400 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
401
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000402let neverHasSideEffects = 1 in {
403 let Defs = [RAX], Uses = [EAX] in
404 def CDQE : RI<0x98, RawFrm, (outs), (ins),
405 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000407 let Defs = [RAX,RDX], Uses = [RAX] in
408 def CQO : RI<0x99, RawFrm, (outs), (ins),
409 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
410}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411
412//===----------------------------------------------------------------------===//
413// Arithmetic Instructions...
414//
415
Evan Cheng55687072007-09-14 21:48:26 +0000416let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000417
418def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
419 "add{q}\t{$src, %rax|%rax, $src}", []>;
420
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421let isTwoAddress = 1 in {
422let isConvertibleToThreeAddress = 1 in {
423let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000424// Register-Register Addition
425def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
426 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000427 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000428 (implicit EFLAGS)]>;
429
430// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000431def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
432 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000433 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
434 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000435def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
436 "add{q}\t{$src2, $dst|$dst, $src2}",
437 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
438 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439} // isConvertibleToThreeAddress
440
Bill Wendlingae034ed2008-12-12 00:56:36 +0000441// Register-Memory Addition
442def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
443 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000444 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000445 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446} // isTwoAddress
447
Bill Wendlingae034ed2008-12-12 00:56:36 +0000448// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000449def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000450 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000451 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
452 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000453def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000454 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000455 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
456 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000457def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
458 "add{q}\t{$src2, $dst|$dst, $src2}",
459 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
460 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461
Evan Cheng259471d2007-10-05 17:59:57 +0000462let Uses = [EFLAGS] in {
Sean Callanan8562bef2009-09-11 19:01:56 +0000463
464def ADC64i32 : RI<0x15, RawFrm, (outs), (ins i32imm:$src),
465 "adc{q}\t{$src, %rax|%rax, $src}", []>;
466
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467let isTwoAddress = 1 in {
468let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000469def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000470 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000471 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
Dale Johannesen747fe522009-06-02 03:12:52 +0000473def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000474 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000475 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476
Dale Johannesen747fe522009-06-02 03:12:52 +0000477def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000479 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
480def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000481 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000482 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483} // isTwoAddress
484
Evan Chengb783fa32007-07-19 01:14:50 +0000485def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000487 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000488def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000490 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000491def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
492 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000493 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000494} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495
496let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000497// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000498def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000499 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000500 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
501 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000502
503// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000504def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000506 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
507 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000508
509// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000510def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
511 (ins GR64:$src1, i64i8imm:$src2),
512 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000513 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
514 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000515def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
516 (ins GR64:$src1, i64i32imm:$src2),
517 "sub{q}\t{$src2, $dst|$dst, $src2}",
518 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
519 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520} // isTwoAddress
521
Sean Callanan8562bef2009-09-11 19:01:56 +0000522def SUB64i32 : RI<0x2D, RawFrm, (outs), (ins i32imm:$src),
523 "sub{q}\t{$src, %rax|%rax, $src}", []>;
524
Bill Wendlingae034ed2008-12-12 00:56:36 +0000525// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000526def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000527 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000528 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
529 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000530
531// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000532def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000533 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000534 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000535 addr:$dst),
536 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000537def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
538 "sub{q}\t{$src2, $dst|$dst, $src2}",
539 [(store (sub (load addr:$dst), i64immSExt32:$src2),
540 addr:$dst),
541 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542
Evan Cheng259471d2007-10-05 17:59:57 +0000543let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000545def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000546 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000547 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548
Dale Johannesen747fe522009-06-02 03:12:52 +0000549def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000550 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000551 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552
Dale Johannesen747fe522009-06-02 03:12:52 +0000553def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000554 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000555 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
556def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000557 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000558 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559} // isTwoAddress
560
Sean Callanan8562bef2009-09-11 19:01:56 +0000561def SBB64i32 : RI<0x1D, RawFrm, (outs), (ins i32imm:$src),
562 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
563
Evan Chengb783fa32007-07-19 01:14:50 +0000564def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000565 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000566 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000567def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000568 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000569 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000570def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
571 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000572 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000573} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000574} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575
576// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000577let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000578def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000579 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000580let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000581def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000582 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583
584// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000585def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000586 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000587let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000588def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000589 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
590}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591
Evan Cheng55687072007-09-14 21:48:26 +0000592let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593let isTwoAddress = 1 in {
594let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000595// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000596def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
597 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000598 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000599 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
600 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601
Bill Wendlingf5399032008-12-12 21:15:41 +0000602// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000603def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
604 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000605 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000606 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
607 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608} // isTwoAddress
609
610// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000611
Bill Wendlingf5399032008-12-12 21:15:41 +0000612// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000614 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000615 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000616 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
617 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000618def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
619 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
620 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
621 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
622 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000623
Bill Wendlingf5399032008-12-12 21:15:41 +0000624// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000626 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000627 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000628 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000629 i64immSExt8:$src2)),
630 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000631def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
632 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
633 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
634 [(set GR64:$dst, (mul (load addr:$src1),
635 i64immSExt32:$src2)),
636 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000637} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638
639// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000640let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000641def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000642 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000644def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000645 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000646let mayLoad = 1 in {
647def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
648 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000649def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000650 "idiv{q}\t$src", []>;
651}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000652}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653
654// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000655let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000657def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000658 [(set GR64:$dst, (ineg GR64:$src)),
659 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000660def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000661 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
662 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663
664let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000665def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000666 [(set GR64:$dst, (add GR64:$src, 1)),
667 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000668def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000669 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
670 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000671
672let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000673def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000674 [(set GR64:$dst, (add GR64:$src, -1)),
675 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000676def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000677 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
678 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000679
680// In 64-bit mode, single byte INC and DEC cannot be encoded.
681let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
682// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000683def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000684 [(set GR16:$dst, (add GR16:$src, 1)),
685 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000687def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000688 [(set GR32:$dst, (add GR32:$src, 1)),
689 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000691def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000692 [(set GR16:$dst, (add GR16:$src, -1)),
693 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000695def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000696 [(set GR32:$dst, (add GR32:$src, -1)),
697 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 Requires<[In64BitMode]>;
699} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000700
701// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
702// how to unfold them.
703let isTwoAddress = 0, CodeSize = 2 in {
704 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000705 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
706 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000707 OpSize, Requires<[In64BitMode]>;
708 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000709 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
710 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000711 Requires<[In64BitMode]>;
712 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000713 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
714 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000715 OpSize, Requires<[In64BitMode]>;
716 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000717 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
718 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000719 Requires<[In64BitMode]>;
720}
Evan Cheng55687072007-09-14 21:48:26 +0000721} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722
723
Evan Cheng55687072007-09-14 21:48:26 +0000724let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725// Shift instructions
726let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000727let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000728def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000730 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000731let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000732def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000733 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000735// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
736// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737} // isTwoAddress
738
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000739let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000742 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
749
750let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000751let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000752def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000754 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000755def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000758def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
761} // isTwoAddress
762
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000763let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000764def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000765 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000766 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000767def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000768 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000769 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000770def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000771 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
773
774let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000775let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000776def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000777 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000778 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000779def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000782def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000783 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
785} // isTwoAddress
786
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000787let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000788def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000789 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000790 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000791def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000792 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000794def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000795 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
797
798// Rotate instructions
799let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000800let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000801def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000804def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000807def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
810} // isTwoAddress
811
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000812let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000813def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000814 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000815 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000816def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000817 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000819def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000820 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
822
823let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000824let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000825def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000826 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000827 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000828def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000829 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000831def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000832 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
834} // isTwoAddress
835
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000836let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000837def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000838 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000839 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000840def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000841 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000843def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000844 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
846
847// Double shift instructions (generalizations of rotate)
848let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000849let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000850def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000851 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
852 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000853def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000854 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
855 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000856}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857
858let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
859def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000860 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000861 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
862 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
863 (i8 imm:$src3)))]>,
864 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000866 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000867 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
868 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
869 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 TB;
871} // isCommutable
872} // isTwoAddress
873
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000874let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000875def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000876 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
877 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
878 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000879def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000880 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
881 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
882 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000883}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000885 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000886 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
887 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
888 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889 TB;
890def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000891 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000892 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
893 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
894 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000896} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897
898//===----------------------------------------------------------------------===//
899// Logical Instructions...
900//
901
Evan Cheng5b51c242009-01-21 19:45:31 +0000902let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000903def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000904 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000905def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
907
Evan Cheng55687072007-09-14 21:48:26 +0000908let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000909def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
910 "and{q}\t{$src, %rax|%rax, $src}", []>;
911
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912let isTwoAddress = 1 in {
913let isCommutable = 1 in
914def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000915 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000916 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000917 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
918 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000919def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000920 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000921 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000922 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
923 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000925 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000926 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000927 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
928 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000929def AND64ri32 : RIi32<0x81, MRM4r,
930 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
931 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000932 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
933 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934} // isTwoAddress
935
936def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000937 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000939 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
940 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000942 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000943 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000944 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
945 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000946def AND64mi32 : RIi32<0x81, MRM4m,
947 (outs), (ins i64mem:$dst, i64i32imm:$src),
948 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000949 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
950 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000951
952let isTwoAddress = 1 in {
953let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000954def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000956 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
957 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000958def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000960 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
961 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000962def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000963 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000964 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
965 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000966def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
967 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000968 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
969 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000970} // isTwoAddress
971
Evan Chengb783fa32007-07-19 01:14:50 +0000972def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000973 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000974 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
975 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000976def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000977 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000978 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
979 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000980def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
981 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000982 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
983 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000984
Sean Callanan8562bef2009-09-11 19:01:56 +0000985def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
986 "or{q}\t{$src, %rax|%rax, $src}", []>;
987
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000988let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000989let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000990def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000991 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000992 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
993 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000994def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000995 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000996 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
997 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000998def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
999 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001000 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1001 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001002def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +00001003 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001005 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1006 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007} // isTwoAddress
1008
Evan Chengb783fa32007-07-19 01:14:50 +00001009def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001010 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001011 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1012 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001013def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001014 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001015 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1016 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001017def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1018 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001019 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1020 (implicit EFLAGS)]>;
Sean Callanan794457a2009-09-10 19:52:26 +00001021
1022def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1023 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1024
Evan Cheng55687072007-09-14 21:48:26 +00001025} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026
1027//===----------------------------------------------------------------------===//
1028// Comparison Instructions...
1029//
1030
1031// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001032let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001033def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1034 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001036def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001037 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001038 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1039 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001040def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001041 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001042 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1043 (implicit EFLAGS)]>;
1044def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1045 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001046 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001047 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1048 (implicit EFLAGS)]>;
1049def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1050 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001051 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001052 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1053 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054
Sean Callanan251676e2009-09-02 00:55:49 +00001055
1056def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1057 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001058def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001059 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001060 [(X86cmp GR64:$src1, GR64:$src2),
1061 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001062def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001064 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1065 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001066def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001067 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001068 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1069 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001070def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1071 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1072 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1073 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001074def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001075 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001076 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001077 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001078def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001079 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001080 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001081 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001082def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1083 (ins i64mem:$src1, i64i32imm:$src2),
1084 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1085 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1086 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001087} // Defs = [EFLAGS]
1088
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001089// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001090// TODO: BTC, BTR, and BTS
1091let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001092def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001093 "bt{q}\t{$src2, $src1|$src1, $src2}",
1094 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001095 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001096
1097// Unlike with the register+register form, the memory+register form of the
1098// bt instruction does not ignore the high bits of the index. From ISel's
1099// perspective, this is pretty bizarre. Disable these instructions for now.
1100//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1101// "bt{q}\t{$src2, $src1|$src1, $src2}",
1102// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1103// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001104
1105def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1106 "bt{q}\t{$src2, $src1|$src1, $src2}",
1107 [(X86bt GR64:$src1, i64immSExt8:$src2),
1108 (implicit EFLAGS)]>, TB;
1109// Note that these instructions don't need FastBTMem because that
1110// only applies when the other operand is in a register. When it's
1111// an immediate, bt is still fast.
1112def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1113 "bt{q}\t{$src2, $src1|$src1, $src2}",
1114 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1115 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001116} // Defs = [EFLAGS]
1117
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001119let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001120let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001122 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001123 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001124 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001125 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001127 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001128 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001130 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001132 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001133 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001135 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001137 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001138 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001140 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001142 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001143 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001144 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001145 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001147 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001148 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001149 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001150 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001152 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001153 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001155 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001156def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001157 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001158 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001159 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001160 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001162 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001163 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001164 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001165 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001167 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001168 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001169 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001170 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001172 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001173 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001174 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001175 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001176def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001177 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001178 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001179 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001180 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001182 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001183 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001184 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001185 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001187 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001188 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001189 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001190 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001191def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1192 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1193 "cmovo\t{$src2, $dst|$dst, $src2}",
1194 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1195 X86_COND_O, EFLAGS))]>, TB;
1196def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1197 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1198 "cmovno\t{$src2, $dst|$dst, $src2}",
1199 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1200 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001201} // isCommutable = 1
1202
1203def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1204 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1205 "cmovb\t{$src2, $dst|$dst, $src2}",
1206 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1207 X86_COND_B, EFLAGS))]>, TB;
1208def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1209 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1210 "cmovae\t{$src2, $dst|$dst, $src2}",
1211 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1212 X86_COND_AE, EFLAGS))]>, TB;
1213def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1214 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1215 "cmove\t{$src2, $dst|$dst, $src2}",
1216 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1217 X86_COND_E, EFLAGS))]>, TB;
1218def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1219 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1220 "cmovne\t{$src2, $dst|$dst, $src2}",
1221 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1222 X86_COND_NE, EFLAGS))]>, TB;
1223def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1224 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1225 "cmovbe\t{$src2, $dst|$dst, $src2}",
1226 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1227 X86_COND_BE, EFLAGS))]>, TB;
1228def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1229 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1230 "cmova\t{$src2, $dst|$dst, $src2}",
1231 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1232 X86_COND_A, EFLAGS))]>, TB;
1233def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1234 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1235 "cmovl\t{$src2, $dst|$dst, $src2}",
1236 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1237 X86_COND_L, EFLAGS))]>, TB;
1238def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1239 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1240 "cmovge\t{$src2, $dst|$dst, $src2}",
1241 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1242 X86_COND_GE, EFLAGS))]>, TB;
1243def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1244 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1245 "cmovle\t{$src2, $dst|$dst, $src2}",
1246 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1247 X86_COND_LE, EFLAGS))]>, TB;
1248def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1249 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1250 "cmovg\t{$src2, $dst|$dst, $src2}",
1251 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1252 X86_COND_G, EFLAGS))]>, TB;
1253def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1254 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1255 "cmovs\t{$src2, $dst|$dst, $src2}",
1256 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1257 X86_COND_S, EFLAGS))]>, TB;
1258def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1259 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1260 "cmovns\t{$src2, $dst|$dst, $src2}",
1261 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1262 X86_COND_NS, EFLAGS))]>, TB;
1263def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1264 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1265 "cmovp\t{$src2, $dst|$dst, $src2}",
1266 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1267 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001268def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001269 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001270 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001271 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001272 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001273def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1274 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1275 "cmovo\t{$src2, $dst|$dst, $src2}",
1276 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1277 X86_COND_O, EFLAGS))]>, TB;
1278def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1279 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1280 "cmovno\t{$src2, $dst|$dst, $src2}",
1281 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1282 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283} // isTwoAddress
1284
1285//===----------------------------------------------------------------------===//
1286// Conversion Instructions...
1287//
1288
1289// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001290def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001292 [(set GR64:$dst,
1293 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001294def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001295 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001296 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1297 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001298def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001299 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001301def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001302 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001303 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001304def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001305 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001306 [(set GR64:$dst,
1307 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001308def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001309 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001310 [(set GR64:$dst,
1311 (int_x86_sse2_cvttsd2si64
1312 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313
1314// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001315def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001316 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001318def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001319 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001321
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322let isTwoAddress = 1 in {
1323def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001324 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001325 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001326 [(set VR128:$dst,
1327 (int_x86_sse2_cvtsi642sd VR128:$src1,
1328 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001330 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001331 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001332 [(set VR128:$dst,
1333 (int_x86_sse2_cvtsi642sd VR128:$src1,
1334 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001335} // isTwoAddress
1336
1337// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001338def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001339 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001340 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001341def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001342 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001343 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001344
1345let isTwoAddress = 1 in {
1346 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1347 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1348 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1349 [(set VR128:$dst,
1350 (int_x86_sse_cvtsi642ss VR128:$src1,
1351 GR64:$src2))]>;
1352 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1353 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1354 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1355 [(set VR128:$dst,
1356 (int_x86_sse_cvtsi642ss VR128:$src1,
1357 (loadi64 addr:$src2)))]>;
1358}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359
1360// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001361def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001362 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001363 [(set GR64:$dst,
1364 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001365def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001366 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001367 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1368 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001369def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001370 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001371 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001372def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001373 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001374 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001375def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001376 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001377 [(set GR64:$dst,
1378 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001379def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001380 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001381 [(set GR64:$dst,
1382 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1383
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001384//===----------------------------------------------------------------------===//
1385// Alias Instructions
1386//===----------------------------------------------------------------------===//
1387
Dan Gohman027cd112007-09-17 14:55:08 +00001388// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1389// equivalent due to implicit zero-extending, and it sometimes has a smaller
1390// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001391// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001392// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001393let AddedComplexity = 1 in
1394def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001395 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001396
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001397
1398// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001399let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001400def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001401 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001402 [(set GR64:$dst, i64immZExt32:$src)]>;
1403
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001404//===----------------------------------------------------------------------===//
1405// Thread Local Storage Instructions
1406//===----------------------------------------------------------------------===//
1407
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001408// All calls clobber the non-callee saved registers. RSP is marked as
1409// a use to prevent stack-pointer assignments that appear immediately
1410// before calls from potentially appearing dead.
1411let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1412 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1413 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1414 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1415 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1416 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001417def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001418 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001419 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001420 ".word\t0x6666; "
1421 "rex64; "
1422 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001423 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001424 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001425
Daniel Dunbar75a07302009-08-11 22:24:40 +00001426let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001427def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1428 "movq\t%gs:$src, $dst",
1429 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1430
Daniel Dunbar75a07302009-08-11 22:24:40 +00001431let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001432def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1433 "movq\t%fs:$src, $dst",
1434 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1435
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001436//===----------------------------------------------------------------------===//
1437// Atomic Instructions
1438//===----------------------------------------------------------------------===//
1439
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001440let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001441def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001442 "lock\n\t"
1443 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001444 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1445}
1446
Dan Gohmana41a1c092008-08-06 15:52:50 +00001447let Constraints = "$val = $dst" in {
1448let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001449def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001450 "lock\n\t"
1451 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001452 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001453 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001454
Evan Chenga1e80602008-04-19 02:05:42 +00001455def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001456 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001457 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001458}
1459
Evan Chengb723fb52009-07-30 08:33:02 +00001460// Optimized codegen when the non-memory output is not used.
1461// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1462def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1463 "lock\n\t"
1464 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1465def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1466 (ins i64mem:$dst, i64i8imm :$src2),
1467 "lock\n\t"
1468 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1469def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1470 (ins i64mem:$dst, i64i32imm :$src2),
1471 "lock\n\t"
1472 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1473def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1474 "lock\n\t"
1475 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1476def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1477 (ins i64mem:$dst, i64i8imm :$src2),
1478 "lock\n\t"
1479 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1480def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1481 (ins i64mem:$dst, i64i32imm:$src2),
1482 "lock\n\t"
1483 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1484def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1485 "lock\n\t"
1486 "inc{q}\t$dst", []>, LOCK;
1487def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1488 "lock\n\t"
1489 "dec{q}\t$dst", []>, LOCK;
1490
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001491// Atomic exchange, and, or, xor
1492let Constraints = "$val = $dst", Defs = [EFLAGS],
1493 usesCustomDAGSchedInserter = 1 in {
1494def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001495 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001496 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001497def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001498 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001499 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001500def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001501 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001502 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001503def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001504 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001505 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001506def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001507 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001508 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001509def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001510 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001511 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001512def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001513 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001514 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001515def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001516 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001517 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001518}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001519
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520//===----------------------------------------------------------------------===//
1521// Non-Instruction Patterns
1522//===----------------------------------------------------------------------===//
1523
Chris Lattner0d2dad62009-07-11 22:50:33 +00001524// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1525// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1526// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001528 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001530 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001531def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001532 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001534 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535
Chris Lattnerc04cd042009-07-11 23:17:29 +00001536// In static codegen with small code model, we can get the address of a label
1537// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1538// the MOV64ri64i32 should accept these.
1539def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1540 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1541def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1542 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1543def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1544 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1545def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1546 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1547
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001548// In kernel code model, we can get the address of a label
1549// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1550// the MOV64ri32 should accept these.
1551def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1552 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1553def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1554 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1555def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1556 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1557def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1558 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001559
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001560// If we have small model and -static mode, it is safe to store global addresses
1561// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001562// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001563def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1564 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001565 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001566def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1567 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001568 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001569def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1570 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001571 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001572def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1573 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001574 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001575
1576// Calls
1577// Direct PC relative function call for small code model. 32-bit displacement
1578// sign extended to 64-bit.
1579def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001580 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001581def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001582 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1583
1584def : Pat<(X86call (i64 tglobaladdr:$dst)),
1585 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1586def : Pat<(X86call (i64 texternalsym:$dst)),
1587 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001588
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001589// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001590def : Pat<(X86tcret GR64:$dst, imm:$off),
1591 (TCRETURNri64 GR64:$dst, imm:$off)>;
1592
1593def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1594 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1595
1596def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1597 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1598
Dan Gohmanec596042007-09-17 14:35:24 +00001599// Comparisons.
1600
1601// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001602def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001603 (TEST64rr GR64:$src1, GR64:$src1)>;
1604
Dan Gohman0a3c5222009-01-07 01:00:24 +00001605// Conditional moves with folded loads with operands swapped and conditions
1606// inverted.
1607def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1608 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1609def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1610 (CMOVB64rm GR64:$src2, addr:$src1)>;
1611def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1612 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1613def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1614 (CMOVE64rm GR64:$src2, addr:$src1)>;
1615def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1616 (CMOVA64rm GR64:$src2, addr:$src1)>;
1617def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1618 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1619def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1620 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1621def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1622 (CMOVL64rm GR64:$src2, addr:$src1)>;
1623def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1624 (CMOVG64rm GR64:$src2, addr:$src1)>;
1625def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1626 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1627def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1628 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1629def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1630 (CMOVP64rm GR64:$src2, addr:$src1)>;
1631def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1632 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1633def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1634 (CMOVS64rm GR64:$src2, addr:$src1)>;
1635def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1636 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1637def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1638 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001639
Duncan Sands082524c2008-01-23 20:39:46 +00001640// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001641def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1642
1643// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001644// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1645// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1646// partial-register updates.
1647def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1648def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1649def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1650// For other extloads, use subregs, since the high contents of the register are
1651// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001652def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001653 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001654 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001655
Dan Gohman9959b052009-08-26 14:59:13 +00001656// anyext. Define these to do an explicit zero-extend to
1657// avoid partial-register updates.
1658def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1659def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1660def : Pat<(i64 (anyext GR32:$src)),
1661 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001662
1663//===----------------------------------------------------------------------===//
1664// Some peepholes
1665//===----------------------------------------------------------------------===//
1666
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001667// Odd encoding trick: -128 fits into an 8-bit immediate field while
1668// +128 doesn't, so in this special case use a sub instead of an add.
1669def : Pat<(add GR64:$src1, 128),
1670 (SUB64ri8 GR64:$src1, -128)>;
1671def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1672 (SUB64mi8 addr:$dst, -128)>;
1673
1674// The same trick applies for 32-bit immediate fields in 64-bit
1675// instructions.
1676def : Pat<(add GR64:$src1, 0x0000000080000000),
1677 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1678def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1679 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1680
Dan Gohman47a419d2008-08-07 02:54:50 +00001681// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001682def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001683 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001684// r & (2^16-1) ==> movz
1685def : Pat<(and GR64:$src, 0xffff),
1686 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1687// r & (2^8-1) ==> movz
1688def : Pat<(and GR64:$src, 0xff),
1689 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001690// r & (2^8-1) ==> movz
1691def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001692 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001693 Requires<[In64BitMode]>;
1694// r & (2^8-1) ==> movz
1695def : Pat<(and GR16:$src1, 0xff),
1696 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1697 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001698
Dan Gohmandd612bb2008-08-20 21:27:32 +00001699// sext_inreg patterns
1700def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001701 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001702def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001703 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001704def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001705 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001706def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001707 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001708 Requires<[In64BitMode]>;
1709def : Pat<(sext_inreg GR16:$src, i8),
1710 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1711 Requires<[In64BitMode]>;
1712
1713// trunc patterns
1714def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001715 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001716def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001717 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001718def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001719 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001720def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001721 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001722 Requires<[In64BitMode]>;
1723def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001724 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1725 Requires<[In64BitMode]>;
1726
1727// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001728// For now, be conservative on x86-64 and use an h-register extract only if the
1729// value is immediately zero-extended or stored, which are somewhat common
1730// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1731// from being allocated in the same instruction as the h register, as there's
1732// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001733
1734// h-register extract and zero-extend.
1735def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1736 (SUBREG_TO_REG
1737 (i64 0),
1738 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001739 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001740 x86_subreg_8bit_hi)),
1741 x86_subreg_32bit)>;
1742def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1743 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001744 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001745 x86_subreg_8bit_hi))>,
1746 Requires<[In64BitMode]>;
1747def : Pat<(srl_su GR16:$src, (i8 8)),
1748 (EXTRACT_SUBREG
1749 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001750 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001751 x86_subreg_8bit_hi)),
1752 x86_subreg_16bit)>,
1753 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001754def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1755 (MOVZX32_NOREXrr8
1756 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1757 x86_subreg_8bit_hi))>,
1758 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001759def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1760 (MOVZX32_NOREXrr8
1761 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1762 x86_subreg_8bit_hi))>,
1763 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001764def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1765 (SUBREG_TO_REG
1766 (i64 0),
1767 (MOVZX32_NOREXrr8
1768 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1769 x86_subreg_8bit_hi)),
1770 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001771def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1772 (SUBREG_TO_REG
1773 (i64 0),
1774 (MOVZX32_NOREXrr8
1775 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1776 x86_subreg_8bit_hi)),
1777 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001778
1779// h-register extract and store.
1780def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1781 (MOV8mr_NOREX
1782 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001783 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001784 x86_subreg_8bit_hi))>;
1785def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1786 (MOV8mr_NOREX
1787 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001788 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001789 x86_subreg_8bit_hi))>,
1790 Requires<[In64BitMode]>;
1791def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1792 (MOV8mr_NOREX
1793 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001794 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001795 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001796 Requires<[In64BitMode]>;
1797
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001798// (shl x, 1) ==> (add x, x)
1799def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1800
Evan Cheng76a64c72008-08-30 02:03:58 +00001801// (shl x (and y, 63)) ==> (shl x, y)
1802def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1803 (SHL64rCL GR64:$src1)>;
1804def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1805 (SHL64mCL addr:$dst)>;
1806
1807def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1808 (SHR64rCL GR64:$src1)>;
1809def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1810 (SHR64mCL addr:$dst)>;
1811
1812def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1813 (SAR64rCL GR64:$src1)>;
1814def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1815 (SAR64mCL addr:$dst)>;
1816
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001817// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1818def : Pat<(or (srl GR64:$src1, CL:$amt),
1819 (shl GR64:$src2, (sub 64, CL:$amt))),
1820 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1821
1822def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1823 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1824 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1825
Dan Gohman921581d2008-10-17 01:23:35 +00001826def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1827 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1828 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1829
1830def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1831 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1832 addr:$dst),
1833 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1834
1835def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1836 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1837
1838def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1839 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1840 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1841
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001842// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1843def : Pat<(or (shl GR64:$src1, CL:$amt),
1844 (srl GR64:$src2, (sub 64, CL:$amt))),
1845 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1846
1847def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1848 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1849 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1850
Dan Gohman921581d2008-10-17 01:23:35 +00001851def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1852 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1853 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1854
1855def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1856 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1857 addr:$dst),
1858 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1859
1860def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1861 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1862
1863def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1864 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1865 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1866
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001867// X86 specific add which produces a flag.
1868def : Pat<(addc GR64:$src1, GR64:$src2),
1869 (ADD64rr GR64:$src1, GR64:$src2)>;
1870def : Pat<(addc GR64:$src1, (load addr:$src2)),
1871 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001872def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1873 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001874def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1875 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001876
1877def : Pat<(subc GR64:$src1, GR64:$src2),
1878 (SUB64rr GR64:$src1, GR64:$src2)>;
1879def : Pat<(subc GR64:$src1, (load addr:$src2)),
1880 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001881def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1882 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001883def : Pat<(subc GR64:$src1, imm:$src2),
1884 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001885
Bill Wendlingf5399032008-12-12 21:15:41 +00001886//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001887// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001888//===----------------------------------------------------------------------===//
1889
Dan Gohman99a12192009-03-04 19:44:21 +00001890// Register-Register Addition with EFLAGS result
1891def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001892 (implicit EFLAGS)),
1893 (ADD64rr GR64:$src1, GR64:$src2)>;
1894
Dan Gohman99a12192009-03-04 19:44:21 +00001895// Register-Integer Addition with EFLAGS result
1896def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001897 (implicit EFLAGS)),
1898 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001899def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001900 (implicit EFLAGS)),
1901 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001902
Dan Gohman99a12192009-03-04 19:44:21 +00001903// Register-Memory Addition with EFLAGS result
1904def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001905 (implicit EFLAGS)),
1906 (ADD64rm GR64:$src1, addr:$src2)>;
1907
Dan Gohman99a12192009-03-04 19:44:21 +00001908// Memory-Register Addition with EFLAGS result
1909def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001910 addr:$dst),
1911 (implicit EFLAGS)),
1912 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001913def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001914 addr:$dst),
1915 (implicit EFLAGS)),
1916 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001917def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001918 addr:$dst),
1919 (implicit EFLAGS)),
1920 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001921
Dan Gohman99a12192009-03-04 19:44:21 +00001922// Register-Register Subtraction with EFLAGS result
1923def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001924 (implicit EFLAGS)),
1925 (SUB64rr GR64:$src1, GR64:$src2)>;
1926
Dan Gohman99a12192009-03-04 19:44:21 +00001927// Register-Memory Subtraction with EFLAGS result
1928def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001929 (implicit EFLAGS)),
1930 (SUB64rm GR64:$src1, addr:$src2)>;
1931
Dan Gohman99a12192009-03-04 19:44:21 +00001932// Register-Integer Subtraction with EFLAGS result
1933def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001934 (implicit EFLAGS)),
1935 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001936def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001937 (implicit EFLAGS)),
1938 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001939
Dan Gohman99a12192009-03-04 19:44:21 +00001940// Memory-Register Subtraction with EFLAGS result
1941def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001942 addr:$dst),
1943 (implicit EFLAGS)),
1944 (SUB64mr addr:$dst, GR64:$src2)>;
1945
Dan Gohman99a12192009-03-04 19:44:21 +00001946// Memory-Integer Subtraction with EFLAGS result
1947def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001948 addr:$dst),
1949 (implicit EFLAGS)),
1950 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001951def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001952 addr:$dst),
1953 (implicit EFLAGS)),
1954 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001955
Dan Gohman99a12192009-03-04 19:44:21 +00001956// Register-Register Signed Integer Multiplication with EFLAGS result
1957def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001958 (implicit EFLAGS)),
1959 (IMUL64rr GR64:$src1, GR64:$src2)>;
1960
Dan Gohman99a12192009-03-04 19:44:21 +00001961// Register-Memory Signed Integer Multiplication with EFLAGS result
1962def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001963 (implicit EFLAGS)),
1964 (IMUL64rm GR64:$src1, addr:$src2)>;
1965
Dan Gohman99a12192009-03-04 19:44:21 +00001966// Register-Integer Signed Integer Multiplication with EFLAGS result
1967def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001968 (implicit EFLAGS)),
1969 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001970def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001971 (implicit EFLAGS)),
1972 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001973
Dan Gohman99a12192009-03-04 19:44:21 +00001974// Memory-Integer Signed Integer Multiplication with EFLAGS result
1975def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001976 (implicit EFLAGS)),
1977 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001978def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001979 (implicit EFLAGS)),
1980 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001981
Dan Gohman99a12192009-03-04 19:44:21 +00001982// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001983def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1984 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1985def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1986 (implicit EFLAGS)),
1987 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1988def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1989 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1990def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1991 (implicit EFLAGS)),
1992 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1993
1994def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1995 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1996def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1997 (implicit EFLAGS)),
1998 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1999def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
2000 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2001def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2002 (implicit EFLAGS)),
2003 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2004
Dan Gohman99a12192009-03-04 19:44:21 +00002005def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2006 (INC64r GR64:$src)>;
2007def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2008 (implicit EFLAGS)),
2009 (INC64m addr:$dst)>;
2010def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2011 (DEC64r GR64:$src)>;
2012def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2013 (implicit EFLAGS)),
2014 (DEC64m addr:$dst)>;
2015
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002016//===----------------------------------------------------------------------===//
2017// X86-64 SSE Instructions
2018//===----------------------------------------------------------------------===//
2019
2020// Move instructions...
2021
Evan Chengb783fa32007-07-19 01:14:50 +00002022def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002023 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002024 [(set VR128:$dst,
2025 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002026def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002027 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002028 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2029 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002030
Evan Chengb783fa32007-07-19 01:14:50 +00002031def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002032 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002033 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002034def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002035 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002036 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2037
Evan Chengb783fa32007-07-19 01:14:50 +00002038def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002039 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002040 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002041def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002042 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002043 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002044
2045//===----------------------------------------------------------------------===//
2046// X86-64 SSE4.1 Instructions
2047//===----------------------------------------------------------------------===//
2048
Nate Begeman4294c1f2008-02-12 22:51:28 +00002049/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2050multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002051 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002052 (ins VR128:$src1, i32i8imm:$src2),
2053 !strconcat(OpcodeStr,
2054 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2055 [(set GR64:$dst,
2056 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002057 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002058 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2059 !strconcat(OpcodeStr,
2060 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2061 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2062 addr:$dst)]>, OpSize, REX_W;
2063}
2064
2065defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2066
2067let isTwoAddress = 1 in {
2068 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002069 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002070 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2071 !strconcat(OpcodeStr,
2072 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2073 [(set VR128:$dst,
2074 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2075 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002076 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002077 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2078 !strconcat(OpcodeStr,
2079 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2080 [(set VR128:$dst,
2081 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2082 imm:$src3)))]>, OpSize, REX_W;
2083 }
2084}
2085
2086defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002087
2088// -disable-16bit support.
2089def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2090 (MOV16mi addr:$dst, imm:$src)>;
2091def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2092 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2093def : Pat<(i64 (sextloadi16 addr:$dst)),
2094 (MOVSX64rm16 addr:$dst)>;
2095def : Pat<(i64 (zextloadi16 addr:$dst)),
2096 (MOVZX64rm16 addr:$dst)>;
2097def : Pat<(i64 (extloadi16 addr:$dst)),
2098 (MOVZX64rm16 addr:$dst)>;