blob: b5fa862712e55c723bae7c066f4eca2f02f6cb0d [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
Chris Lattner357a0ca2009-06-20 19:34:09 +000022
23// 64-bits but only 32 bits are significant, and those bits are treated as being
24// pc relative.
25def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27}
28
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// 64-bits but only 8 bits are significant.
Daniel Dunbaraa097b62009-08-10 21:06:41 +000031def i64i8imm : Operand<i64> {
32 let ParserMatchClass = ImmSExt8AsmOperand;
33}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034
35def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000036 let PrintMethod = "printlea64mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000037 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000038 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}
40
41def lea64_32mem : Operand<i32> {
42 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000043 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000044 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000045 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}
47
48//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000049// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050//
51def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Dan Gohman0c0d7412009-08-02 16:09:17 +000052 [add, sub, mul, X86mul_imm, shl, or, frameindex,
Chris Lattnerc04cd042009-07-11 23:17:29 +000053 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Chris Lattnerf1940742009-06-20 20:38:48 +000055def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
56 [tglobaltlsaddr], []>;
57
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000059// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060//
61
Dan Gohmand16fdc02008-12-19 18:25:21 +000062def i64immSExt8 : PatLeaf<(i64 imm), [{
63 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
64 // sign extended field.
65 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
66}]>;
67
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068def i64immSExt32 : PatLeaf<(i64 imm), [{
69 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
70 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000071 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072}]>;
73
74def i64immZExt32 : PatLeaf<(i64 imm), [{
75 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
76 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000077 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078}]>;
79
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
81def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
82def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
83
84def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
85def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
86def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
87def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
88
89def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
90def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
91def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
92def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
93
94//===----------------------------------------------------------------------===//
95// Instruction list...
96//
97
Dan Gohman01c9f772008-10-01 18:28:06 +000098// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
99// a stack adjustment and the codegen must know that they may modify the stack
100// pointer before prolog-epilog rewriting occurs.
101// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
102// sub / add which can clobber EFLAGS.
103let Defs = [RSP, EFLAGS], Uses = [RSP] in {
104def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
105 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000106 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000107 Requires<[In64BitMode]>;
108def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
109 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000110 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000111 Requires<[In64BitMode]>;
112}
113
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114//===----------------------------------------------------------------------===//
115// Call Instructions...
116//
Evan Cheng37e7c752007-07-21 00:34:19 +0000117let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000118 // All calls clobber the non-callee saved registers. RSP is marked as
119 // a use to prevent stack-pointer assignments that appear immediately
120 // before calls from potentially appearing dead. Uses for argument
121 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000123 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
125 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000126 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
127 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000128
129 // NOTE: this pattern doesn't match "X86call imm", because we do not know
130 // that the offset between an arbitrary immediate and the call will fit in
131 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000132 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000133 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
134 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000135 Requires<[In64BitMode, NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000136 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000137 "call\t{*}$dst", [(X86call GR64:$dst)]>,
138 Requires<[NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000139 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000140 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
141 Requires<[NotWin64]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000142
143 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
144 "lcall{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 }
146
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000147 // FIXME: We need to teach codegen about single list of call-clobbered registers.
148let isCall = 1 in
149 // All calls clobber the non-callee saved registers. RSP is marked as
150 // a use to prevent stack-pointer assignments that appear immediately
151 // before calls from potentially appearing dead. Uses for argument
152 // registers are added manually.
153 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
154 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
155 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
156 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
157 Uses = [RSP] in {
158 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000159 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
160 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000161 Requires<[IsWin64]>;
162 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
163 "call\t{*}$dst",
164 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
165 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
166 "call\t{*}$dst",
167 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
168 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000169
170
171let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000172def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
173 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000174 "#TC_RETURN $dst $offset",
175 []>;
176
177let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000178def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
179 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000180 "#TC_RETURN $dst $offset",
181 []>;
182
183
184let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000185 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
186 "jmp{q}\t{*}$dst # TAILCALL",
187 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000188
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000190let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000191 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000193 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 [(brind (loadi64 addr:$dst))]>;
Sean Callanan66fdfa02009-09-03 00:04:47 +0000195 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
196 "ljmp{q}\t{*}$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197}
198
199//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000200// EH Pseudo Instructions
201//
202let isTerminator = 1, isReturn = 1, isBarrier = 1,
203 hasCtrlDep = 1 in {
204def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
205 "ret\t#eh_return, addr: $addr",
206 [(X86ehret GR64:$addr)]>;
207
208}
209
210//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211// Miscellaneous Instructions...
212//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000213let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000215 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000216let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000217let mayLoad = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000219 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000220def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
221def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", []>;
222}
223let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000225 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
Sean Callanan9f3c3f52009-09-10 18:29:13 +0000226def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
227def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", []>;
228}
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000229}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Bill Wendling4c2638c2009-06-15 19:39:04 +0000231let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
232def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000233 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000234def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000235 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000236def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000237 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000238}
239
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000240let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000241def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000242let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000243def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000244
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000246 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000247 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
249
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000250let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000251def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000252 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253 [(set GR64:$dst, lea64addr:$src)]>;
254
255let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000256def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000257 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259
Evan Cheng48679f42007-12-14 02:13:44 +0000260// Bit scan instructions.
261let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000262def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000263 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000264 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000265def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000266 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000267 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
268 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000269
Evan Cheng4e33de92007-12-14 18:49:43 +0000270def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000271 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000272 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000273def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000274 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000275 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
276 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000277} // Defs = [EFLAGS]
278
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000280let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000281def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000282 [(X86rep_movs i64)]>, REP;
283let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000284def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000285 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286
Sean Callanan481f06d2009-09-12 00:37:19 +0000287def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scas{q}", []>;
288
Sean Callanan25220d62009-09-12 02:25:20 +0000289def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmps{q}", []>;
290
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000291// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000292def SYSEXIT64 : RI<0x35, RawFrm,
293 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000294
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295//===----------------------------------------------------------------------===//
296// Move Instructions...
297//
298
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000299let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000300def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000301 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302
Evan Chengd2b9d302008-06-25 01:16:38 +0000303let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000304def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000305 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000307def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000308 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000310}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311
Evan Cheng3c1a4c52009-11-17 00:55:55 +0000312let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000313def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000314 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 [(set GR64:$dst, (load addr:$src))]>;
316
Evan Chengb783fa32007-07-19 01:14:50 +0000317def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000318 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000320def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000321 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 [(store i64immSExt32:$src, addr:$dst)]>;
323
Sean Callanan70953a52009-09-10 18:33:42 +0000324def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins i8imm:$src),
325 "mov{q}\t{$src, %rax|%rax, $src}", []>;
326def MOV64o32a : RIi32<0xA1, RawFrm, (outs), (ins i32imm:$src),
327 "mov{q}\t{$src, %rax|%rax, $src}", []>;
328def MOV64ao8 : RIi8<0xA2, RawFrm, (outs i8imm:$dst), (ins),
329 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
330def MOV64ao32 : RIi32<0xA3, RawFrm, (outs i32imm:$dst), (ins),
331 "mov{q}\t{%rax, $dst|$dst, %rax}", []>;
332
Sean Callananad87a3a2009-09-15 18:47:29 +0000333// Moves to and from segment registers
334def MOV64rs : RI<0x8C, MRMDestReg, (outs GR64:$dst), (ins SEGMENT_REG:$src),
335 "mov{w}\t{$src, $dst|$dst, $src}", []>;
336def MOV64ms : RI<0x8C, MRMDestMem, (outs i64mem:$dst), (ins SEGMENT_REG:$src),
337 "mov{w}\t{$src, $dst|$dst, $src}", []>;
338def MOV64sr : RI<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR64:$src),
339 "mov{w}\t{$src, $dst|$dst, $src}", []>;
340def MOV64sm : RI<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i64mem:$src),
341 "mov{w}\t{$src, $dst|$dst, $src}", []>;
342
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343// Sign/Zero extenders
344
Dan Gohmanedde1992009-04-13 15:13:28 +0000345// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
346// operand, which makes it a rare instruction with an 8-bit register
347// operand that can never access an h register. If support for h registers
348// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000349def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000350 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000352def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000353 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000355def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000356 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000358def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000359 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000361def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000362 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000364def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000365 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
367
Dan Gohman9203ab42008-07-30 18:09:17 +0000368// Use movzbl instead of movzbq when the destination is a register; it's
369// equivalent due to implicit zero-extending, and it has a smaller encoding.
370def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000371 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000372def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000373 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000374// Use movzwl instead of movzwq when the destination is a register; it's
375// equivalent due to implicit zero-extending, and it has a smaller encoding.
376def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000377 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
Dan Gohman9203ab42008-07-30 18:09:17 +0000378def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000379 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380
Dan Gohman47a419d2008-08-07 02:54:50 +0000381// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000382// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
383// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
384// zero-extension, however this isn't possible when the 32-bit value is
385// defined by a truncate or is copied from something where the high bits aren't
386// necessarily all zero. In such cases, we fall back to these explicit zext
387// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000388def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000389 "", [(set GR64:$dst, (zext GR32:$src))]>;
Dan Gohman47a419d2008-08-07 02:54:50 +0000390def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +0000391 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
Dan Gohman47a419d2008-08-07 02:54:50 +0000392
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000393// Any instruction that defines a 32-bit result leaves the high half of the
Dan Gohman5d38ee42009-09-15 00:14:11 +0000394// register. Truncate can be lowered to EXTRACT_SUBREG. CopyFromReg may
395// be copying from a truncate. And x86's cmov doesn't do anything if the
396// condition is false. But any other 32-bit operation will zero-extend
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000397// up to 64 bits.
398def def32 : PatLeaf<(i32 GR32:$src), [{
399 return N->getOpcode() != ISD::TRUNCATE &&
400 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
Dan Gohman5d38ee42009-09-15 00:14:11 +0000401 N->getOpcode() != ISD::CopyFromReg &&
402 N->getOpcode() != X86ISD::CMOV;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000403}]>;
404
405// In the case of a 32-bit def that is known to implicitly zero-extend,
406// we can use a SUBREG_TO_REG.
407def : Pat<(i64 (zext def32:$src)),
408 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
409
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000410let neverHasSideEffects = 1 in {
411 let Defs = [RAX], Uses = [EAX] in
412 def CDQE : RI<0x98, RawFrm, (outs), (ins),
413 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000415 let Defs = [RAX,RDX], Uses = [RAX] in
416 def CQO : RI<0x99, RawFrm, (outs), (ins),
417 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
418}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419
420//===----------------------------------------------------------------------===//
421// Arithmetic Instructions...
422//
423
Evan Cheng55687072007-09-14 21:48:26 +0000424let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000425
426def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
427 "add{q}\t{$src, %rax|%rax, $src}", []>;
428
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429let isTwoAddress = 1 in {
430let isConvertibleToThreeAddress = 1 in {
431let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000432// Register-Register Addition
433def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
434 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000435 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000436 (implicit EFLAGS)]>;
437
438// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000439def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
440 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000441 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
442 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000443def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
444 "add{q}\t{$src2, $dst|$dst, $src2}",
445 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
446 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447} // isConvertibleToThreeAddress
448
Bill Wendlingae034ed2008-12-12 00:56:36 +0000449// Register-Memory Addition
450def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
451 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000452 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000453 (implicit EFLAGS)]>;
Sean Callanan7e7df0e2009-09-15 20:53:57 +0000454
Sean Callanan84df9312009-09-15 21:43:27 +0000455// Register-Register Addition - Equivalent to the normal rr form (ADD64rr), but
456// differently encoded.
Sean Callanan7e7df0e2009-09-15 20:53:57 +0000457def ADD64mrmrr : RI<0x03, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
458 "add{l}\t{$src2, $dst|$dst, $src2}", []>;
459
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460} // isTwoAddress
461
Bill Wendlingae034ed2008-12-12 00:56:36 +0000462// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000463def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000464 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000465 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
466 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000467def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000468 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000469 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
470 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000471def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
472 "add{q}\t{$src2, $dst|$dst, $src2}",
473 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
474 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475
Evan Cheng259471d2007-10-05 17:59:57 +0000476let Uses = [EFLAGS] in {
Sean Callanan8562bef2009-09-11 19:01:56 +0000477
478def ADC64i32 : RI<0x15, RawFrm, (outs), (ins i32imm:$src),
479 "adc{q}\t{$src, %rax|%rax, $src}", []>;
480
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481let isTwoAddress = 1 in {
482let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000483def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000484 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000485 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486
Dale Johannesen747fe522009-06-02 03:12:52 +0000487def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000488 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000489 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490
Dale Johannesen747fe522009-06-02 03:12:52 +0000491def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000492 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000493 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
494def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000495 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000496 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497} // isTwoAddress
498
Evan Chengb783fa32007-07-19 01:14:50 +0000499def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000501 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000502def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000503 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000504 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000505def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
506 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000507 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000508} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509
510let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000511// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000512def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000513 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000514 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
515 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000516
517// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000518def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000519 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000520 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
521 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000522
523// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000524def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
525 (ins GR64:$src1, i64i8imm:$src2),
526 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000527 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
528 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000529def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
530 (ins GR64:$src1, i64i32imm:$src2),
531 "sub{q}\t{$src2, $dst|$dst, $src2}",
532 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
533 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534} // isTwoAddress
535
Sean Callanan8562bef2009-09-11 19:01:56 +0000536def SUB64i32 : RI<0x2D, RawFrm, (outs), (ins i32imm:$src),
537 "sub{q}\t{$src, %rax|%rax, $src}", []>;
538
Bill Wendlingae034ed2008-12-12 00:56:36 +0000539// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000540def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000541 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000542 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
543 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000544
545// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000546def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000547 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000548 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000549 addr:$dst),
550 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000551def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
552 "sub{q}\t{$src2, $dst|$dst, $src2}",
553 [(store (sub (load addr:$dst), i64immSExt32:$src2),
554 addr:$dst),
555 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
Evan Cheng259471d2007-10-05 17:59:57 +0000557let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000559def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000560 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000561 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562
Dale Johannesen747fe522009-06-02 03:12:52 +0000563def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000564 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000565 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000566
Dale Johannesen747fe522009-06-02 03:12:52 +0000567def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000568 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000569 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
570def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000571 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000572 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573} // isTwoAddress
574
Sean Callanan8562bef2009-09-11 19:01:56 +0000575def SBB64i32 : RI<0x1D, RawFrm, (outs), (ins i32imm:$src),
576 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
577
Evan Chengb783fa32007-07-19 01:14:50 +0000578def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000579 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000580 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000581def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000582 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000583 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000584def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
585 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000586 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000587} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000588} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589
590// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000591let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000592def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000593 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000594let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000595def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000596 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597
598// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000599def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000600 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000601let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000602def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000603 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
604}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605
Evan Cheng55687072007-09-14 21:48:26 +0000606let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607let isTwoAddress = 1 in {
608let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000609// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000610def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
611 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000612 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000613 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
614 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615
Bill Wendlingf5399032008-12-12 21:15:41 +0000616// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000617def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
618 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000619 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000620 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
621 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622} // isTwoAddress
623
624// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000625
Bill Wendlingf5399032008-12-12 21:15:41 +0000626// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000628 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000629 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000630 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
631 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000632def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
633 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
634 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
635 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
636 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000637
Bill Wendlingf5399032008-12-12 21:15:41 +0000638// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000640 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000641 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000642 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000643 i64immSExt8:$src2)),
644 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000645def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
646 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
647 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
648 [(set GR64:$dst, (mul (load addr:$src1),
649 i64immSExt32:$src2)),
650 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000651} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000652
653// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000654let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000655def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000656 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000657// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000658def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000659 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000660let mayLoad = 1 in {
661def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
662 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000663def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000664 "idiv{q}\t$src", []>;
665}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000666}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667
668// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000669let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000671def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000672 [(set GR64:$dst, (ineg GR64:$src)),
673 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000674def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000675 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
676 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677
678let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000679def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000680 [(set GR64:$dst, (add GR64:$src, 1)),
681 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000682def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000683 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
684 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685
686let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000687def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000688 [(set GR64:$dst, (add GR64:$src, -1)),
689 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000690def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000691 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
692 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693
694// In 64-bit mode, single byte INC and DEC cannot be encoded.
695let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
696// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000697def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000698 [(set GR16:$dst, (add GR16:$src, 1)),
699 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000701def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000702 [(set GR32:$dst, (add GR32:$src, 1)),
703 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000705def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000706 [(set GR16:$dst, (add GR16:$src, -1)),
707 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000709def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000710 [(set GR32:$dst, (add GR32:$src, -1)),
711 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 Requires<[In64BitMode]>;
713} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000714
715// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
716// how to unfold them.
717let isTwoAddress = 0, CodeSize = 2 in {
718 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000719 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
720 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000721 OpSize, Requires<[In64BitMode]>;
722 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000723 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
724 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000725 Requires<[In64BitMode]>;
726 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000727 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
728 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000729 OpSize, Requires<[In64BitMode]>;
730 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000731 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
732 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000733 Requires<[In64BitMode]>;
734}
Evan Cheng55687072007-09-14 21:48:26 +0000735} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736
737
Evan Cheng55687072007-09-14 21:48:26 +0000738let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739// Shift instructions
740let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000743 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000745let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Sean Callananca503e02009-09-16 02:28:43 +0000749// NOTE: We don't include patterns for shifts of a register by one, because
750// 'add reg,reg' is cheaper.
751def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
752 "shr{q}\t$dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753} // isTwoAddress
754
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000755let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000756def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000757 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000758 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000759def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000760 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000762def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000763 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
765
766let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000767let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000768def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000769 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000770 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000771def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000772 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000774def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000775 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
777} // isTwoAddress
778
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000779let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000780def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000781 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000782 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000783def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000786def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000787 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000788 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
789
790let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000791let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000792def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000793 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000794 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000795def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000798def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000799 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
801} // isTwoAddress
802
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000804def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000806 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000807def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000810def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000811 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
813
814// Rotate instructions
Sean Callanan3c8eecd2009-09-18 19:35:23 +0000815
816let isTwoAddress = 1 in {
817def RCL64r1 : RI<0xD1, MRM2r, (outs GR64:$dst), (ins GR64:$src),
818 "rcl{q}\t{1, $dst|$dst, 1}", []>;
819def RCL64m1 : RI<0xD1, MRM2m, (outs i64mem:$dst), (ins i64mem:$src),
820 "rcl{q}\t{1, $dst|$dst, 1}", []>;
821let Uses = [CL] in {
822def RCL64rCL : RI<0xD3, MRM2r, (outs GR64:$dst), (ins GR64:$src),
823 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
824def RCL64mCL : RI<0xD3, MRM2m, (outs i64mem:$dst), (ins i64mem:$src),
825 "rcl{q}\t{%cl, $dst|$dst, CL}", []>;
826}
827def RCL64ri : RIi8<0xC1, MRM2r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
828 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
829def RCL64mi : RIi8<0xC1, MRM2m, (outs i64mem:$dst), (ins i64mem:$src, i8imm:$cnt),
830 "rcl{q}\t{$cnt, $dst|$dst, $cnt}", []>;
831
832def RCR64r1 : RI<0xD1, MRM3r, (outs GR64:$dst), (ins GR64:$src),
833 "rcr{q}\t{1, $dst|$dst, 1}", []>;
834def RCR64m1 : RI<0xD1, MRM3m, (outs i64mem:$dst), (ins i64mem:$src),
835 "rcr{q}\t{1, $dst|$dst, 1}", []>;
836let Uses = [CL] in {
837def RCR64rCL : RI<0xD3, MRM3r, (outs GR64:$dst), (ins GR64:$src),
838 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
839def RCR64mCL : RI<0xD3, MRM3m, (outs i64mem:$dst), (ins i64mem:$src),
840 "rcr{q}\t{%cl, $dst|$dst, CL}", []>;
841}
842def RCR64ri : RIi8<0xC1, MRM3r, (outs GR64:$dst), (ins GR64:$src, i8imm:$cnt),
843 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
844def RCR64mi : RIi8<0xC1, MRM3m, (outs i64mem:$dst), (ins i64mem:$src, i8imm:$cnt),
845 "rcr{q}\t{$cnt, $dst|$dst, $cnt}", []>;
846}
847
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000849let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000850def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000851 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000852 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000853def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000854 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000856def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000857 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000858 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
859} // isTwoAddress
860
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000861let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000862def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000863 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000864 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000865def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000866 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000868def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000869 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
871
872let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000873let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000874def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000875 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000876 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000877def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000878 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000880def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000881 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000882 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
883} // isTwoAddress
884
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000885let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000886def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000887 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000888 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000889def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000890 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000892def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000893 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000894 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
895
896// Double shift instructions (generalizations of rotate)
897let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000898let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000899def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000900 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
901 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000902def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000903 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
904 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000905}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906
907let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
908def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000909 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000910 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
911 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
912 (i8 imm:$src3)))]>,
913 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000915 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000916 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
917 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
918 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000919 TB;
920} // isCommutable
921} // isTwoAddress
922
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000923let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000924def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000925 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
926 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
927 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000928def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000929 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
930 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
931 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000932}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000933def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000934 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000935 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
936 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
937 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 TB;
939def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000940 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000941 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
942 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
943 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000944 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000945} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946
947//===----------------------------------------------------------------------===//
948// Logical Instructions...
949//
950
Evan Cheng5b51c242009-01-21 19:45:31 +0000951let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000952def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000954def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
956
Evan Cheng55687072007-09-14 21:48:26 +0000957let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000958def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
959 "and{q}\t{$src, %rax|%rax, $src}", []>;
960
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961let isTwoAddress = 1 in {
962let isCommutable = 1 in
963def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000964 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000966 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
967 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000969 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000970 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000971 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
972 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000974 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000975 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000976 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
977 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000978def AND64ri32 : RIi32<0x81, MRM4r,
979 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
980 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000981 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
982 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000983} // isTwoAddress
984
985def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000986 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000987 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000988 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
989 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000991 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000992 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000993 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
994 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000995def AND64mi32 : RIi32<0x81, MRM4m,
996 (outs), (ins i64mem:$dst, i64i32imm:$src),
997 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000998 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
999 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000
1001let isTwoAddress = 1 in {
1002let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001003def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001005 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
1006 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001007def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001008 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001009 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
1010 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001011def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001013 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
1014 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001015def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
1016 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001017 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
1018 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001019} // isTwoAddress
1020
Evan Chengb783fa32007-07-19 01:14:50 +00001021def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001022 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001023 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
1024 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001025def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001026 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001027 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
1028 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001029def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1030 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001031 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1032 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033
Sean Callanan8562bef2009-09-11 19:01:56 +00001034def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
1035 "or{q}\t{$src, %rax|%rax, $src}", []>;
1036
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001037let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +00001038let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001039def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001041 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
1042 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001043def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001044 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001045 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
1046 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001047def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1048 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001049 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1050 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +00001052 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001053 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001054 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1055 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056} // isTwoAddress
1057
Evan Chengb783fa32007-07-19 01:14:50 +00001058def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001059 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001060 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1061 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001062def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001064 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1065 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001066def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1067 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001068 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1069 (implicit EFLAGS)]>;
Sean Callanan794457a2009-09-10 19:52:26 +00001070
1071def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1072 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1073
Evan Cheng55687072007-09-14 21:48:26 +00001074} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075
1076//===----------------------------------------------------------------------===//
1077// Comparison Instructions...
1078//
1079
1080// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001081let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001082def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1083 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001085def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001086 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001087 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1088 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001089def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001090 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001091 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1092 (implicit EFLAGS)]>;
1093def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1094 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001096 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1097 (implicit EFLAGS)]>;
1098def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1099 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001100 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001101 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1102 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103
Sean Callanan251676e2009-09-02 00:55:49 +00001104
1105def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1106 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001107def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001108 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001109 [(X86cmp GR64:$src1, GR64:$src2),
1110 (implicit EFLAGS)]>;
Sean Callanan11490dc2009-09-16 21:11:23 +00001111def CMP64mrmrr : RI<0x3B, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
1112 "cmp{q}\t{$src2, $src1|$src1, $src2}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001113def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001114 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001115 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1116 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001117def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001118 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001119 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1120 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001121def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1122 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1123 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1124 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001125def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001127 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001128 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001129def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001130 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001131 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001132 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001133def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1134 (ins i64mem:$src1, i64i32imm:$src2),
1135 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1136 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1137 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001138} // Defs = [EFLAGS]
1139
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001140// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001141// TODO: BTC, BTR, and BTS
1142let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001143def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001144 "bt{q}\t{$src2, $src1|$src1, $src2}",
1145 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001146 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001147
1148// Unlike with the register+register form, the memory+register form of the
1149// bt instruction does not ignore the high bits of the index. From ISel's
1150// perspective, this is pretty bizarre. Disable these instructions for now.
1151//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1152// "bt{q}\t{$src2, $src1|$src1, $src2}",
1153// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1154// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001155
1156def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1157 "bt{q}\t{$src2, $src1|$src1, $src2}",
1158 [(X86bt GR64:$src1, i64immSExt8:$src2),
1159 (implicit EFLAGS)]>, TB;
1160// Note that these instructions don't need FastBTMem because that
1161// only applies when the other operand is in a register. When it's
1162// an immediate, bt is still fast.
1163def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1164 "bt{q}\t{$src2, $src1|$src1, $src2}",
1165 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1166 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001167} // Defs = [EFLAGS]
1168
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001169// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001170let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001171let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001172def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001173 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001174 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001175 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001176 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001178 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001179 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001180 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001181 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001183 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001184 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001186 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001188 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001189 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001191 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001193 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001194 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001196 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001198 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001199 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001201 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001202def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001203 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001204 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001206 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001207def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001208 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001209 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001211 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001213 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001214 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001215 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001216 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001217def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001218 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001221 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001223 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001224 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001226 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001228 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001229 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001231 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001232def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001233 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001236 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001237def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001238 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001239 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001241 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001242def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1243 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1244 "cmovo\t{$src2, $dst|$dst, $src2}",
1245 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1246 X86_COND_O, EFLAGS))]>, TB;
1247def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1248 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1249 "cmovno\t{$src2, $dst|$dst, $src2}",
1250 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1251 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001252} // isCommutable = 1
1253
1254def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1255 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1256 "cmovb\t{$src2, $dst|$dst, $src2}",
1257 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1258 X86_COND_B, EFLAGS))]>, TB;
1259def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1260 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1261 "cmovae\t{$src2, $dst|$dst, $src2}",
1262 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1263 X86_COND_AE, EFLAGS))]>, TB;
1264def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1265 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1266 "cmove\t{$src2, $dst|$dst, $src2}",
1267 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1268 X86_COND_E, EFLAGS))]>, TB;
1269def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1270 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1271 "cmovne\t{$src2, $dst|$dst, $src2}",
1272 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1273 X86_COND_NE, EFLAGS))]>, TB;
1274def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1275 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1276 "cmovbe\t{$src2, $dst|$dst, $src2}",
1277 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1278 X86_COND_BE, EFLAGS))]>, TB;
1279def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1280 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1281 "cmova\t{$src2, $dst|$dst, $src2}",
1282 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1283 X86_COND_A, EFLAGS))]>, TB;
1284def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1285 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1286 "cmovl\t{$src2, $dst|$dst, $src2}",
1287 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1288 X86_COND_L, EFLAGS))]>, TB;
1289def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1290 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1291 "cmovge\t{$src2, $dst|$dst, $src2}",
1292 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1293 X86_COND_GE, EFLAGS))]>, TB;
1294def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1295 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1296 "cmovle\t{$src2, $dst|$dst, $src2}",
1297 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1298 X86_COND_LE, EFLAGS))]>, TB;
1299def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1300 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1301 "cmovg\t{$src2, $dst|$dst, $src2}",
1302 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1303 X86_COND_G, EFLAGS))]>, TB;
1304def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1305 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1306 "cmovs\t{$src2, $dst|$dst, $src2}",
1307 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1308 X86_COND_S, EFLAGS))]>, TB;
1309def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1310 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1311 "cmovns\t{$src2, $dst|$dst, $src2}",
1312 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1313 X86_COND_NS, EFLAGS))]>, TB;
1314def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1315 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1316 "cmovp\t{$src2, $dst|$dst, $src2}",
1317 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1318 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001320 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001323 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001324def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1325 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1326 "cmovo\t{$src2, $dst|$dst, $src2}",
1327 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1328 X86_COND_O, EFLAGS))]>, TB;
1329def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1330 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1331 "cmovno\t{$src2, $dst|$dst, $src2}",
1332 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1333 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001334} // isTwoAddress
1335
1336//===----------------------------------------------------------------------===//
1337// Conversion Instructions...
1338//
1339
1340// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001341def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001342 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001343 [(set GR64:$dst,
1344 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001345def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001346 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001347 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1348 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001349def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001350 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001351 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001352def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001353 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001354 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001355def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001356 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001357 [(set GR64:$dst,
1358 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001359def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001360 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001361 [(set GR64:$dst,
1362 (int_x86_sse2_cvttsd2si64
1363 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364
1365// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001366def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001367 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001368 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001369def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001370 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001371 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001372
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001373let isTwoAddress = 1 in {
1374def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001375 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001376 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001377 [(set VR128:$dst,
1378 (int_x86_sse2_cvtsi642sd VR128:$src1,
1379 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001380def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001381 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001382 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001383 [(set VR128:$dst,
1384 (int_x86_sse2_cvtsi642sd VR128:$src1,
1385 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001386} // isTwoAddress
1387
1388// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001389def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001390 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001391 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001392def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001393 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001394 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001395
1396let isTwoAddress = 1 in {
1397 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1398 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1399 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1400 [(set VR128:$dst,
1401 (int_x86_sse_cvtsi642ss VR128:$src1,
1402 GR64:$src2))]>;
1403 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1404 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1405 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1406 [(set VR128:$dst,
1407 (int_x86_sse_cvtsi642ss VR128:$src1,
1408 (loadi64 addr:$src2)))]>;
1409}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001410
1411// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001412def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001413 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001414 [(set GR64:$dst,
1415 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001416def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001417 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001418 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1419 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001420def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001421 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001422 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001423def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001424 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001425 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001426def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001427 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001428 [(set GR64:$dst,
1429 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001430def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001431 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001432 [(set GR64:$dst,
1433 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1434
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001435//===----------------------------------------------------------------------===//
1436// Alias Instructions
1437//===----------------------------------------------------------------------===//
1438
Dan Gohman027cd112007-09-17 14:55:08 +00001439// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1440// equivalent due to implicit zero-extending, and it sometimes has a smaller
1441// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001442// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001443// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001444let AddedComplexity = 1 in
1445def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001446 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001447
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001448
1449// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001450let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001451def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Chris Lattnerbe7efcc2009-10-19 19:51:42 +00001452 "", [(set GR64:$dst, i64immZExt32:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001453
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001454//===----------------------------------------------------------------------===//
1455// Thread Local Storage Instructions
1456//===----------------------------------------------------------------------===//
1457
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001458// All calls clobber the non-callee saved registers. RSP is marked as
1459// a use to prevent stack-pointer assignments that appear immediately
1460// before calls from potentially appearing dead.
1461let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1462 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1463 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1464 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1465 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1466 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001467def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001468 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001469 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001470 ".word\t0x6666; "
1471 "rex64; "
1472 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001473 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001474 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001475
Daniel Dunbar75a07302009-08-11 22:24:40 +00001476let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001477def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1478 "movq\t%gs:$src, $dst",
1479 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1480
Daniel Dunbar75a07302009-08-11 22:24:40 +00001481let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001482def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1483 "movq\t%fs:$src, $dst",
1484 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1485
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001486//===----------------------------------------------------------------------===//
1487// Atomic Instructions
1488//===----------------------------------------------------------------------===//
1489
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001490let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001491def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001492 "lock\n\t"
1493 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001494 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1495}
1496
Dan Gohmana41a1c092008-08-06 15:52:50 +00001497let Constraints = "$val = $dst" in {
1498let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001499def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001500 "lock\n\t"
1501 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001502 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001503 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001504
Evan Chenga1e80602008-04-19 02:05:42 +00001505def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001506 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001507 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001508}
1509
Evan Chengb723fb52009-07-30 08:33:02 +00001510// Optimized codegen when the non-memory output is not used.
Edwin Törökce819f12009-10-19 11:00:58 +00001511let Defs = [EFLAGS] in {
Evan Chengb723fb52009-07-30 08:33:02 +00001512// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1513def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1514 "lock\n\t"
1515 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1516def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1517 (ins i64mem:$dst, i64i8imm :$src2),
1518 "lock\n\t"
1519 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1520def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1521 (ins i64mem:$dst, i64i32imm :$src2),
1522 "lock\n\t"
1523 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1524def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1525 "lock\n\t"
1526 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1527def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1528 (ins i64mem:$dst, i64i8imm :$src2),
1529 "lock\n\t"
1530 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1531def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1532 (ins i64mem:$dst, i64i32imm:$src2),
1533 "lock\n\t"
1534 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1535def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1536 "lock\n\t"
1537 "inc{q}\t$dst", []>, LOCK;
1538def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1539 "lock\n\t"
1540 "dec{q}\t$dst", []>, LOCK;
Edwin Törökce819f12009-10-19 11:00:58 +00001541}
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001542// Atomic exchange, and, or, xor
1543let Constraints = "$val = $dst", Defs = [EFLAGS],
Dan Gohman30afe012009-10-29 18:10:34 +00001544 usesCustomInserter = 1 in {
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001545def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001546 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001547 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001548def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001549 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001550 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001551def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001552 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001553 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001554def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001555 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001556 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001557def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001558 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001559 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001560def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001561 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001562 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001563def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001564 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001565 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001566def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001567 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001568 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001569}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001570
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001571// Segmentation support instructions
1572
1573// i16mem operand in LAR64rm and GR32 operand in LAR32rr is not a typo.
1574def LAR64rm : RI<0x02, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
1575 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
1576def LAR64rr : RI<0x02, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
1577 "lar{q}\t{$src, $dst|$dst, $src}", []>, TB;
Sean Callanan23f33d72009-09-16 22:59:28 +00001578
1579// String manipulation instructions
1580
1581def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", []>;
Sean Callanan2eddf5d2009-09-16 21:55:34 +00001582
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001583//===----------------------------------------------------------------------===//
1584// Non-Instruction Patterns
1585//===----------------------------------------------------------------------===//
1586
Chris Lattner0d2dad62009-07-11 22:50:33 +00001587// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1588// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1589// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001591 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001592def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001593 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001594def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001595 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001596def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001597 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001598def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1599 (MOV64ri tblockaddress:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001600
Chris Lattnerc04cd042009-07-11 23:17:29 +00001601// In static codegen with small code model, we can get the address of a label
1602// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1603// the MOV64ri64i32 should accept these.
1604def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1605 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1606def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1607 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1608def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1609 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1610def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1611 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001612def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1613 (MOV64ri64i32 tblockaddress:$dst)>, Requires<[SmallCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001614
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001615// In kernel code model, we can get the address of a label
1616// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1617// the MOV64ri32 should accept these.
1618def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1619 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1620def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1621 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1622def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1623 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1624def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1625 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001626def : Pat<(i64 (X86Wrapper tblockaddress:$dst)),
1627 (MOV64ri32 tblockaddress:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001628
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001629// If we have small model and -static mode, it is safe to store global addresses
1630// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001631// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1633 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001634 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001635def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1636 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001637 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001638def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1639 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001640 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001641def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1642 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001643 Requires<[NearData, IsStatic]>;
Dan Gohman064403e2009-10-30 01:28:02 +00001644def : Pat<(store (i64 (X86Wrapper tblockaddress:$src)), addr:$dst),
1645 (MOV64mi32 addr:$dst, tblockaddress:$src)>,
1646 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001647
1648// Calls
1649// Direct PC relative function call for small code model. 32-bit displacement
1650// sign extended to 64-bit.
1651def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001652 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001653def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001654 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1655
1656def : Pat<(X86call (i64 tglobaladdr:$dst)),
1657 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1658def : Pat<(X86call (i64 texternalsym:$dst)),
1659 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001660
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001661// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001662def : Pat<(X86tcret GR64:$dst, imm:$off),
1663 (TCRETURNri64 GR64:$dst, imm:$off)>;
1664
1665def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
Dan Gohman66fe2bc2009-11-30 23:33:37 +00001666 (TCRETURNdi64 tglobaladdr:$dst, imm:$off)>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001667
1668def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1669 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1670
Dan Gohmanec596042007-09-17 14:35:24 +00001671// Comparisons.
1672
1673// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001674def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001675 (TEST64rr GR64:$src1, GR64:$src1)>;
1676
Dan Gohman0a3c5222009-01-07 01:00:24 +00001677// Conditional moves with folded loads with operands swapped and conditions
1678// inverted.
1679def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1680 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1681def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1682 (CMOVB64rm GR64:$src2, addr:$src1)>;
1683def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1684 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1685def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1686 (CMOVE64rm GR64:$src2, addr:$src1)>;
1687def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1688 (CMOVA64rm GR64:$src2, addr:$src1)>;
1689def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1690 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1691def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1692 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1693def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1694 (CMOVL64rm GR64:$src2, addr:$src1)>;
1695def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1696 (CMOVG64rm GR64:$src2, addr:$src1)>;
1697def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1698 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1699def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1700 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1701def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1702 (CMOVP64rm GR64:$src2, addr:$src1)>;
1703def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1704 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1705def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1706 (CMOVS64rm GR64:$src2, addr:$src1)>;
1707def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1708 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1709def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1710 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001711
Duncan Sands082524c2008-01-23 20:39:46 +00001712// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001713def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1714
1715// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001716// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1717// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1718// partial-register updates.
1719def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1720def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1721def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1722// For other extloads, use subregs, since the high contents of the register are
1723// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001724def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001725 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001726 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001727
Dan Gohman9959b052009-08-26 14:59:13 +00001728// anyext. Define these to do an explicit zero-extend to
1729// avoid partial-register updates.
1730def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1731def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1732def : Pat<(i64 (anyext GR32:$src)),
1733 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001734
1735//===----------------------------------------------------------------------===//
1736// Some peepholes
1737//===----------------------------------------------------------------------===//
1738
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001739// Odd encoding trick: -128 fits into an 8-bit immediate field while
1740// +128 doesn't, so in this special case use a sub instead of an add.
1741def : Pat<(add GR64:$src1, 128),
1742 (SUB64ri8 GR64:$src1, -128)>;
1743def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1744 (SUB64mi8 addr:$dst, -128)>;
1745
1746// The same trick applies for 32-bit immediate fields in 64-bit
1747// instructions.
1748def : Pat<(add GR64:$src1, 0x0000000080000000),
1749 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1750def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1751 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1752
Dan Gohman47a419d2008-08-07 02:54:50 +00001753// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001754def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001755 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001756// r & (2^16-1) ==> movz
1757def : Pat<(and GR64:$src, 0xffff),
1758 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1759// r & (2^8-1) ==> movz
1760def : Pat<(and GR64:$src, 0xff),
1761 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001762// r & (2^8-1) ==> movz
1763def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001764 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001765 Requires<[In64BitMode]>;
1766// r & (2^8-1) ==> movz
1767def : Pat<(and GR16:$src1, 0xff),
1768 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1769 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001770
Dan Gohmandd612bb2008-08-20 21:27:32 +00001771// sext_inreg patterns
1772def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001773 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001774def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001775 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001776def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001777 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001778def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001779 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001780 Requires<[In64BitMode]>;
1781def : Pat<(sext_inreg GR16:$src, i8),
1782 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1783 Requires<[In64BitMode]>;
1784
1785// trunc patterns
1786def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001787 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001788def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001789 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001790def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001791 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001792def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001793 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001794 Requires<[In64BitMode]>;
1795def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001796 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1797 Requires<[In64BitMode]>;
1798
1799// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001800// For now, be conservative on x86-64 and use an h-register extract only if the
1801// value is immediately zero-extended or stored, which are somewhat common
1802// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1803// from being allocated in the same instruction as the h register, as there's
1804// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001805
1806// h-register extract and zero-extend.
1807def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1808 (SUBREG_TO_REG
1809 (i64 0),
1810 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001811 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001812 x86_subreg_8bit_hi)),
1813 x86_subreg_32bit)>;
1814def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1815 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001816 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001817 x86_subreg_8bit_hi))>,
1818 Requires<[In64BitMode]>;
1819def : Pat<(srl_su GR16:$src, (i8 8)),
1820 (EXTRACT_SUBREG
1821 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001822 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001823 x86_subreg_8bit_hi)),
1824 x86_subreg_16bit)>,
1825 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001826def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1827 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001828 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00001829 x86_subreg_8bit_hi))>,
1830 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001831def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1832 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001833 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00001834 x86_subreg_8bit_hi))>,
1835 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001836def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1837 (SUBREG_TO_REG
1838 (i64 0),
1839 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001840 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Evan Cheng957ca282009-05-29 01:44:43 +00001841 x86_subreg_8bit_hi)),
1842 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001843def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1844 (SUBREG_TO_REG
1845 (i64 0),
1846 (MOVZX32_NOREXrr8
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001847 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman9959b052009-08-26 14:59:13 +00001848 x86_subreg_8bit_hi)),
1849 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001850
1851// h-register extract and store.
1852def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1853 (MOV8mr_NOREX
1854 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001855 (EXTRACT_SUBREG (i64 (COPY_TO_REGCLASS GR64:$src, GR64_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001856 x86_subreg_8bit_hi))>;
1857def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1858 (MOV8mr_NOREX
1859 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001860 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001861 x86_subreg_8bit_hi))>,
1862 Requires<[In64BitMode]>;
1863def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1864 (MOV8mr_NOREX
1865 addr:$dst,
Anton Korobeynikovd9331212009-11-02 00:11:39 +00001866 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
Dan Gohman744d4622009-04-13 16:09:41 +00001867 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001868 Requires<[In64BitMode]>;
1869
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001870// (shl x, 1) ==> (add x, x)
1871def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1872
Evan Cheng76a64c72008-08-30 02:03:58 +00001873// (shl x (and y, 63)) ==> (shl x, y)
1874def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1875 (SHL64rCL GR64:$src1)>;
1876def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1877 (SHL64mCL addr:$dst)>;
1878
1879def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1880 (SHR64rCL GR64:$src1)>;
1881def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1882 (SHR64mCL addr:$dst)>;
1883
1884def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1885 (SAR64rCL GR64:$src1)>;
1886def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1887 (SAR64mCL addr:$dst)>;
1888
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1890def : Pat<(or (srl GR64:$src1, CL:$amt),
1891 (shl GR64:$src2, (sub 64, CL:$amt))),
1892 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1893
1894def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1895 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1896 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1897
Dan Gohman921581d2008-10-17 01:23:35 +00001898def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1899 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1900 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1901
1902def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1903 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1904 addr:$dst),
1905 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1906
1907def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1908 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1909
1910def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1911 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1912 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1913
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1915def : Pat<(or (shl GR64:$src1, CL:$amt),
1916 (srl GR64:$src2, (sub 64, CL:$amt))),
1917 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1918
1919def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1920 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1921 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1922
Dan Gohman921581d2008-10-17 01:23:35 +00001923def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1924 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1925 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1926
1927def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1928 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1929 addr:$dst),
1930 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1931
1932def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1933 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1934
1935def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1936 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1937 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1938
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001939// X86 specific add which produces a flag.
1940def : Pat<(addc GR64:$src1, GR64:$src2),
1941 (ADD64rr GR64:$src1, GR64:$src2)>;
1942def : Pat<(addc GR64:$src1, (load addr:$src2)),
1943 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001944def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1945 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001946def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1947 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001948
1949def : Pat<(subc GR64:$src1, GR64:$src2),
1950 (SUB64rr GR64:$src1, GR64:$src2)>;
1951def : Pat<(subc GR64:$src1, (load addr:$src2)),
1952 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001953def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1954 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001955def : Pat<(subc GR64:$src1, imm:$src2),
1956 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001957
Bill Wendlingf5399032008-12-12 21:15:41 +00001958//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001959// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001960//===----------------------------------------------------------------------===//
1961
Dan Gohman99a12192009-03-04 19:44:21 +00001962// Register-Register Addition with EFLAGS result
1963def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001964 (implicit EFLAGS)),
1965 (ADD64rr GR64:$src1, GR64:$src2)>;
1966
Dan Gohman99a12192009-03-04 19:44:21 +00001967// Register-Integer Addition with EFLAGS result
1968def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001969 (implicit EFLAGS)),
1970 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001971def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001972 (implicit EFLAGS)),
1973 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001974
Dan Gohman99a12192009-03-04 19:44:21 +00001975// Register-Memory Addition with EFLAGS result
1976def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001977 (implicit EFLAGS)),
1978 (ADD64rm GR64:$src1, addr:$src2)>;
1979
Dan Gohman99a12192009-03-04 19:44:21 +00001980// Memory-Register Addition with EFLAGS result
1981def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001982 addr:$dst),
1983 (implicit EFLAGS)),
1984 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001985def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001986 addr:$dst),
1987 (implicit EFLAGS)),
1988 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001989def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001990 addr:$dst),
1991 (implicit EFLAGS)),
1992 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001993
Dan Gohman99a12192009-03-04 19:44:21 +00001994// Register-Register Subtraction with EFLAGS result
1995def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001996 (implicit EFLAGS)),
1997 (SUB64rr GR64:$src1, GR64:$src2)>;
1998
Dan Gohman99a12192009-03-04 19:44:21 +00001999// Register-Memory Subtraction with EFLAGS result
2000def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002001 (implicit EFLAGS)),
2002 (SUB64rm GR64:$src1, addr:$src2)>;
2003
Dan Gohman99a12192009-03-04 19:44:21 +00002004// Register-Integer Subtraction with EFLAGS result
2005def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002006 (implicit EFLAGS)),
2007 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002008def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002009 (implicit EFLAGS)),
2010 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002011
Dan Gohman99a12192009-03-04 19:44:21 +00002012// Memory-Register Subtraction with EFLAGS result
2013def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002014 addr:$dst),
2015 (implicit EFLAGS)),
2016 (SUB64mr addr:$dst, GR64:$src2)>;
2017
Dan Gohman99a12192009-03-04 19:44:21 +00002018// Memory-Integer Subtraction with EFLAGS result
2019def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002020 addr:$dst),
2021 (implicit EFLAGS)),
2022 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002023def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002024 addr:$dst),
2025 (implicit EFLAGS)),
2026 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002027
Dan Gohman99a12192009-03-04 19:44:21 +00002028// Register-Register Signed Integer Multiplication with EFLAGS result
2029def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002030 (implicit EFLAGS)),
2031 (IMUL64rr GR64:$src1, GR64:$src2)>;
2032
Dan Gohman99a12192009-03-04 19:44:21 +00002033// Register-Memory Signed Integer Multiplication with EFLAGS result
2034def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00002035 (implicit EFLAGS)),
2036 (IMUL64rm GR64:$src1, addr:$src2)>;
2037
Dan Gohman99a12192009-03-04 19:44:21 +00002038// Register-Integer Signed Integer Multiplication with EFLAGS result
2039def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002040 (implicit EFLAGS)),
2041 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002042def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002043 (implicit EFLAGS)),
2044 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00002045
Dan Gohman99a12192009-03-04 19:44:21 +00002046// Memory-Integer Signed Integer Multiplication with EFLAGS result
2047def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00002048 (implicit EFLAGS)),
2049 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00002050def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00002051 (implicit EFLAGS)),
2052 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002053
Dan Gohman99a12192009-03-04 19:44:21 +00002054// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00002055def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
2056 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2057def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
2058 (implicit EFLAGS)),
2059 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2060def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
2061 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
2062def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
2063 (implicit EFLAGS)),
2064 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
2065
2066def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
2067 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2068def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
2069 (implicit EFLAGS)),
2070 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2071def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
2072 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2073def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2074 (implicit EFLAGS)),
2075 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2076
Dan Gohman99a12192009-03-04 19:44:21 +00002077def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2078 (INC64r GR64:$src)>;
2079def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2080 (implicit EFLAGS)),
2081 (INC64m addr:$dst)>;
2082def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2083 (DEC64r GR64:$src)>;
2084def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2085 (implicit EFLAGS)),
2086 (DEC64m addr:$dst)>;
2087
Dan Gohman12e03292009-09-18 19:59:53 +00002088// Register-Register Logical Or with EFLAGS result
2089def : Pat<(parallel (X86or_flag GR64:$src1, GR64:$src2),
2090 (implicit EFLAGS)),
2091 (OR64rr GR64:$src1, GR64:$src2)>;
2092
2093// Register-Integer Logical Or with EFLAGS result
2094def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt8:$src2),
2095 (implicit EFLAGS)),
2096 (OR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2097def : Pat<(parallel (X86or_flag GR64:$src1, i64immSExt32:$src2),
2098 (implicit EFLAGS)),
2099 (OR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2100
2101// Register-Memory Logical Or with EFLAGS result
2102def : Pat<(parallel (X86or_flag GR64:$src1, (loadi64 addr:$src2)),
2103 (implicit EFLAGS)),
2104 (OR64rm GR64:$src1, addr:$src2)>;
2105
2106// Memory-Register Logical Or with EFLAGS result
2107def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), GR64:$src2),
2108 addr:$dst),
2109 (implicit EFLAGS)),
2110 (OR64mr addr:$dst, GR64:$src2)>;
2111def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2112 addr:$dst),
2113 (implicit EFLAGS)),
2114 (OR64mi8 addr:$dst, i64immSExt8:$src2)>;
2115def : Pat<(parallel (store (X86or_flag (loadi64 addr:$dst), i64immSExt32:$src2),
2116 addr:$dst),
2117 (implicit EFLAGS)),
2118 (OR64mi32 addr:$dst, i64immSExt32:$src2)>;
2119
2120// Register-Register Logical XOr with EFLAGS result
2121def : Pat<(parallel (X86xor_flag GR64:$src1, GR64:$src2),
2122 (implicit EFLAGS)),
2123 (XOR64rr GR64:$src1, GR64:$src2)>;
2124
2125// Register-Integer Logical XOr with EFLAGS result
2126def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt8:$src2),
2127 (implicit EFLAGS)),
2128 (XOR64ri8 GR64:$src1, i64immSExt8:$src2)>;
2129def : Pat<(parallel (X86xor_flag GR64:$src1, i64immSExt32:$src2),
2130 (implicit EFLAGS)),
2131 (XOR64ri32 GR64:$src1, i64immSExt32:$src2)>;
2132
2133// Register-Memory Logical XOr with EFLAGS result
2134def : Pat<(parallel (X86xor_flag GR64:$src1, (loadi64 addr:$src2)),
2135 (implicit EFLAGS)),
2136 (XOR64rm GR64:$src1, addr:$src2)>;
2137
2138// Memory-Register Logical XOr with EFLAGS result
2139def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), GR64:$src2),
2140 addr:$dst),
2141 (implicit EFLAGS)),
2142 (XOR64mr addr:$dst, GR64:$src2)>;
2143def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2144 addr:$dst),
2145 (implicit EFLAGS)),
2146 (XOR64mi8 addr:$dst, i64immSExt8:$src2)>;
2147def : Pat<(parallel (store (X86xor_flag (loadi64 addr:$dst), i64immSExt32:$src2),
2148 addr:$dst),
2149 (implicit EFLAGS)),
2150 (XOR64mi32 addr:$dst, i64immSExt32:$src2)>;
2151
2152// Register-Register Logical And with EFLAGS result
2153def : Pat<(parallel (X86and_flag GR64:$src1, GR64:$src2),
2154 (implicit EFLAGS)),
2155 (AND64rr GR64:$src1, GR64:$src2)>;
2156
2157// Register-Integer Logical And with EFLAGS result
2158def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt8:$src2),
2159 (implicit EFLAGS)),
2160 (AND64ri8 GR64:$src1, i64immSExt8:$src2)>;
2161def : Pat<(parallel (X86and_flag GR64:$src1, i64immSExt32:$src2),
2162 (implicit EFLAGS)),
2163 (AND64ri32 GR64:$src1, i64immSExt32:$src2)>;
2164
2165// Register-Memory Logical And with EFLAGS result
2166def : Pat<(parallel (X86and_flag GR64:$src1, (loadi64 addr:$src2)),
2167 (implicit EFLAGS)),
2168 (AND64rm GR64:$src1, addr:$src2)>;
2169
2170// Memory-Register Logical And with EFLAGS result
2171def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), GR64:$src2),
2172 addr:$dst),
2173 (implicit EFLAGS)),
2174 (AND64mr addr:$dst, GR64:$src2)>;
2175def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), i64immSExt8:$src2),
2176 addr:$dst),
2177 (implicit EFLAGS)),
2178 (AND64mi8 addr:$dst, i64immSExt8:$src2)>;
2179def : Pat<(parallel (store (X86and_flag (loadi64 addr:$dst), i64immSExt32:$src2),
2180 addr:$dst),
2181 (implicit EFLAGS)),
2182 (AND64mi32 addr:$dst, i64immSExt32:$src2)>;
2183
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002184//===----------------------------------------------------------------------===//
2185// X86-64 SSE Instructions
2186//===----------------------------------------------------------------------===//
2187
2188// Move instructions...
2189
Evan Chengb783fa32007-07-19 01:14:50 +00002190def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002191 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002192 [(set VR128:$dst,
2193 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002194def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002195 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002196 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2197 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002198
Evan Chengb783fa32007-07-19 01:14:50 +00002199def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002200 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002201 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002202def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002203 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002204 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2205
Evan Chengb783fa32007-07-19 01:14:50 +00002206def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002207 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002208 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002209def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002210 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002211 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002212
2213//===----------------------------------------------------------------------===//
2214// X86-64 SSE4.1 Instructions
2215//===----------------------------------------------------------------------===//
2216
Nate Begeman4294c1f2008-02-12 22:51:28 +00002217/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2218multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002219 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002220 (ins VR128:$src1, i32i8imm:$src2),
2221 !strconcat(OpcodeStr,
2222 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2223 [(set GR64:$dst,
2224 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002225 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002226 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2227 !strconcat(OpcodeStr,
2228 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2229 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2230 addr:$dst)]>, OpSize, REX_W;
2231}
2232
2233defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2234
2235let isTwoAddress = 1 in {
2236 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002237 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002238 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2239 !strconcat(OpcodeStr,
2240 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2241 [(set VR128:$dst,
2242 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2243 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002244 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002245 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2246 !strconcat(OpcodeStr,
2247 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2248 [(set VR128:$dst,
2249 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2250 imm:$src3)))]>, OpSize, REX_W;
2251 }
2252}
2253
2254defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002255
2256// -disable-16bit support.
2257def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2258 (MOV16mi addr:$dst, imm:$src)>;
2259def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2260 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2261def : Pat<(i64 (sextloadi16 addr:$dst)),
2262 (MOVSX64rm16 addr:$dst)>;
2263def : Pat<(i64 (zextloadi16 addr:$dst)),
2264 (MOVZX64rm16 addr:$dst)>;
2265def : Pat<(i64 (extloadi16 addr:$dst)),
2266 (MOVZX64rm16 addr:$dst)>;