blob: 948b1ca4abb2236ce2c1b4d4ec66cb1292fca55b [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
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000287// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000288def SYSEXIT64 : RI<0x35, RawFrm,
289 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000290
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291//===----------------------------------------------------------------------===//
292// Move Instructions...
293//
294
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000295let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000296def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000297 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298
Evan Chengd2b9d302008-06-25 01:16:38 +0000299let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000300def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000301 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000303def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000304 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000306}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307
Dan Gohman5574cc72008-12-03 18:15:48 +0000308let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000309def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000310 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 [(set GR64:$dst, (load addr:$src))]>;
312
Evan Chengb783fa32007-07-19 01:14:50 +0000313def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000314 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000316def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000317 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318 [(store i64immSExt32:$src, addr:$dst)]>;
319
320// Sign/Zero extenders
321
Dan Gohmanedde1992009-04-13 15:13:28 +0000322// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
323// operand, which makes it a rare instruction with an 8-bit register
324// operand that can never access an h register. If support for h registers
325// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000326def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000332def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000333 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000335def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000336 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000338def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000339 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000341def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000342 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
344
Dan Gohman9203ab42008-07-30 18:09:17 +0000345// Use movzbl instead of movzbq when the destination is a register; it's
346// equivalent due to implicit zero-extending, and it has a smaller encoding.
347def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
348 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
349 [(set GR64:$dst, (zext GR8:$src))]>, TB;
350def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
351 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
352 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
353// Use movzwl instead of movzwq when the destination is a register; it's
354// equivalent due to implicit zero-extending, and it has a smaller encoding.
355def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
356 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
357 [(set GR64:$dst, (zext GR16:$src))]>, TB;
358def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
359 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
360 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361
Dan Gohman47a419d2008-08-07 02:54:50 +0000362// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000363// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
364// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
365// zero-extension, however this isn't possible when the 32-bit value is
366// defined by a truncate or is copied from something where the high bits aren't
367// necessarily all zero. In such cases, we fall back to these explicit zext
368// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000369def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
370 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
371 [(set GR64:$dst, (zext GR32:$src))]>;
372def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
373 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
374 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
375
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000376// Any instruction that defines a 32-bit result leaves the high half of the
377// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
378// be copying from a truncate, but any other 32-bit operation will zero-extend
379// up to 64 bits.
380def def32 : PatLeaf<(i32 GR32:$src), [{
381 return N->getOpcode() != ISD::TRUNCATE &&
382 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
383 N->getOpcode() != ISD::CopyFromReg;
384}]>;
385
386// In the case of a 32-bit def that is known to implicitly zero-extend,
387// we can use a SUBREG_TO_REG.
388def : Pat<(i64 (zext def32:$src)),
389 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
390
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000391let neverHasSideEffects = 1 in {
392 let Defs = [RAX], Uses = [EAX] in
393 def CDQE : RI<0x98, RawFrm, (outs), (ins),
394 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000396 let Defs = [RAX,RDX], Uses = [RAX] in
397 def CQO : RI<0x99, RawFrm, (outs), (ins),
398 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
399}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400
401//===----------------------------------------------------------------------===//
402// Arithmetic Instructions...
403//
404
Evan Cheng55687072007-09-14 21:48:26 +0000405let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000406
407def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
408 "add{q}\t{$src, %rax|%rax, $src}", []>;
409
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410let isTwoAddress = 1 in {
411let isConvertibleToThreeAddress = 1 in {
412let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000413// Register-Register Addition
414def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
415 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000416 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000417 (implicit EFLAGS)]>;
418
419// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000420def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
421 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000422 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
423 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000424def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
425 "add{q}\t{$src2, $dst|$dst, $src2}",
426 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
427 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428} // isConvertibleToThreeAddress
429
Bill Wendlingae034ed2008-12-12 00:56:36 +0000430// Register-Memory Addition
431def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
432 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000433 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000434 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435} // isTwoAddress
436
Bill Wendlingae034ed2008-12-12 00:56:36 +0000437// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000438def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000439 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000440 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
441 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000442def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000444 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
445 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000446def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
447 "add{q}\t{$src2, $dst|$dst, $src2}",
448 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
449 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450
Evan Cheng259471d2007-10-05 17:59:57 +0000451let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452let isTwoAddress = 1 in {
453let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000454def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000455 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000456 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457
Dale Johannesen747fe522009-06-02 03:12:52 +0000458def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000460 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461
Dale Johannesen747fe522009-06-02 03:12:52 +0000462def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000463 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000464 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
465def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000466 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000467 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468} // isTwoAddress
469
Evan Chengb783fa32007-07-19 01:14:50 +0000470def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000471 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000472 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000473def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000474 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000475 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000476def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
477 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000478 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000479} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480
481let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000482// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000483def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000484 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000485 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
486 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000487
488// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000489def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000490 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000491 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
492 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000493
494// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000495def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
496 (ins GR64:$src1, i64i8imm:$src2),
497 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000498 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
499 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000500def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
501 (ins GR64:$src1, i64i32imm:$src2),
502 "sub{q}\t{$src2, $dst|$dst, $src2}",
503 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
504 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505} // isTwoAddress
506
Bill Wendlingae034ed2008-12-12 00:56:36 +0000507// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000508def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000509 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000510 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
511 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000512
513// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000514def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000515 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000516 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000517 addr:$dst),
518 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000519def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
520 "sub{q}\t{$src2, $dst|$dst, $src2}",
521 [(store (sub (load addr:$dst), i64immSExt32:$src2),
522 addr:$dst),
523 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524
Evan Cheng259471d2007-10-05 17:59:57 +0000525let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000527def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000528 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000529 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530
Dale Johannesen747fe522009-06-02 03:12:52 +0000531def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000532 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000533 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
Dale Johannesen747fe522009-06-02 03:12:52 +0000535def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000536 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000537 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
538def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000539 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000540 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541} // isTwoAddress
542
Evan Chengb783fa32007-07-19 01:14:50 +0000543def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000544 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000545 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000546def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000547 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000548 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000549def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
550 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000551 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000552} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000553} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554
555// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000556let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000557def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000558 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000559let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000560def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000561 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562
563// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000564def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000565 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000566let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000567def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000568 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
569}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
Evan Cheng55687072007-09-14 21:48:26 +0000571let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572let isTwoAddress = 1 in {
573let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000574// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000575def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
576 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000577 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000578 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
579 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580
Bill Wendlingf5399032008-12-12 21:15:41 +0000581// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000582def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
583 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000584 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000585 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
586 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000587} // isTwoAddress
588
589// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000590
Bill Wendlingf5399032008-12-12 21:15:41 +0000591// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000593 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000594 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000595 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
596 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000597def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
598 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
599 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
600 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
601 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000602
Bill Wendlingf5399032008-12-12 21:15:41 +0000603// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000605 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000606 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000607 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000608 i64immSExt8:$src2)),
609 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000610def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
611 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
612 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
613 [(set GR64:$dst, (mul (load addr:$src1),
614 i64immSExt32:$src2)),
615 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000616} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000619let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000620def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000621 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000623def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000624 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000625let mayLoad = 1 in {
626def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
627 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000628def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000629 "idiv{q}\t$src", []>;
630}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000631}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632
633// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000634let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000636def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000637 [(set GR64:$dst, (ineg GR64:$src)),
638 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000639def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000640 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
641 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642
643let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000644def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000645 [(set GR64:$dst, (add GR64:$src, 1)),
646 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000647def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000648 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
649 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000650
651let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000652def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000653 [(set GR64:$dst, (add GR64:$src, -1)),
654 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000655def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000656 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
657 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658
659// In 64-bit mode, single byte INC and DEC cannot be encoded.
660let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
661// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000662def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000663 [(set GR16:$dst, (add GR16:$src, 1)),
664 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000666def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000667 [(set GR32:$dst, (add GR32:$src, 1)),
668 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000670def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000671 [(set GR16:$dst, (add GR16:$src, -1)),
672 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000674def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000675 [(set GR32:$dst, (add GR32:$src, -1)),
676 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 Requires<[In64BitMode]>;
678} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000679
680// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
681// how to unfold them.
682let isTwoAddress = 0, CodeSize = 2 in {
683 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000684 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
685 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000686 OpSize, Requires<[In64BitMode]>;
687 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000688 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
689 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000690 Requires<[In64BitMode]>;
691 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000692 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
693 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000694 OpSize, Requires<[In64BitMode]>;
695 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000696 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
697 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000698 Requires<[In64BitMode]>;
699}
Evan Cheng55687072007-09-14 21:48:26 +0000700} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701
702
Evan Cheng55687072007-09-14 21:48:26 +0000703let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704// Shift instructions
705let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000706let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000707def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000709 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000710let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000714// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
715// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716} // isTwoAddress
717
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000718let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000719def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000720 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000721 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000722def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000725def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000726 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
728
729let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000730let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000731def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000732 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000733 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000737def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000738 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
740} // isTwoAddress
741
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000742let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000745 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000749def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000750 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
752
753let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000754let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000755def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000757 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000758def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000761def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000763 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
764} // isTwoAddress
765
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000766let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000767def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000768 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000769 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000770def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000771 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000773def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000774 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000775 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
776
777// Rotate instructions
778let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000779let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000780def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000781 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000782 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000783def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000786def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000787 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000788 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
789} // isTwoAddress
790
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000791let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000792def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000793 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000794 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000795def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000798def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000799 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
801
802let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000804def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000806 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000807def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000810def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000811 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
813} // isTwoAddress
814
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000815let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000816def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000817 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000818 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000819def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000820 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000822def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000823 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
825
826// Double shift instructions (generalizations of rotate)
827let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000828let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000829def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000830 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
831 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000832def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000833 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
834 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000835}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836
837let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
838def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000839 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000840 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
841 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
842 (i8 imm:$src3)))]>,
843 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000844def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000845 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000846 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
847 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
848 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849 TB;
850} // isCommutable
851} // isTwoAddress
852
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000853let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000854def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000855 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
856 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
857 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000858def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000859 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
860 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
861 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000862}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000863def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000864 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000865 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
866 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
867 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868 TB;
869def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000870 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000871 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
872 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
873 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000875} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000876
877//===----------------------------------------------------------------------===//
878// Logical Instructions...
879//
880
Evan Cheng5b51c242009-01-21 19:45:31 +0000881let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000882def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000884def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
886
Evan Cheng55687072007-09-14 21:48:26 +0000887let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000888def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
889 "and{q}\t{$src, %rax|%rax, $src}", []>;
890
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891let isTwoAddress = 1 in {
892let isCommutable = 1 in
893def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000894 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000895 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000896 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
897 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000899 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000900 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000901 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
902 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000904 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000906 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
907 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000908def AND64ri32 : RIi32<0x81, MRM4r,
909 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
910 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000911 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
912 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913} // isTwoAddress
914
915def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000916 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000917 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000918 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
919 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000921 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000922 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000923 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
924 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000925def AND64mi32 : RIi32<0x81, MRM4m,
926 (outs), (ins i64mem:$dst, i64i32imm:$src),
927 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000928 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
929 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930
931let isTwoAddress = 1 in {
932let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000933def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000935 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
936 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000937def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000939 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
940 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000941def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
944 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000945def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
946 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000947 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
948 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949} // isTwoAddress
950
Evan Chengb783fa32007-07-19 01:14:50 +0000951def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000952 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000953 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
954 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000955def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000956 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000957 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
958 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000959def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
960 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000961 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
962 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963
964let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000965let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000966def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000967 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000968 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
969 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000970def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000972 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
973 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000974def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
975 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000976 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
977 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000979 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000981 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
982 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000983} // isTwoAddress
984
Evan Chengb783fa32007-07-19 01:14:50 +0000985def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000986 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000987 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
988 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000989def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000990 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000991 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
992 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000993def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
994 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000995 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
996 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000997} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000998
999//===----------------------------------------------------------------------===//
1000// Comparison Instructions...
1001//
1002
1003// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001004let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001005def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1006 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001008def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001009 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001010 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1011 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001012def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001013 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001014 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1015 (implicit EFLAGS)]>;
1016def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1017 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001018 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001019 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1020 (implicit EFLAGS)]>;
1021def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1022 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001023 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001024 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1025 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026
Sean Callanan251676e2009-09-02 00:55:49 +00001027
1028def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1029 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001030def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001031 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001032 [(X86cmp GR64:$src1, GR64:$src2),
1033 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001034def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001035 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001036 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1037 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001038def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001039 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001040 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1041 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001042def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1043 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1044 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1045 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001046def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001047 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001048 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001049 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001050def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001051 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001052 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001053 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001054def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1055 (ins i64mem:$src1, i64i32imm:$src2),
1056 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1057 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1058 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001059} // Defs = [EFLAGS]
1060
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001061// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001062// TODO: BTC, BTR, and BTS
1063let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001064def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001065 "bt{q}\t{$src2, $src1|$src1, $src2}",
1066 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001067 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001068
1069// Unlike with the register+register form, the memory+register form of the
1070// bt instruction does not ignore the high bits of the index. From ISel's
1071// perspective, this is pretty bizarre. Disable these instructions for now.
1072//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1073// "bt{q}\t{$src2, $src1|$src1, $src2}",
1074// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1075// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001076
1077def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1078 "bt{q}\t{$src2, $src1|$src1, $src2}",
1079 [(X86bt GR64:$src1, i64immSExt8:$src2),
1080 (implicit EFLAGS)]>, TB;
1081// Note that these instructions don't need FastBTMem because that
1082// only applies when the other operand is in a register. When it's
1083// an immediate, bt is still fast.
1084def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1085 "bt{q}\t{$src2, $src1|$src1, $src2}",
1086 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1087 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001088} // Defs = [EFLAGS]
1089
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001091let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001092let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001094 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001097 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001099 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001100 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001102 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001104 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001105 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001107 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001108def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001109 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001110 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001112 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001114 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001115 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001117 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001119 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001120 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001122 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001124 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001125 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001127 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001129 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001130 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001132 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001134 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001137 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001139 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001140 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001142 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001144 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001145 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001147 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001148def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001149 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001150 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001152 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001154 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001155 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001156 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001157 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001158def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001159 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001160 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001162 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001163def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1164 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1165 "cmovo\t{$src2, $dst|$dst, $src2}",
1166 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1167 X86_COND_O, EFLAGS))]>, TB;
1168def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1169 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1170 "cmovno\t{$src2, $dst|$dst, $src2}",
1171 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1172 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001173} // isCommutable = 1
1174
1175def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1176 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1177 "cmovb\t{$src2, $dst|$dst, $src2}",
1178 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1179 X86_COND_B, EFLAGS))]>, TB;
1180def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1181 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1182 "cmovae\t{$src2, $dst|$dst, $src2}",
1183 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1184 X86_COND_AE, EFLAGS))]>, TB;
1185def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1186 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1187 "cmove\t{$src2, $dst|$dst, $src2}",
1188 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1189 X86_COND_E, EFLAGS))]>, TB;
1190def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1191 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1192 "cmovne\t{$src2, $dst|$dst, $src2}",
1193 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1194 X86_COND_NE, EFLAGS))]>, TB;
1195def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1196 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1197 "cmovbe\t{$src2, $dst|$dst, $src2}",
1198 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1199 X86_COND_BE, EFLAGS))]>, TB;
1200def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1201 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1202 "cmova\t{$src2, $dst|$dst, $src2}",
1203 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1204 X86_COND_A, EFLAGS))]>, TB;
1205def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1206 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1207 "cmovl\t{$src2, $dst|$dst, $src2}",
1208 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1209 X86_COND_L, EFLAGS))]>, TB;
1210def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1211 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1212 "cmovge\t{$src2, $dst|$dst, $src2}",
1213 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1214 X86_COND_GE, EFLAGS))]>, TB;
1215def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1216 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1217 "cmovle\t{$src2, $dst|$dst, $src2}",
1218 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1219 X86_COND_LE, EFLAGS))]>, TB;
1220def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1221 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1222 "cmovg\t{$src2, $dst|$dst, $src2}",
1223 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1224 X86_COND_G, EFLAGS))]>, TB;
1225def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1226 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1227 "cmovs\t{$src2, $dst|$dst, $src2}",
1228 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1229 X86_COND_S, EFLAGS))]>, TB;
1230def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1231 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1232 "cmovns\t{$src2, $dst|$dst, $src2}",
1233 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1234 X86_COND_NS, EFLAGS))]>, TB;
1235def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1236 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1237 "cmovp\t{$src2, $dst|$dst, $src2}",
1238 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1239 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001241 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001242 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001244 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001245def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1246 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1247 "cmovo\t{$src2, $dst|$dst, $src2}",
1248 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1249 X86_COND_O, EFLAGS))]>, TB;
1250def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1251 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1252 "cmovno\t{$src2, $dst|$dst, $src2}",
1253 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1254 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001255} // isTwoAddress
1256
1257//===----------------------------------------------------------------------===//
1258// Conversion Instructions...
1259//
1260
1261// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001262def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001263 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001264 [(set GR64:$dst,
1265 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001266def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001267 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001268 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1269 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001270def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001273def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001274 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001275 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001276def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001277 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001278 [(set GR64:$dst,
1279 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001280def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001281 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001282 [(set GR64:$dst,
1283 (int_x86_sse2_cvttsd2si64
1284 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001285
1286// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001287def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001288 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001290def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001292 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001293
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001294let isTwoAddress = 1 in {
1295def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001296 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001298 [(set VR128:$dst,
1299 (int_x86_sse2_cvtsi642sd VR128:$src1,
1300 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001302 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001303 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001304 [(set VR128:$dst,
1305 (int_x86_sse2_cvtsi642sd VR128:$src1,
1306 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001307} // isTwoAddress
1308
1309// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001310def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001311 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001313def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001314 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001315 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001316
1317let isTwoAddress = 1 in {
1318 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1319 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1320 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1321 [(set VR128:$dst,
1322 (int_x86_sse_cvtsi642ss VR128:$src1,
1323 GR64:$src2))]>;
1324 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1325 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1326 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1327 [(set VR128:$dst,
1328 (int_x86_sse_cvtsi642ss VR128:$src1,
1329 (loadi64 addr:$src2)))]>;
1330}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001331
1332// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001333def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001334 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001335 [(set GR64:$dst,
1336 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001337def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001338 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001339 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1340 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001341def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001342 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001343 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001344def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001345 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001346 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001347def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001348 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001349 [(set GR64:$dst,
1350 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001351def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001352 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001353 [(set GR64:$dst,
1354 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1355
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001356//===----------------------------------------------------------------------===//
1357// Alias Instructions
1358//===----------------------------------------------------------------------===//
1359
Dan Gohman027cd112007-09-17 14:55:08 +00001360// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1361// equivalent due to implicit zero-extending, and it sometimes has a smaller
1362// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001363// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001365let AddedComplexity = 1 in
1366def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001367 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001368
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001369
1370// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001371let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001372def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001373 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001374 [(set GR64:$dst, i64immZExt32:$src)]>;
1375
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001376//===----------------------------------------------------------------------===//
1377// Thread Local Storage Instructions
1378//===----------------------------------------------------------------------===//
1379
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001380// All calls clobber the non-callee saved registers. RSP is marked as
1381// a use to prevent stack-pointer assignments that appear immediately
1382// before calls from potentially appearing dead.
1383let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1384 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1385 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1386 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1387 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1388 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001389def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001390 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001391 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001392 ".word\t0x6666; "
1393 "rex64; "
1394 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001395 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001396 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001397
Daniel Dunbar75a07302009-08-11 22:24:40 +00001398let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001399def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1400 "movq\t%gs:$src, $dst",
1401 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1402
Daniel Dunbar75a07302009-08-11 22:24:40 +00001403let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001404def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1405 "movq\t%fs:$src, $dst",
1406 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1407
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001408//===----------------------------------------------------------------------===//
1409// Atomic Instructions
1410//===----------------------------------------------------------------------===//
1411
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001412let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001413def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001414 "lock\n\t"
1415 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001416 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1417}
1418
Dan Gohmana41a1c092008-08-06 15:52:50 +00001419let Constraints = "$val = $dst" in {
1420let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001421def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001422 "lock\n\t"
1423 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001424 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001425 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001426
Evan Chenga1e80602008-04-19 02:05:42 +00001427def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001428 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001429 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001430}
1431
Evan Chengb723fb52009-07-30 08:33:02 +00001432// Optimized codegen when the non-memory output is not used.
1433// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1434def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1435 "lock\n\t"
1436 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1437def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1438 (ins i64mem:$dst, i64i8imm :$src2),
1439 "lock\n\t"
1440 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1441def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1442 (ins i64mem:$dst, i64i32imm :$src2),
1443 "lock\n\t"
1444 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1445def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1446 "lock\n\t"
1447 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1448def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1449 (ins i64mem:$dst, i64i8imm :$src2),
1450 "lock\n\t"
1451 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1452def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1453 (ins i64mem:$dst, i64i32imm:$src2),
1454 "lock\n\t"
1455 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1456def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1457 "lock\n\t"
1458 "inc{q}\t$dst", []>, LOCK;
1459def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1460 "lock\n\t"
1461 "dec{q}\t$dst", []>, LOCK;
1462
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001463// Atomic exchange, and, or, xor
1464let Constraints = "$val = $dst", Defs = [EFLAGS],
1465 usesCustomDAGSchedInserter = 1 in {
1466def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001467 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001468 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001469def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001470 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001471 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001472def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001473 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001474 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001475def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001476 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001477 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001478def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001479 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001480 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001481def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001482 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001483 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001484def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001485 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001486 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001487def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001488 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001489 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001490}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001491
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001492//===----------------------------------------------------------------------===//
1493// Non-Instruction Patterns
1494//===----------------------------------------------------------------------===//
1495
Chris Lattner0d2dad62009-07-11 22:50:33 +00001496// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1497// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1498// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001499def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001500 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001501def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001502 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001503def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001504 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001505def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001506 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001507
Chris Lattnerc04cd042009-07-11 23:17:29 +00001508// In static codegen with small code model, we can get the address of a label
1509// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1510// the MOV64ri64i32 should accept these.
1511def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1512 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1513def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1514 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1515def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1516 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1517def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1518 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1519
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001520// In kernel code model, we can get the address of a label
1521// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1522// the MOV64ri32 should accept these.
1523def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1524 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1525def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1526 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1527def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1528 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1529def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1530 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001531
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001532// If we have small model and -static mode, it is safe to store global addresses
1533// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001534// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1536 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001537 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1539 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001540 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001541def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1542 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001543 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001544def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1545 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001546 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001547
1548// Calls
1549// Direct PC relative function call for small code model. 32-bit displacement
1550// sign extended to 64-bit.
1551def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001552 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001553def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001554 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1555
1556def : Pat<(X86call (i64 tglobaladdr:$dst)),
1557 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1558def : Pat<(X86call (i64 texternalsym:$dst)),
1559 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001560
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001561// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001562def : Pat<(X86tcret GR64:$dst, imm:$off),
1563 (TCRETURNri64 GR64:$dst, imm:$off)>;
1564
1565def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1566 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1567
1568def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1569 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1570
Dan Gohmanec596042007-09-17 14:35:24 +00001571// Comparisons.
1572
1573// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001574def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001575 (TEST64rr GR64:$src1, GR64:$src1)>;
1576
Dan Gohman0a3c5222009-01-07 01:00:24 +00001577// Conditional moves with folded loads with operands swapped and conditions
1578// inverted.
1579def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1580 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1581def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1582 (CMOVB64rm GR64:$src2, addr:$src1)>;
1583def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1584 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1585def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1586 (CMOVE64rm GR64:$src2, addr:$src1)>;
1587def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1588 (CMOVA64rm GR64:$src2, addr:$src1)>;
1589def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1590 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1591def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1592 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1593def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1594 (CMOVL64rm GR64:$src2, addr:$src1)>;
1595def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1596 (CMOVG64rm GR64:$src2, addr:$src1)>;
1597def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1598 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1599def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1600 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1601def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1602 (CMOVP64rm GR64:$src2, addr:$src1)>;
1603def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1604 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1605def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1606 (CMOVS64rm GR64:$src2, addr:$src1)>;
1607def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1608 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1609def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1610 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001611
Duncan Sands082524c2008-01-23 20:39:46 +00001612// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001613def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1614
1615// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001616// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1617// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1618// partial-register updates.
1619def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1620def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1621def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1622// For other extloads, use subregs, since the high contents of the register are
1623// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001624def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001625 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001626 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001627
Dan Gohman9959b052009-08-26 14:59:13 +00001628// anyext. Define these to do an explicit zero-extend to
1629// avoid partial-register updates.
1630def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1631def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1632def : Pat<(i64 (anyext GR32:$src)),
1633 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001634
1635//===----------------------------------------------------------------------===//
1636// Some peepholes
1637//===----------------------------------------------------------------------===//
1638
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001639// Odd encoding trick: -128 fits into an 8-bit immediate field while
1640// +128 doesn't, so in this special case use a sub instead of an add.
1641def : Pat<(add GR64:$src1, 128),
1642 (SUB64ri8 GR64:$src1, -128)>;
1643def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1644 (SUB64mi8 addr:$dst, -128)>;
1645
1646// The same trick applies for 32-bit immediate fields in 64-bit
1647// instructions.
1648def : Pat<(add GR64:$src1, 0x0000000080000000),
1649 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1650def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1651 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1652
Dan Gohman47a419d2008-08-07 02:54:50 +00001653// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001654def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001655 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001656// r & (2^16-1) ==> movz
1657def : Pat<(and GR64:$src, 0xffff),
1658 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1659// r & (2^8-1) ==> movz
1660def : Pat<(and GR64:$src, 0xff),
1661 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001662// r & (2^8-1) ==> movz
1663def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001664 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001665 Requires<[In64BitMode]>;
1666// r & (2^8-1) ==> movz
1667def : Pat<(and GR16:$src1, 0xff),
1668 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1669 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001670
Dan Gohmandd612bb2008-08-20 21:27:32 +00001671// sext_inreg patterns
1672def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001673 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001674def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001675 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001676def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001677 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001678def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001679 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001680 Requires<[In64BitMode]>;
1681def : Pat<(sext_inreg GR16:$src, i8),
1682 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1683 Requires<[In64BitMode]>;
1684
1685// trunc patterns
1686def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001687 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001688def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001689 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001690def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001691 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001692def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001693 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001694 Requires<[In64BitMode]>;
1695def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001696 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1697 Requires<[In64BitMode]>;
1698
1699// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001700// For now, be conservative on x86-64 and use an h-register extract only if the
1701// value is immediately zero-extended or stored, which are somewhat common
1702// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1703// from being allocated in the same instruction as the h register, as there's
1704// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001705
1706// h-register extract and zero-extend.
1707def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1708 (SUBREG_TO_REG
1709 (i64 0),
1710 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001711 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001712 x86_subreg_8bit_hi)),
1713 x86_subreg_32bit)>;
1714def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1715 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001716 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001717 x86_subreg_8bit_hi))>,
1718 Requires<[In64BitMode]>;
1719def : Pat<(srl_su GR16:$src, (i8 8)),
1720 (EXTRACT_SUBREG
1721 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001722 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001723 x86_subreg_8bit_hi)),
1724 x86_subreg_16bit)>,
1725 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001726def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1727 (MOVZX32_NOREXrr8
1728 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1729 x86_subreg_8bit_hi))>,
1730 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001731def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1732 (MOVZX32_NOREXrr8
1733 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1734 x86_subreg_8bit_hi))>,
1735 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001736def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1737 (SUBREG_TO_REG
1738 (i64 0),
1739 (MOVZX32_NOREXrr8
1740 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1741 x86_subreg_8bit_hi)),
1742 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001743def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1744 (SUBREG_TO_REG
1745 (i64 0),
1746 (MOVZX32_NOREXrr8
1747 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1748 x86_subreg_8bit_hi)),
1749 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001750
1751// h-register extract and store.
1752def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1753 (MOV8mr_NOREX
1754 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001755 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001756 x86_subreg_8bit_hi))>;
1757def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1758 (MOV8mr_NOREX
1759 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001760 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001761 x86_subreg_8bit_hi))>,
1762 Requires<[In64BitMode]>;
1763def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1764 (MOV8mr_NOREX
1765 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001766 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001767 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001768 Requires<[In64BitMode]>;
1769
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001770// (shl x, 1) ==> (add x, x)
1771def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1772
Evan Cheng76a64c72008-08-30 02:03:58 +00001773// (shl x (and y, 63)) ==> (shl x, y)
1774def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1775 (SHL64rCL GR64:$src1)>;
1776def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1777 (SHL64mCL addr:$dst)>;
1778
1779def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1780 (SHR64rCL GR64:$src1)>;
1781def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1782 (SHR64mCL addr:$dst)>;
1783
1784def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1785 (SAR64rCL GR64:$src1)>;
1786def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1787 (SAR64mCL addr:$dst)>;
1788
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001789// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1790def : Pat<(or (srl GR64:$src1, CL:$amt),
1791 (shl GR64:$src2, (sub 64, CL:$amt))),
1792 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1793
1794def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1795 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1796 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1797
Dan Gohman921581d2008-10-17 01:23:35 +00001798def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1799 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1800 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1801
1802def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1803 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1804 addr:$dst),
1805 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1806
1807def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1808 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1809
1810def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1811 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1812 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1813
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001814// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1815def : Pat<(or (shl GR64:$src1, CL:$amt),
1816 (srl GR64:$src2, (sub 64, CL:$amt))),
1817 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1818
1819def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1820 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1821 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1822
Dan Gohman921581d2008-10-17 01:23:35 +00001823def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1824 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1825 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1826
1827def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1828 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1829 addr:$dst),
1830 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1831
1832def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1833 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1834
1835def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1836 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1837 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1838
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001839// X86 specific add which produces a flag.
1840def : Pat<(addc GR64:$src1, GR64:$src2),
1841 (ADD64rr GR64:$src1, GR64:$src2)>;
1842def : Pat<(addc GR64:$src1, (load addr:$src2)),
1843 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001844def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1845 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001846def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1847 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001848
1849def : Pat<(subc GR64:$src1, GR64:$src2),
1850 (SUB64rr GR64:$src1, GR64:$src2)>;
1851def : Pat<(subc GR64:$src1, (load addr:$src2)),
1852 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001853def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1854 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001855def : Pat<(subc GR64:$src1, imm:$src2),
1856 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001857
Bill Wendlingf5399032008-12-12 21:15:41 +00001858//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001859// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001860//===----------------------------------------------------------------------===//
1861
Dan Gohman99a12192009-03-04 19:44:21 +00001862// Register-Register Addition with EFLAGS result
1863def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001864 (implicit EFLAGS)),
1865 (ADD64rr GR64:$src1, GR64:$src2)>;
1866
Dan Gohman99a12192009-03-04 19:44:21 +00001867// Register-Integer Addition with EFLAGS result
1868def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001869 (implicit EFLAGS)),
1870 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001871def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001872 (implicit EFLAGS)),
1873 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001874
Dan Gohman99a12192009-03-04 19:44:21 +00001875// Register-Memory Addition with EFLAGS result
1876def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001877 (implicit EFLAGS)),
1878 (ADD64rm GR64:$src1, addr:$src2)>;
1879
Dan Gohman99a12192009-03-04 19:44:21 +00001880// Memory-Register Addition with EFLAGS result
1881def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001882 addr:$dst),
1883 (implicit EFLAGS)),
1884 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001885def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001886 addr:$dst),
1887 (implicit EFLAGS)),
1888 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001889def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001890 addr:$dst),
1891 (implicit EFLAGS)),
1892 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001893
Dan Gohman99a12192009-03-04 19:44:21 +00001894// Register-Register Subtraction with EFLAGS result
1895def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001896 (implicit EFLAGS)),
1897 (SUB64rr GR64:$src1, GR64:$src2)>;
1898
Dan Gohman99a12192009-03-04 19:44:21 +00001899// Register-Memory Subtraction with EFLAGS result
1900def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001901 (implicit EFLAGS)),
1902 (SUB64rm GR64:$src1, addr:$src2)>;
1903
Dan Gohman99a12192009-03-04 19:44:21 +00001904// Register-Integer Subtraction with EFLAGS result
1905def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001906 (implicit EFLAGS)),
1907 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001908def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001909 (implicit EFLAGS)),
1910 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001911
Dan Gohman99a12192009-03-04 19:44:21 +00001912// Memory-Register Subtraction with EFLAGS result
1913def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001914 addr:$dst),
1915 (implicit EFLAGS)),
1916 (SUB64mr addr:$dst, GR64:$src2)>;
1917
Dan Gohman99a12192009-03-04 19:44:21 +00001918// Memory-Integer Subtraction with EFLAGS result
1919def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001920 addr:$dst),
1921 (implicit EFLAGS)),
1922 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001923def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001924 addr:$dst),
1925 (implicit EFLAGS)),
1926 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001927
Dan Gohman99a12192009-03-04 19:44:21 +00001928// Register-Register Signed Integer Multiplication with EFLAGS result
1929def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001930 (implicit EFLAGS)),
1931 (IMUL64rr GR64:$src1, GR64:$src2)>;
1932
Dan Gohman99a12192009-03-04 19:44:21 +00001933// Register-Memory Signed Integer Multiplication with EFLAGS result
1934def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001935 (implicit EFLAGS)),
1936 (IMUL64rm GR64:$src1, addr:$src2)>;
1937
Dan Gohman99a12192009-03-04 19:44:21 +00001938// Register-Integer Signed Integer Multiplication with EFLAGS result
1939def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001940 (implicit EFLAGS)),
1941 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001942def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001943 (implicit EFLAGS)),
1944 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001945
Dan Gohman99a12192009-03-04 19:44:21 +00001946// Memory-Integer Signed Integer Multiplication with EFLAGS result
1947def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001948 (implicit EFLAGS)),
1949 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001950def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001951 (implicit EFLAGS)),
1952 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001953
Dan Gohman99a12192009-03-04 19:44:21 +00001954// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001955def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1956 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1957def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1958 (implicit EFLAGS)),
1959 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1960def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1961 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1962def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1963 (implicit EFLAGS)),
1964 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1965
1966def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1967 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1968def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1969 (implicit EFLAGS)),
1970 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1971def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1972 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1973def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1974 (implicit EFLAGS)),
1975 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1976
Dan Gohman99a12192009-03-04 19:44:21 +00001977def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1978 (INC64r GR64:$src)>;
1979def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1980 (implicit EFLAGS)),
1981 (INC64m addr:$dst)>;
1982def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1983 (DEC64r GR64:$src)>;
1984def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1985 (implicit EFLAGS)),
1986 (DEC64m addr:$dst)>;
1987
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001988//===----------------------------------------------------------------------===//
1989// X86-64 SSE Instructions
1990//===----------------------------------------------------------------------===//
1991
1992// Move instructions...
1993
Evan Chengb783fa32007-07-19 01:14:50 +00001994def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001995 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001996 [(set VR128:$dst,
1997 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001998def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001999 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002000 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2001 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002002
Evan Chengb783fa32007-07-19 01:14:50 +00002003def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002004 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002005 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002006def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002007 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002008 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2009
Evan Chengb783fa32007-07-19 01:14:50 +00002010def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002011 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002012 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002013def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002014 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002015 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002016
2017//===----------------------------------------------------------------------===//
2018// X86-64 SSE4.1 Instructions
2019//===----------------------------------------------------------------------===//
2020
Nate Begeman4294c1f2008-02-12 22:51:28 +00002021/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2022multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002023 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002024 (ins VR128:$src1, i32i8imm:$src2),
2025 !strconcat(OpcodeStr,
2026 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2027 [(set GR64:$dst,
2028 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002029 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002030 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2031 !strconcat(OpcodeStr,
2032 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2033 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2034 addr:$dst)]>, OpSize, REX_W;
2035}
2036
2037defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2038
2039let isTwoAddress = 1 in {
2040 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002041 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002042 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2043 !strconcat(OpcodeStr,
2044 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2045 [(set VR128:$dst,
2046 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2047 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002048 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002049 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2050 !strconcat(OpcodeStr,
2051 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2052 [(set VR128:$dst,
2053 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2054 imm:$src3)))]>, OpSize, REX_W;
2055 }
2056}
2057
2058defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002059
2060// -disable-16bit support.
2061def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2062 (MOV16mi addr:$dst, imm:$src)>;
2063def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2064 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2065def : Pat<(i64 (sextloadi16 addr:$dst)),
2066 (MOVSX64rm16 addr:$dst)>;
2067def : Pat<(i64 (zextloadi16 addr:$dst)),
2068 (MOVZX64rm16 addr:$dst)>;
2069def : Pat<(i64 (extloadi16 addr:$dst)),
2070 (MOVZX64rm16 addr:$dst)>;