blob: 4a1a899c88077ecb7906535f4b07bbacf319b6dd [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 {
217let 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", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000220let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000222 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
223}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224
Bill Wendling4c2638c2009-06-15 19:39:04 +0000225let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
226def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000227 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000228def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000229 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000230def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000231 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000232}
233
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000234let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000235def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000236let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000237def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000238
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000240 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000241 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
243
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000244let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, lea64addr:$src)]>;
248
249let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000250def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000251 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253
Evan Cheng48679f42007-12-14 02:13:44 +0000254// Bit scan instructions.
255let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000256def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000257 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000258 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000259def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000260 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000261 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
262 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000263
Evan Cheng4e33de92007-12-14 18:49:43 +0000264def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000265 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000266 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000267def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000268 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000269 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
270 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000271} // Defs = [EFLAGS]
272
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000274let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000275def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000276 [(X86rep_movs i64)]>, REP;
277let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000278def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000279 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000281// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000282def SYSEXIT64 : RI<0x35, RawFrm,
283 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000284
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285//===----------------------------------------------------------------------===//
286// Move Instructions...
287//
288
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000289let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000290def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000291 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292
Evan Chengd2b9d302008-06-25 01:16:38 +0000293let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000294def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000295 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000297def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000298 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000300}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
Dan Gohman5574cc72008-12-03 18:15:48 +0000302let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000303def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$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, (load addr:$src))]>;
306
Evan Chengb783fa32007-07-19 01:14:50 +0000307def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000308 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000310def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000311 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 [(store i64immSExt32:$src, addr:$dst)]>;
313
314// Sign/Zero extenders
315
Dan Gohmanedde1992009-04-13 15:13:28 +0000316// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
317// operand, which makes it a rare instruction with an 8-bit register
318// operand that can never access an h register. If support for h registers
319// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000320def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000321 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000323def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000324 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000326def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000332def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000333 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000335def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000336 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
338
Dan Gohman9203ab42008-07-30 18:09:17 +0000339// Use movzbl instead of movzbq when the destination is a register; it's
340// equivalent due to implicit zero-extending, and it has a smaller encoding.
341def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
342 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
343 [(set GR64:$dst, (zext GR8:$src))]>, TB;
344def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
345 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
346 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
347// Use movzwl instead of movzwq when the destination is a register; it's
348// equivalent due to implicit zero-extending, and it has a smaller encoding.
349def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
350 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
351 [(set GR64:$dst, (zext GR16:$src))]>, TB;
352def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
353 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
354 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355
Dan Gohman47a419d2008-08-07 02:54:50 +0000356// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000357// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
358// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
359// zero-extension, however this isn't possible when the 32-bit value is
360// defined by a truncate or is copied from something where the high bits aren't
361// necessarily all zero. In such cases, we fall back to these explicit zext
362// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000363def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
364 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
365 [(set GR64:$dst, (zext GR32:$src))]>;
366def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
367 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
368 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
369
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000370// Any instruction that defines a 32-bit result leaves the high half of the
371// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
372// be copying from a truncate, but any other 32-bit operation will zero-extend
373// up to 64 bits.
374def def32 : PatLeaf<(i32 GR32:$src), [{
375 return N->getOpcode() != ISD::TRUNCATE &&
376 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
377 N->getOpcode() != ISD::CopyFromReg;
378}]>;
379
380// In the case of a 32-bit def that is known to implicitly zero-extend,
381// we can use a SUBREG_TO_REG.
382def : Pat<(i64 (zext def32:$src)),
383 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
384
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000385let neverHasSideEffects = 1 in {
386 let Defs = [RAX], Uses = [EAX] in
387 def CDQE : RI<0x98, RawFrm, (outs), (ins),
388 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000390 let Defs = [RAX,RDX], Uses = [RAX] in
391 def CQO : RI<0x99, RawFrm, (outs), (ins),
392 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
393}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394
395//===----------------------------------------------------------------------===//
396// Arithmetic Instructions...
397//
398
Evan Cheng55687072007-09-14 21:48:26 +0000399let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000400
401def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
402 "add{q}\t{$src, %rax|%rax, $src}", []>;
403
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404let isTwoAddress = 1 in {
405let isConvertibleToThreeAddress = 1 in {
406let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000407// Register-Register Addition
408def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
409 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000410 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000411 (implicit EFLAGS)]>;
412
413// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000414def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
415 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000416 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
417 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000418def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
419 "add{q}\t{$src2, $dst|$dst, $src2}",
420 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
421 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422} // isConvertibleToThreeAddress
423
Bill Wendlingae034ed2008-12-12 00:56:36 +0000424// Register-Memory Addition
425def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
426 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000427 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000428 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429} // isTwoAddress
430
Bill Wendlingae034ed2008-12-12 00:56:36 +0000431// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000432def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000433 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000434 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
435 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000436def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000437 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000438 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
439 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000440def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
441 "add{q}\t{$src2, $dst|$dst, $src2}",
442 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
443 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444
Evan Cheng259471d2007-10-05 17:59:57 +0000445let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446let isTwoAddress = 1 in {
447let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000448def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000450 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451
Dale Johannesen747fe522009-06-02 03:12:52 +0000452def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000453 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000454 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000455
Dale Johannesen747fe522009-06-02 03:12:52 +0000456def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000457 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000458 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
459def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000460 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000461 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462} // isTwoAddress
463
Evan Chengb783fa32007-07-19 01:14:50 +0000464def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000465 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000466 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000467def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000468 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000469 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000470def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
471 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000472 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000473} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
475let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000476// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000477def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000479 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
480 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000481
482// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000483def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$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, (load addr:$src2))),
486 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000487
488// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000489def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
490 (ins GR64:$src1, i64i8imm:$src2),
491 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000492 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
493 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000494def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
495 (ins GR64:$src1, i64i32imm:$src2),
496 "sub{q}\t{$src2, $dst|$dst, $src2}",
497 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
498 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499} // isTwoAddress
500
Bill Wendlingae034ed2008-12-12 00:56:36 +0000501// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000502def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000503 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000504 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
505 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000506
507// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000508def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000509 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000510 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000511 addr:$dst),
512 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000513def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
514 "sub{q}\t{$src2, $dst|$dst, $src2}",
515 [(store (sub (load addr:$dst), i64immSExt32:$src2),
516 addr:$dst),
517 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
Evan Cheng259471d2007-10-05 17:59:57 +0000519let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000521def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000522 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000523 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524
Dale Johannesen747fe522009-06-02 03:12:52 +0000525def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000526 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000527 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
Dale Johannesen747fe522009-06-02 03:12:52 +0000529def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000530 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000531 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
532def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000533 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000534 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535} // isTwoAddress
536
Evan Chengb783fa32007-07-19 01:14:50 +0000537def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000538 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000539 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000540def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000541 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000542 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000543def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
544 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000545 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000546} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000547} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548
549// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000550let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000551def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000552 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000553let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000554def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000555 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
557// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000558def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000559 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000560let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000561def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000562 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
563}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564
Evan Cheng55687072007-09-14 21:48:26 +0000565let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000566let isTwoAddress = 1 in {
567let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000568// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000569def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
570 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000571 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000572 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
573 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574
Bill Wendlingf5399032008-12-12 21:15:41 +0000575// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000576def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
577 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000578 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000579 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
580 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581} // isTwoAddress
582
583// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000584
Bill Wendlingf5399032008-12-12 21:15:41 +0000585// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000587 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000588 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000589 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
590 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000591def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
592 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
593 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
594 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
595 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000596
Bill Wendlingf5399032008-12-12 21:15:41 +0000597// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000599 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000601 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000602 i64immSExt8:$src2)),
603 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000604def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
605 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
606 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
607 [(set GR64:$dst, (mul (load addr:$src1),
608 i64immSExt32:$src2)),
609 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000610} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611
612// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000613let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000614def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000615 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000617def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000618 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000619let mayLoad = 1 in {
620def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
621 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000622def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000623 "idiv{q}\t$src", []>;
624}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000625}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626
627// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000628let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000630def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000631 [(set GR64:$dst, (ineg GR64:$src)),
632 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000633def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000634 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
635 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636
637let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000638def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000639 [(set GR64:$dst, (add GR64:$src, 1)),
640 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000641def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000642 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
643 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000644
645let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000646def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000647 [(set GR64:$dst, (add GR64:$src, -1)),
648 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000649def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000650 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
651 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000652
653// In 64-bit mode, single byte INC and DEC cannot be encoded.
654let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
655// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000656def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000657 [(set GR16:$dst, (add GR16:$src, 1)),
658 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000660def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000661 [(set GR32:$dst, (add GR32:$src, 1)),
662 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000664def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000665 [(set GR16:$dst, (add GR16:$src, -1)),
666 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000668def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000669 [(set GR32:$dst, (add GR32:$src, -1)),
670 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000671 Requires<[In64BitMode]>;
672} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000673
674// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
675// how to unfold them.
676let isTwoAddress = 0, CodeSize = 2 in {
677 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000678 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
679 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000680 OpSize, Requires<[In64BitMode]>;
681 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000682 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
683 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000684 Requires<[In64BitMode]>;
685 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000686 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
687 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000688 OpSize, Requires<[In64BitMode]>;
689 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000690 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
691 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000692 Requires<[In64BitMode]>;
693}
Evan Cheng55687072007-09-14 21:48:26 +0000694} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000695
696
Evan Cheng55687072007-09-14 21:48:26 +0000697let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698// Shift instructions
699let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000700let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000701def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000702 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000703 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000704let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000705def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000706 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000708// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
709// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000710} // isTwoAddress
711
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000712let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000713def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000714 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000715 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000716def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000717 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000719def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000720 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
722
723let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000724let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000725def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000726 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000727 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000728def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000731def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000732 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000733 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
734} // isTwoAddress
735
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000736let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000737def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000738 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000739 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000742 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
746
747let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000748let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000749def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000750 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000751 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000752def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000755def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
758} // isTwoAddress
759
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000760let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000761def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000763 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000764def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000765 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000766 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000767def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000768 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000769 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
770
771// Rotate instructions
772let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000773let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000774def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000775 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000776 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000777def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000778 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000780def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000781 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
783} // isTwoAddress
784
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000785let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000786def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000787 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000788 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000789def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000792def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000793 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
795
796let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000797let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000798def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000799 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000800 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000801def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000804def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
807} // isTwoAddress
808
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000809let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000810def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000811 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000812 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000813def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000814 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000815 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000816def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000817 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
819
820// Double shift instructions (generalizations of rotate)
821let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000822let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000823def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000824 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
825 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000826def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000827 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
828 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000829}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830
831let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
832def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000833 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000834 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
835 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
836 (i8 imm:$src3)))]>,
837 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838def SHRD64rri8 : RIi8<0xAC, 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 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
841 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
842 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000843 TB;
844} // isCommutable
845} // isTwoAddress
846
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000847let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000848def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000849 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
850 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
851 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000852def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000853 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
854 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
855 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000856}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000858 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000859 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
860 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
861 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862 TB;
863def SHRD64mri8 : RIi8<0xAC, 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 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
866 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
867 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000869} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870
871//===----------------------------------------------------------------------===//
872// Logical Instructions...
873//
874
Evan Cheng5b51c242009-01-21 19:45:31 +0000875let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000876def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000878def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
880
Evan Cheng55687072007-09-14 21:48:26 +0000881let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000882def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
883 "and{q}\t{$src, %rax|%rax, $src}", []>;
884
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885let isTwoAddress = 1 in {
886let isCommutable = 1 in
887def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000888 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000889 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000890 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
891 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000892def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000893 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000894 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000895 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
896 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000898 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000899 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000900 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
901 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000902def AND64ri32 : RIi32<0x81, MRM4r,
903 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
904 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000905 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
906 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000907} // isTwoAddress
908
909def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000910 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000911 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000912 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
913 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000915 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000916 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000917 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
918 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000919def AND64mi32 : RIi32<0x81, MRM4m,
920 (outs), (ins i64mem:$dst, i64i32imm:$src),
921 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000922 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
923 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924
925let isTwoAddress = 1 in {
926let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000927def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
930 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000931def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000932 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000933 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
934 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000935def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000937 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
938 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000939def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
940 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000941 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
942 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943} // isTwoAddress
944
Evan Chengb783fa32007-07-19 01:14:50 +0000945def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000947 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
948 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000949def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000950 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000951 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
952 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000953def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
954 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000955 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
956 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957
958let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000959let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000960def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000962 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
963 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000964def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000966 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
967 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000968def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
969 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000970 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
971 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000973 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000975 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
976 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977} // isTwoAddress
978
Evan Chengb783fa32007-07-19 01:14:50 +0000979def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000981 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
982 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000983def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000984 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000985 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
986 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000987def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
988 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000989 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
990 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000991} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000992
993//===----------------------------------------------------------------------===//
994// Comparison Instructions...
995//
996
997// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000998let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +0000999def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1000 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001001let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001002def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001003 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001004 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1005 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001006def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001007 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001008 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1009 (implicit EFLAGS)]>;
1010def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1011 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001013 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1014 (implicit EFLAGS)]>;
1015def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1016 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001017 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001018 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1019 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020
Sean Callanan251676e2009-09-02 00:55:49 +00001021
1022def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1023 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001024def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001025 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001026 [(X86cmp GR64:$src1, GR64:$src2),
1027 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001028def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001029 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001030 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1031 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001032def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001033 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001034 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1035 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001036def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1037 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1038 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1039 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001040def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001041 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001042 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001043 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001044def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001045 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001046 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001047 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001048def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1049 (ins i64mem:$src1, i64i32imm:$src2),
1050 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1051 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1052 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001053} // Defs = [EFLAGS]
1054
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001055// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001056// TODO: BTC, BTR, and BTS
1057let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001058def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001059 "bt{q}\t{$src2, $src1|$src1, $src2}",
1060 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001061 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001062
1063// Unlike with the register+register form, the memory+register form of the
1064// bt instruction does not ignore the high bits of the index. From ISel's
1065// perspective, this is pretty bizarre. Disable these instructions for now.
1066//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1067// "bt{q}\t{$src2, $src1|$src1, $src2}",
1068// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1069// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001070
1071def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1072 "bt{q}\t{$src2, $src1|$src1, $src2}",
1073 [(X86bt GR64:$src1, i64immSExt8:$src2),
1074 (implicit EFLAGS)]>, TB;
1075// Note that these instructions don't need FastBTMem because that
1076// only applies when the other operand is in a register. When it's
1077// an immediate, bt is still fast.
1078def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1079 "bt{q}\t{$src2, $src1|$src1, $src2}",
1080 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1081 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001082} // Defs = [EFLAGS]
1083
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001085let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001086let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001088 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001089 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001091 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001093 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001094 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001096 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001097def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001098 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001099 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001101 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001103 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001104 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001106 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001107def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001108 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001109 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001111 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001112def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001113 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001114 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001116 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001117def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001118 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001119 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001120 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001121 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001123 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001124 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001126 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001127def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001128 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001129 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001131 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001132def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001133 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001134 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001135 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001136 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001137def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001138 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001139 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001141 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001142def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001143 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001144 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001145 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001146 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001148 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001149 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001150 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001151 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001152def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001153 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001154 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001155 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001156 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001157def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1158 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1159 "cmovo\t{$src2, $dst|$dst, $src2}",
1160 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1161 X86_COND_O, EFLAGS))]>, TB;
1162def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1163 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1164 "cmovno\t{$src2, $dst|$dst, $src2}",
1165 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1166 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001167} // isCommutable = 1
1168
1169def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1170 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1171 "cmovb\t{$src2, $dst|$dst, $src2}",
1172 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1173 X86_COND_B, EFLAGS))]>, TB;
1174def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1175 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1176 "cmovae\t{$src2, $dst|$dst, $src2}",
1177 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1178 X86_COND_AE, EFLAGS))]>, TB;
1179def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1180 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1181 "cmove\t{$src2, $dst|$dst, $src2}",
1182 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1183 X86_COND_E, EFLAGS))]>, TB;
1184def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1185 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1186 "cmovne\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1188 X86_COND_NE, EFLAGS))]>, TB;
1189def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1190 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1191 "cmovbe\t{$src2, $dst|$dst, $src2}",
1192 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1193 X86_COND_BE, EFLAGS))]>, TB;
1194def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1195 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1196 "cmova\t{$src2, $dst|$dst, $src2}",
1197 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1198 X86_COND_A, EFLAGS))]>, TB;
1199def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1200 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1201 "cmovl\t{$src2, $dst|$dst, $src2}",
1202 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1203 X86_COND_L, EFLAGS))]>, TB;
1204def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1205 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1206 "cmovge\t{$src2, $dst|$dst, $src2}",
1207 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1208 X86_COND_GE, EFLAGS))]>, TB;
1209def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1210 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1211 "cmovle\t{$src2, $dst|$dst, $src2}",
1212 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1213 X86_COND_LE, EFLAGS))]>, TB;
1214def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1215 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1216 "cmovg\t{$src2, $dst|$dst, $src2}",
1217 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1218 X86_COND_G, EFLAGS))]>, TB;
1219def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1220 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1221 "cmovs\t{$src2, $dst|$dst, $src2}",
1222 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1223 X86_COND_S, EFLAGS))]>, TB;
1224def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1225 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1226 "cmovns\t{$src2, $dst|$dst, $src2}",
1227 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1228 X86_COND_NS, EFLAGS))]>, TB;
1229def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1230 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1231 "cmovp\t{$src2, $dst|$dst, $src2}",
1232 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1233 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001235 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001236 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001237 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001238 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001239def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1240 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1241 "cmovo\t{$src2, $dst|$dst, $src2}",
1242 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1243 X86_COND_O, EFLAGS))]>, TB;
1244def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1245 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1246 "cmovno\t{$src2, $dst|$dst, $src2}",
1247 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1248 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249} // isTwoAddress
1250
1251//===----------------------------------------------------------------------===//
1252// Conversion Instructions...
1253//
1254
1255// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001256def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001258 [(set GR64:$dst,
1259 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001260def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001261 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001262 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1263 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001264def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001265 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001267def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001270def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001272 [(set GR64:$dst,
1273 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001274def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001275 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001276 [(set GR64:$dst,
1277 (int_x86_sse2_cvttsd2si64
1278 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279
1280// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001281def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001282 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001284def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001285 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001287
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001288let isTwoAddress = 1 in {
1289def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001290 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001292 [(set VR128:$dst,
1293 (int_x86_sse2_cvtsi642sd VR128:$src1,
1294 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001295def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001296 (outs VR128:$dst), (ins VR128:$src1, i64mem:$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 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301} // isTwoAddress
1302
1303// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001304def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001305 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001306 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001307def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001308 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001310
1311let isTwoAddress = 1 in {
1312 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1313 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1314 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1315 [(set VR128:$dst,
1316 (int_x86_sse_cvtsi642ss VR128:$src1,
1317 GR64:$src2))]>;
1318 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1319 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1320 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1321 [(set VR128:$dst,
1322 (int_x86_sse_cvtsi642ss VR128:$src1,
1323 (loadi64 addr:$src2)))]>;
1324}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325
1326// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001327def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001328 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001329 [(set GR64:$dst,
1330 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001331def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001332 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001333 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1334 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001335def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001336 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001338def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001339 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001340 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001341def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001342 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001343 [(set GR64:$dst,
1344 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001345def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001346 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001347 [(set GR64:$dst,
1348 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1349
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001350//===----------------------------------------------------------------------===//
1351// Alias Instructions
1352//===----------------------------------------------------------------------===//
1353
Dan Gohman027cd112007-09-17 14:55:08 +00001354// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1355// equivalent due to implicit zero-extending, and it sometimes has a smaller
1356// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001357// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001358// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001359let AddedComplexity = 1 in
1360def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001361 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001362
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001363
1364// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001365let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001366def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001367 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001368 [(set GR64:$dst, i64immZExt32:$src)]>;
1369
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001370//===----------------------------------------------------------------------===//
1371// Thread Local Storage Instructions
1372//===----------------------------------------------------------------------===//
1373
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001374// All calls clobber the non-callee saved registers. RSP is marked as
1375// a use to prevent stack-pointer assignments that appear immediately
1376// before calls from potentially appearing dead.
1377let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1378 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1379 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1380 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1381 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1382 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001383def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001384 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001385 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001386 ".word\t0x6666; "
1387 "rex64; "
1388 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001389 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001390 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001391
Daniel Dunbar75a07302009-08-11 22:24:40 +00001392let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001393def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1394 "movq\t%gs:$src, $dst",
1395 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1396
Daniel Dunbar75a07302009-08-11 22:24:40 +00001397let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001398def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1399 "movq\t%fs:$src, $dst",
1400 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1401
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001402//===----------------------------------------------------------------------===//
1403// Atomic Instructions
1404//===----------------------------------------------------------------------===//
1405
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001406let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001407def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001408 "lock\n\t"
1409 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001410 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1411}
1412
Dan Gohmana41a1c092008-08-06 15:52:50 +00001413let Constraints = "$val = $dst" in {
1414let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001415def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001416 "lock\n\t"
1417 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001418 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001419 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001420
Evan Chenga1e80602008-04-19 02:05:42 +00001421def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001422 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001423 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001424}
1425
Evan Chengb723fb52009-07-30 08:33:02 +00001426// Optimized codegen when the non-memory output is not used.
1427// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1428def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1429 "lock\n\t"
1430 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1431def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1432 (ins i64mem:$dst, i64i8imm :$src2),
1433 "lock\n\t"
1434 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1435def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1436 (ins i64mem:$dst, i64i32imm :$src2),
1437 "lock\n\t"
1438 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1439def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1440 "lock\n\t"
1441 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1442def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1443 (ins i64mem:$dst, i64i8imm :$src2),
1444 "lock\n\t"
1445 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1446def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1447 (ins i64mem:$dst, i64i32imm:$src2),
1448 "lock\n\t"
1449 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1450def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1451 "lock\n\t"
1452 "inc{q}\t$dst", []>, LOCK;
1453def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1454 "lock\n\t"
1455 "dec{q}\t$dst", []>, LOCK;
1456
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001457// Atomic exchange, and, or, xor
1458let Constraints = "$val = $dst", Defs = [EFLAGS],
1459 usesCustomDAGSchedInserter = 1 in {
1460def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001461 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001462 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001463def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001464 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001465 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001466def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001467 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001468 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001469def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001470 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001471 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001472def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001473 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001474 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001475def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001476 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001477 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001478def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001479 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001480 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001481def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001482 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001483 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001484}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001485
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486//===----------------------------------------------------------------------===//
1487// Non-Instruction Patterns
1488//===----------------------------------------------------------------------===//
1489
Chris Lattner0d2dad62009-07-11 22:50:33 +00001490// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1491// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1492// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001493def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001494 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001495def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001496 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001497def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001498 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001499def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001500 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001501
Chris Lattnerc04cd042009-07-11 23:17:29 +00001502// In static codegen with small code model, we can get the address of a label
1503// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1504// the MOV64ri64i32 should accept these.
1505def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1506 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1507def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1508 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1509def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1510 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1511def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1512 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1513
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001514// In kernel code model, we can get the address of a label
1515// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1516// the MOV64ri32 should accept these.
1517def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1518 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1519def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1520 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1521def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1522 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1523def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1524 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001525
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001526// If we have small model and -static mode, it is safe to store global addresses
1527// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001528// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1530 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001531 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001532def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1533 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001534 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1536 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001537 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1539 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001540 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001541
1542// Calls
1543// Direct PC relative function call for small code model. 32-bit displacement
1544// sign extended to 64-bit.
1545def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001546 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001547def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001548 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1549
1550def : Pat<(X86call (i64 tglobaladdr:$dst)),
1551 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1552def : Pat<(X86call (i64 texternalsym:$dst)),
1553 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001554
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001555// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001556def : Pat<(X86tcret GR64:$dst, imm:$off),
1557 (TCRETURNri64 GR64:$dst, imm:$off)>;
1558
1559def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1560 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1561
1562def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1563 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1564
Dan Gohmanec596042007-09-17 14:35:24 +00001565// Comparisons.
1566
1567// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001568def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001569 (TEST64rr GR64:$src1, GR64:$src1)>;
1570
Dan Gohman0a3c5222009-01-07 01:00:24 +00001571// Conditional moves with folded loads with operands swapped and conditions
1572// inverted.
1573def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1574 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1575def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1576 (CMOVB64rm GR64:$src2, addr:$src1)>;
1577def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1578 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1579def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1580 (CMOVE64rm GR64:$src2, addr:$src1)>;
1581def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1582 (CMOVA64rm GR64:$src2, addr:$src1)>;
1583def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1584 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1585def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1586 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1587def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1588 (CMOVL64rm GR64:$src2, addr:$src1)>;
1589def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1590 (CMOVG64rm GR64:$src2, addr:$src1)>;
1591def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1592 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1593def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1594 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1595def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1596 (CMOVP64rm GR64:$src2, addr:$src1)>;
1597def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1598 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1599def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1600 (CMOVS64rm GR64:$src2, addr:$src1)>;
1601def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1602 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1603def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1604 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001605
Duncan Sands082524c2008-01-23 20:39:46 +00001606// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001607def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1608
1609// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001610// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1611// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1612// partial-register updates.
1613def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1614def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1615def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1616// For other extloads, use subregs, since the high contents of the register are
1617// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001618def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001619 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001620 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001621
Dan Gohman9959b052009-08-26 14:59:13 +00001622// anyext. Define these to do an explicit zero-extend to
1623// avoid partial-register updates.
1624def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1625def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1626def : Pat<(i64 (anyext GR32:$src)),
1627 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001628
1629//===----------------------------------------------------------------------===//
1630// Some peepholes
1631//===----------------------------------------------------------------------===//
1632
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001633// Odd encoding trick: -128 fits into an 8-bit immediate field while
1634// +128 doesn't, so in this special case use a sub instead of an add.
1635def : Pat<(add GR64:$src1, 128),
1636 (SUB64ri8 GR64:$src1, -128)>;
1637def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1638 (SUB64mi8 addr:$dst, -128)>;
1639
1640// The same trick applies for 32-bit immediate fields in 64-bit
1641// instructions.
1642def : Pat<(add GR64:$src1, 0x0000000080000000),
1643 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1644def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1645 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1646
Dan Gohman47a419d2008-08-07 02:54:50 +00001647// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001648def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001649 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001650// r & (2^16-1) ==> movz
1651def : Pat<(and GR64:$src, 0xffff),
1652 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1653// r & (2^8-1) ==> movz
1654def : Pat<(and GR64:$src, 0xff),
1655 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001656// r & (2^8-1) ==> movz
1657def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001658 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001659 Requires<[In64BitMode]>;
1660// r & (2^8-1) ==> movz
1661def : Pat<(and GR16:$src1, 0xff),
1662 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1663 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001664
Dan Gohmandd612bb2008-08-20 21:27:32 +00001665// sext_inreg patterns
1666def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001667 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001668def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001669 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001670def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001671 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001672def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001673 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001674 Requires<[In64BitMode]>;
1675def : Pat<(sext_inreg GR16:$src, i8),
1676 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1677 Requires<[In64BitMode]>;
1678
1679// trunc patterns
1680def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001681 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001682def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001683 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001684def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001685 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001686def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001687 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001688 Requires<[In64BitMode]>;
1689def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001690 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1691 Requires<[In64BitMode]>;
1692
1693// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001694// For now, be conservative on x86-64 and use an h-register extract only if the
1695// value is immediately zero-extended or stored, which are somewhat common
1696// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1697// from being allocated in the same instruction as the h register, as there's
1698// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001699
1700// h-register extract and zero-extend.
1701def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1702 (SUBREG_TO_REG
1703 (i64 0),
1704 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001705 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001706 x86_subreg_8bit_hi)),
1707 x86_subreg_32bit)>;
1708def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1709 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001710 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001711 x86_subreg_8bit_hi))>,
1712 Requires<[In64BitMode]>;
1713def : Pat<(srl_su GR16:$src, (i8 8)),
1714 (EXTRACT_SUBREG
1715 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001716 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001717 x86_subreg_8bit_hi)),
1718 x86_subreg_16bit)>,
1719 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001720def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1721 (MOVZX32_NOREXrr8
1722 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1723 x86_subreg_8bit_hi))>,
1724 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001725def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1726 (MOVZX32_NOREXrr8
1727 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1728 x86_subreg_8bit_hi))>,
1729 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001730def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1731 (SUBREG_TO_REG
1732 (i64 0),
1733 (MOVZX32_NOREXrr8
1734 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1735 x86_subreg_8bit_hi)),
1736 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001737def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1738 (SUBREG_TO_REG
1739 (i64 0),
1740 (MOVZX32_NOREXrr8
1741 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1742 x86_subreg_8bit_hi)),
1743 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001744
1745// h-register extract and store.
1746def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1747 (MOV8mr_NOREX
1748 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001749 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001750 x86_subreg_8bit_hi))>;
1751def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1752 (MOV8mr_NOREX
1753 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001754 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001755 x86_subreg_8bit_hi))>,
1756 Requires<[In64BitMode]>;
1757def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1758 (MOV8mr_NOREX
1759 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001760 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001761 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001762 Requires<[In64BitMode]>;
1763
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001764// (shl x, 1) ==> (add x, x)
1765def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1766
Evan Cheng76a64c72008-08-30 02:03:58 +00001767// (shl x (and y, 63)) ==> (shl x, y)
1768def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1769 (SHL64rCL GR64:$src1)>;
1770def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1771 (SHL64mCL addr:$dst)>;
1772
1773def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1774 (SHR64rCL GR64:$src1)>;
1775def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1776 (SHR64mCL addr:$dst)>;
1777
1778def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1779 (SAR64rCL GR64:$src1)>;
1780def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1781 (SAR64mCL addr:$dst)>;
1782
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001783// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1784def : Pat<(or (srl GR64:$src1, CL:$amt),
1785 (shl GR64:$src2, (sub 64, CL:$amt))),
1786 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1787
1788def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1789 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1790 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1791
Dan Gohman921581d2008-10-17 01:23:35 +00001792def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1793 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1794 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1795
1796def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1797 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1798 addr:$dst),
1799 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1800
1801def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1802 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1803
1804def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1805 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1806 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1807
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001808// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1809def : Pat<(or (shl GR64:$src1, CL:$amt),
1810 (srl GR64:$src2, (sub 64, CL:$amt))),
1811 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1812
1813def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1814 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1815 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1816
Dan Gohman921581d2008-10-17 01:23:35 +00001817def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1818 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1819 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1820
1821def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1822 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1823 addr:$dst),
1824 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1825
1826def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1827 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1828
1829def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1830 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1831 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1832
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001833// X86 specific add which produces a flag.
1834def : Pat<(addc GR64:$src1, GR64:$src2),
1835 (ADD64rr GR64:$src1, GR64:$src2)>;
1836def : Pat<(addc GR64:$src1, (load addr:$src2)),
1837 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001838def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1839 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001840def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1841 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001842
1843def : Pat<(subc GR64:$src1, GR64:$src2),
1844 (SUB64rr GR64:$src1, GR64:$src2)>;
1845def : Pat<(subc GR64:$src1, (load addr:$src2)),
1846 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001847def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1848 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001849def : Pat<(subc GR64:$src1, imm:$src2),
1850 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001851
Bill Wendlingf5399032008-12-12 21:15:41 +00001852//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001853// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001854//===----------------------------------------------------------------------===//
1855
Dan Gohman99a12192009-03-04 19:44:21 +00001856// Register-Register Addition with EFLAGS result
1857def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001858 (implicit EFLAGS)),
1859 (ADD64rr GR64:$src1, GR64:$src2)>;
1860
Dan Gohman99a12192009-03-04 19:44:21 +00001861// Register-Integer Addition with EFLAGS result
1862def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001863 (implicit EFLAGS)),
1864 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001865def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001866 (implicit EFLAGS)),
1867 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001868
Dan Gohman99a12192009-03-04 19:44:21 +00001869// Register-Memory Addition with EFLAGS result
1870def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001871 (implicit EFLAGS)),
1872 (ADD64rm GR64:$src1, addr:$src2)>;
1873
Dan Gohman99a12192009-03-04 19:44:21 +00001874// Memory-Register Addition with EFLAGS result
1875def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001876 addr:$dst),
1877 (implicit EFLAGS)),
1878 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001879def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001880 addr:$dst),
1881 (implicit EFLAGS)),
1882 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001883def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001884 addr:$dst),
1885 (implicit EFLAGS)),
1886 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001887
Dan Gohman99a12192009-03-04 19:44:21 +00001888// Register-Register Subtraction with EFLAGS result
1889def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001890 (implicit EFLAGS)),
1891 (SUB64rr GR64:$src1, GR64:$src2)>;
1892
Dan Gohman99a12192009-03-04 19:44:21 +00001893// Register-Memory Subtraction with EFLAGS result
1894def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001895 (implicit EFLAGS)),
1896 (SUB64rm GR64:$src1, addr:$src2)>;
1897
Dan Gohman99a12192009-03-04 19:44:21 +00001898// Register-Integer Subtraction with EFLAGS result
1899def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001900 (implicit EFLAGS)),
1901 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001902def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001903 (implicit EFLAGS)),
1904 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001905
Dan Gohman99a12192009-03-04 19:44:21 +00001906// Memory-Register Subtraction with EFLAGS result
1907def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001908 addr:$dst),
1909 (implicit EFLAGS)),
1910 (SUB64mr addr:$dst, GR64:$src2)>;
1911
Dan Gohman99a12192009-03-04 19:44:21 +00001912// Memory-Integer Subtraction with EFLAGS result
1913def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001914 addr:$dst),
1915 (implicit EFLAGS)),
1916 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001917def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001918 addr:$dst),
1919 (implicit EFLAGS)),
1920 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001921
Dan Gohman99a12192009-03-04 19:44:21 +00001922// Register-Register Signed Integer Multiplication with EFLAGS result
1923def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001924 (implicit EFLAGS)),
1925 (IMUL64rr GR64:$src1, GR64:$src2)>;
1926
Dan Gohman99a12192009-03-04 19:44:21 +00001927// Register-Memory Signed Integer Multiplication with EFLAGS result
1928def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001929 (implicit EFLAGS)),
1930 (IMUL64rm GR64:$src1, addr:$src2)>;
1931
Dan Gohman99a12192009-03-04 19:44:21 +00001932// Register-Integer Signed Integer Multiplication with EFLAGS result
1933def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001934 (implicit EFLAGS)),
1935 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001936def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001937 (implicit EFLAGS)),
1938 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001939
Dan Gohman99a12192009-03-04 19:44:21 +00001940// Memory-Integer Signed Integer Multiplication with EFLAGS result
1941def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001942 (implicit EFLAGS)),
1943 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001944def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001945 (implicit EFLAGS)),
1946 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001947
Dan Gohman99a12192009-03-04 19:44:21 +00001948// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001949def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1950 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1951def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1952 (implicit EFLAGS)),
1953 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1954def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1955 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1956def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1957 (implicit EFLAGS)),
1958 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1959
1960def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1961 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1962def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1963 (implicit EFLAGS)),
1964 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1965def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1966 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1967def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1968 (implicit EFLAGS)),
1969 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1970
Dan Gohman99a12192009-03-04 19:44:21 +00001971def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1972 (INC64r GR64:$src)>;
1973def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1974 (implicit EFLAGS)),
1975 (INC64m addr:$dst)>;
1976def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1977 (DEC64r GR64:$src)>;
1978def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1979 (implicit EFLAGS)),
1980 (DEC64m addr:$dst)>;
1981
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001982//===----------------------------------------------------------------------===//
1983// X86-64 SSE Instructions
1984//===----------------------------------------------------------------------===//
1985
1986// Move instructions...
1987
Evan Chengb783fa32007-07-19 01:14:50 +00001988def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001989 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001990 [(set VR128:$dst,
1991 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001992def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001993 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001994 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1995 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001996
Evan Chengb783fa32007-07-19 01:14:50 +00001997def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001998 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001999 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002000def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002001 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002002 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2003
Evan Chengb783fa32007-07-19 01:14:50 +00002004def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002005 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002006 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002007def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002008 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002009 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002010
2011//===----------------------------------------------------------------------===//
2012// X86-64 SSE4.1 Instructions
2013//===----------------------------------------------------------------------===//
2014
Nate Begeman4294c1f2008-02-12 22:51:28 +00002015/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2016multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002017 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002018 (ins VR128:$src1, i32i8imm:$src2),
2019 !strconcat(OpcodeStr,
2020 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2021 [(set GR64:$dst,
2022 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002023 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002024 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2025 !strconcat(OpcodeStr,
2026 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2027 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2028 addr:$dst)]>, OpSize, REX_W;
2029}
2030
2031defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2032
2033let isTwoAddress = 1 in {
2034 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002035 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002036 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2037 !strconcat(OpcodeStr,
2038 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2039 [(set VR128:$dst,
2040 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2041 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002042 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002043 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2044 !strconcat(OpcodeStr,
2045 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2046 [(set VR128:$dst,
2047 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2048 imm:$src3)))]>, OpSize, REX_W;
2049 }
2050}
2051
2052defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;