blob: 353868a407aff754bef7210ecb575e58873c20d7 [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
Dan Gohman5574cc72008-12-03 18:15:48 +0000312let canFoldAsLoad = 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333// Sign/Zero extenders
334
Dan Gohmanedde1992009-04-13 15:13:28 +0000335// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
336// operand, which makes it a rare instruction with an 8-bit register
337// operand that can never access an h register. If support for h registers
338// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000339def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000340 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000342def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000343 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000344 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000345def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000346 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000348def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000349 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000351def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000352 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000354def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000355 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
357
Dan Gohman9203ab42008-07-30 18:09:17 +0000358// Use movzbl instead of movzbq when the destination is a register; it's
359// equivalent due to implicit zero-extending, and it has a smaller encoding.
360def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
361 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
362 [(set GR64:$dst, (zext GR8:$src))]>, TB;
363def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
364 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
365 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
366// Use movzwl instead of movzwq when the destination is a register; it's
367// equivalent due to implicit zero-extending, and it has a smaller encoding.
368def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
369 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
370 [(set GR64:$dst, (zext GR16:$src))]>, TB;
371def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
372 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
373 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374
Dan Gohman47a419d2008-08-07 02:54:50 +0000375// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000376// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
377// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
378// zero-extension, however this isn't possible when the 32-bit value is
379// defined by a truncate or is copied from something where the high bits aren't
380// necessarily all zero. In such cases, we fall back to these explicit zext
381// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000382def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
383 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
384 [(set GR64:$dst, (zext GR32:$src))]>;
385def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
386 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
387 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
388
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000389// Any instruction that defines a 32-bit result leaves the high half of the
390// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
391// be copying from a truncate, but any other 32-bit operation will zero-extend
392// up to 64 bits.
393def def32 : PatLeaf<(i32 GR32:$src), [{
394 return N->getOpcode() != ISD::TRUNCATE &&
395 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
396 N->getOpcode() != ISD::CopyFromReg;
397}]>;
398
399// In the case of a 32-bit def that is known to implicitly zero-extend,
400// we can use a SUBREG_TO_REG.
401def : Pat<(i64 (zext def32:$src)),
402 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
403
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000404let neverHasSideEffects = 1 in {
405 let Defs = [RAX], Uses = [EAX] in
406 def CDQE : RI<0x98, RawFrm, (outs), (ins),
407 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000409 let Defs = [RAX,RDX], Uses = [RAX] in
410 def CQO : RI<0x99, RawFrm, (outs), (ins),
411 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
412}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413
414//===----------------------------------------------------------------------===//
415// Arithmetic Instructions...
416//
417
Evan Cheng55687072007-09-14 21:48:26 +0000418let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000419
420def ADD64i32 : RI<0x05, RawFrm, (outs), (ins i32imm:$src),
421 "add{q}\t{$src, %rax|%rax, $src}", []>;
422
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423let isTwoAddress = 1 in {
424let isConvertibleToThreeAddress = 1 in {
425let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000426// Register-Register Addition
427def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
428 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000429 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000430 (implicit EFLAGS)]>;
431
432// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000433def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
434 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000435 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
436 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000437def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
438 "add{q}\t{$src2, $dst|$dst, $src2}",
439 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
440 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441} // isConvertibleToThreeAddress
442
Bill Wendlingae034ed2008-12-12 00:56:36 +0000443// Register-Memory Addition
444def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
445 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000446 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000447 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448} // isTwoAddress
449
Bill Wendlingae034ed2008-12-12 00:56:36 +0000450// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000451def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000452 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000453 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
454 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000455def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000457 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
458 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000459def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
460 "add{q}\t{$src2, $dst|$dst, $src2}",
461 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
462 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
Evan Cheng259471d2007-10-05 17:59:57 +0000464let Uses = [EFLAGS] in {
Sean Callanan8562bef2009-09-11 19:01:56 +0000465
466def ADC64i32 : RI<0x15, RawFrm, (outs), (ins i32imm:$src),
467 "adc{q}\t{$src, %rax|%rax, $src}", []>;
468
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469let isTwoAddress = 1 in {
470let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000471def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000472 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000473 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
Dale Johannesen747fe522009-06-02 03:12:52 +0000475def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000476 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000477 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478
Dale Johannesen747fe522009-06-02 03:12:52 +0000479def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000480 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000481 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
482def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000483 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000484 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485} // isTwoAddress
486
Evan Chengb783fa32007-07-19 01:14:50 +0000487def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000488 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000489 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000490def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000491 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000492 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000493def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
494 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000495 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000496} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497
498let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000499// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000500def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000502 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
503 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000504
505// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000506def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000507 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000508 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
509 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000510
511// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000512def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
513 (ins GR64:$src1, i64i8imm:$src2),
514 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000515 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
516 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000517def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
518 (ins GR64:$src1, i64i32imm:$src2),
519 "sub{q}\t{$src2, $dst|$dst, $src2}",
520 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
521 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522} // isTwoAddress
523
Sean Callanan8562bef2009-09-11 19:01:56 +0000524def SUB64i32 : RI<0x2D, RawFrm, (outs), (ins i32imm:$src),
525 "sub{q}\t{$src, %rax|%rax, $src}", []>;
526
Bill Wendlingae034ed2008-12-12 00:56:36 +0000527// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000528def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000529 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000530 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
531 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000532
533// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000534def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000535 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000536 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000537 addr:$dst),
538 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000539def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
540 "sub{q}\t{$src2, $dst|$dst, $src2}",
541 [(store (sub (load addr:$dst), i64immSExt32:$src2),
542 addr:$dst),
543 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544
Evan Cheng259471d2007-10-05 17:59:57 +0000545let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000547def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000548 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000549 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550
Dale Johannesen747fe522009-06-02 03:12:52 +0000551def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000552 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000553 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554
Dale Johannesen747fe522009-06-02 03:12:52 +0000555def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000556 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000557 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
558def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000559 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000560 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561} // isTwoAddress
562
Sean Callanan8562bef2009-09-11 19:01:56 +0000563def SBB64i32 : RI<0x1D, RawFrm, (outs), (ins i32imm:$src),
564 "sbb{q}\t{$src, %rax|%rax, $src}", []>;
565
Evan Chengb783fa32007-07-19 01:14:50 +0000566def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000567 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000568 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000569def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000570 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000571 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000572def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
573 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000574 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000575} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000576} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577
578// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000579let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000580def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000581 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000582let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000583def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000584 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585
586// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000587def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000588 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000589let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000590def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000591 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
592}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593
Evan Cheng55687072007-09-14 21:48:26 +0000594let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000595let isTwoAddress = 1 in {
596let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000597// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000598def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
599 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000601 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
602 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000603
Bill Wendlingf5399032008-12-12 21:15:41 +0000604// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000605def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
606 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000607 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000608 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
609 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610} // isTwoAddress
611
612// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000613
Bill Wendlingf5399032008-12-12 21:15:41 +0000614// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000616 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000617 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000618 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
619 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000620def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
621 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
622 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
623 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
624 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000625
Bill Wendlingf5399032008-12-12 21:15:41 +0000626// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000628 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000629 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000630 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000631 i64immSExt8:$src2)),
632 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000633def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
634 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
635 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
636 [(set GR64:$dst, (mul (load addr:$src1),
637 i64immSExt32:$src2)),
638 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000639} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640
641// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000642let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000643def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000644 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000646def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000647 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000648let mayLoad = 1 in {
649def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
650 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000651def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000652 "idiv{q}\t$src", []>;
653}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000654}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655
656// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000657let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000659def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000660 [(set GR64:$dst, (ineg GR64:$src)),
661 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000662def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000663 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
664 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665
666let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000667def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000668 [(set GR64:$dst, (add GR64:$src, 1)),
669 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000670def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000671 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
672 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673
674let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000675def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000676 [(set GR64:$dst, (add GR64:$src, -1)),
677 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000678def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000679 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
680 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681
682// In 64-bit mode, single byte INC and DEC cannot be encoded.
683let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
684// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000685def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000686 [(set GR16:$dst, (add GR16:$src, 1)),
687 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000689def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000690 [(set GR32:$dst, (add GR32:$src, 1)),
691 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000693def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000694 [(set GR16:$dst, (add GR16:$src, -1)),
695 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000696 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000697def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000698 [(set GR32:$dst, (add GR32:$src, -1)),
699 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 Requires<[In64BitMode]>;
701} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000702
703// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
704// how to unfold them.
705let isTwoAddress = 0, CodeSize = 2 in {
706 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000707 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
708 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000709 OpSize, Requires<[In64BitMode]>;
710 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000711 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
712 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000713 Requires<[In64BitMode]>;
714 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000715 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
716 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000717 OpSize, Requires<[In64BitMode]>;
718 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000719 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
720 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000721 Requires<[In64BitMode]>;
722}
Evan Cheng55687072007-09-14 21:48:26 +0000723} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724
725
Evan Cheng55687072007-09-14 21:48:26 +0000726let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727// Shift instructions
728let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000729let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000730def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000731 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000732 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000733let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000737// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
738// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739} // isTwoAddress
740
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000743 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000745def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
751
752let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000753let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000754def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000757def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
763} // isTwoAddress
764
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000765let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000766def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000768 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000769def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000772def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
775
776let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000777let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000778def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000779 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000780 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000781def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000782 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000783 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000784def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000785 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
787} // isTwoAddress
788
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000789let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000790def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000791 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000792 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000793def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000794 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000795 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000796def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000797 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
799
800// Rotate instructions
801let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000802let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000803def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000804 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000805 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000806def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000807 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000809def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000810 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
812} // isTwoAddress
813
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000814let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000815def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000816 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000817 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000818def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000819 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000820 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000821def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000822 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
824
825let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000826let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000827def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000828 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000829 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000830def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000831 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000833def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000834 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
836} // isTwoAddress
837
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000838let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000839def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000840 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000841 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000842def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000843 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000844 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000845def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000846 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000847 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
848
849// Double shift instructions (generalizations of rotate)
850let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000851let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000852def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000853 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
854 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000855def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000856 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
857 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000858}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859
860let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
861def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000862 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000863 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
864 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
865 (i8 imm:$src3)))]>,
866 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000868 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000869 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
870 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
871 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000872 TB;
873} // isCommutable
874} // isTwoAddress
875
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000876let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000877def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000878 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
879 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
880 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000881def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000882 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
883 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
884 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000885}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000887 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000888 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
889 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
890 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891 TB;
892def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000893 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000894 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
895 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
896 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000898} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899
900//===----------------------------------------------------------------------===//
901// Logical Instructions...
902//
903
Evan Cheng5b51c242009-01-21 19:45:31 +0000904let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000905def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000907def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
909
Evan Cheng55687072007-09-14 21:48:26 +0000910let Defs = [EFLAGS] in {
Sean Callanan251676e2009-09-02 00:55:49 +0000911def AND64i32 : RI<0x25, RawFrm, (outs), (ins i32imm:$src),
912 "and{q}\t{$src, %rax|%rax, $src}", []>;
913
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914let isTwoAddress = 1 in {
915let isCommutable = 1 in
916def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000917 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000919 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
920 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000922 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000923 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000924 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
925 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000926def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000927 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
930 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000931def AND64ri32 : RIi32<0x81, MRM4r,
932 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
933 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000934 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
935 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000936} // isTwoAddress
937
938def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000939 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000941 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
942 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000944 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000945 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000946 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
947 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000948def AND64mi32 : RIi32<0x81, MRM4m,
949 (outs), (ins i64mem:$dst, i64i32imm:$src),
950 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000951 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
952 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953
954let isTwoAddress = 1 in {
955let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000956def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000957 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000958 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
959 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000960def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000962 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
963 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000964def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000966 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
967 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000968def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
969 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000970 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
971 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972} // isTwoAddress
973
Evan Chengb783fa32007-07-19 01:14:50 +0000974def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000975 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000976 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
977 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000978def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000979 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000980 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
981 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000982def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
983 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000984 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
985 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986
Sean Callanan8562bef2009-09-11 19:01:56 +0000987def OR64i32 : RIi32<0x0D, RawFrm, (outs), (ins i32imm:$src),
988 "or{q}\t{$src, %rax|%rax, $src}", []>;
989
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000991let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000992def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000993 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000994 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
995 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000996def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000997 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000998 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
999 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001000def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
1001 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001002 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
1003 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001004def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +00001005 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001006 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001007 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
1008 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001009} // isTwoAddress
1010
Evan Chengb783fa32007-07-19 01:14:50 +00001011def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001013 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
1014 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001015def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001016 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001017 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
1018 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001019def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
1020 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +00001021 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
1022 (implicit EFLAGS)]>;
Sean Callanan794457a2009-09-10 19:52:26 +00001023
1024def XOR64i32 : RIi32<0x35, RawFrm, (outs), (ins i32imm:$src),
1025 "xor{q}\t{$src, %rax|%rax, $src}", []>;
1026
Evan Cheng55687072007-09-14 21:48:26 +00001027} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028
1029//===----------------------------------------------------------------------===//
1030// Comparison Instructions...
1031//
1032
1033// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +00001034let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +00001035def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
1036 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001037let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001038def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001039 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001040 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
1041 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001042def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001043 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001044 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1045 (implicit EFLAGS)]>;
1046def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1047 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001048 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001049 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1050 (implicit EFLAGS)]>;
1051def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1052 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001053 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001054 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1055 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056
Sean Callanan251676e2009-09-02 00:55:49 +00001057
1058def CMP64i32 : RI<0x3D, RawFrm, (outs), (ins i32imm:$src),
1059 "cmp{q}\t{$src, %rax|%rax, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001060def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001061 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001062 [(X86cmp GR64:$src1, GR64:$src2),
1063 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001064def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001065 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001066 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1067 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001068def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001069 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001070 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1071 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001072def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1073 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1074 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1075 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001076def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001078 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001079 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001080def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001081 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001082 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001083 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001084def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1085 (ins i64mem:$src1, i64i32imm:$src2),
1086 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1087 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1088 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001089} // Defs = [EFLAGS]
1090
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001091// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001092// TODO: BTC, BTR, and BTS
1093let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001094def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001095 "bt{q}\t{$src2, $src1|$src1, $src2}",
1096 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001097 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001098
1099// Unlike with the register+register form, the memory+register form of the
1100// bt instruction does not ignore the high bits of the index. From ISel's
1101// perspective, this is pretty bizarre. Disable these instructions for now.
1102//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1103// "bt{q}\t{$src2, $src1|$src1, $src2}",
1104// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1105// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001106
1107def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1108 "bt{q}\t{$src2, $src1|$src1, $src2}",
1109 [(X86bt GR64:$src1, i64immSExt8:$src2),
1110 (implicit EFLAGS)]>, TB;
1111// Note that these instructions don't need FastBTMem because that
1112// only applies when the other operand is in a register. When it's
1113// an immediate, bt is still fast.
1114def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1115 "bt{q}\t{$src2, $src1|$src1, $src2}",
1116 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1117 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001118} // Defs = [EFLAGS]
1119
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001120// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001121let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001122let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001124 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001125 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001127 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001129 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001130 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001132 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001134 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001137 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001139 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001140 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001142 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001144 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001145 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001147 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001148def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001149 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001150 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001152 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001154 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001155 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001156 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001157 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001158def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001159 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001160 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001162 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001163def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001164 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001165 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001167 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001168def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001169 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001170 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001172 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001173def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001174 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001175 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001176 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001177 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001178def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001179 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001180 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001182 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001183def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001184 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001185 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001187 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001188def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001189 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001190 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001191 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001192 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001193def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1194 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1195 "cmovo\t{$src2, $dst|$dst, $src2}",
1196 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1197 X86_COND_O, EFLAGS))]>, TB;
1198def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1199 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1200 "cmovno\t{$src2, $dst|$dst, $src2}",
1201 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1202 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001203} // isCommutable = 1
1204
1205def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1206 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1207 "cmovb\t{$src2, $dst|$dst, $src2}",
1208 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1209 X86_COND_B, EFLAGS))]>, TB;
1210def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1211 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1212 "cmovae\t{$src2, $dst|$dst, $src2}",
1213 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1214 X86_COND_AE, EFLAGS))]>, TB;
1215def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1216 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1217 "cmove\t{$src2, $dst|$dst, $src2}",
1218 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1219 X86_COND_E, EFLAGS))]>, TB;
1220def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1221 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1222 "cmovne\t{$src2, $dst|$dst, $src2}",
1223 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1224 X86_COND_NE, EFLAGS))]>, TB;
1225def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1226 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1227 "cmovbe\t{$src2, $dst|$dst, $src2}",
1228 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1229 X86_COND_BE, EFLAGS))]>, TB;
1230def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1231 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1232 "cmova\t{$src2, $dst|$dst, $src2}",
1233 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1234 X86_COND_A, EFLAGS))]>, TB;
1235def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1236 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1237 "cmovl\t{$src2, $dst|$dst, $src2}",
1238 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1239 X86_COND_L, EFLAGS))]>, TB;
1240def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1241 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1242 "cmovge\t{$src2, $dst|$dst, $src2}",
1243 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1244 X86_COND_GE, EFLAGS))]>, TB;
1245def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1246 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1247 "cmovle\t{$src2, $dst|$dst, $src2}",
1248 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1249 X86_COND_LE, EFLAGS))]>, TB;
1250def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1251 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1252 "cmovg\t{$src2, $dst|$dst, $src2}",
1253 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1254 X86_COND_G, EFLAGS))]>, TB;
1255def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1256 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1257 "cmovs\t{$src2, $dst|$dst, $src2}",
1258 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1259 X86_COND_S, EFLAGS))]>, TB;
1260def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1261 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1262 "cmovns\t{$src2, $dst|$dst, $src2}",
1263 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1264 X86_COND_NS, EFLAGS))]>, TB;
1265def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1266 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1267 "cmovp\t{$src2, $dst|$dst, $src2}",
1268 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1269 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001270def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001271 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001272 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001274 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001275def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1276 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1277 "cmovo\t{$src2, $dst|$dst, $src2}",
1278 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1279 X86_COND_O, EFLAGS))]>, TB;
1280def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1281 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1282 "cmovno\t{$src2, $dst|$dst, $src2}",
1283 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1284 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001285} // isTwoAddress
1286
1287//===----------------------------------------------------------------------===//
1288// Conversion Instructions...
1289//
1290
1291// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001292def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001293 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001294 [(set GR64:$dst,
1295 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001296def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001298 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1299 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001300def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001301 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001302 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001303def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001304 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001306def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001307 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001308 [(set GR64:$dst,
1309 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001310def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001311 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001312 [(set GR64:$dst,
1313 (int_x86_sse2_cvttsd2si64
1314 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001315
1316// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001317def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001318 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001320def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001323
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001324let isTwoAddress = 1 in {
1325def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001326 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001327 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001328 [(set VR128:$dst,
1329 (int_x86_sse2_cvtsi642sd VR128:$src1,
1330 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001331def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001332 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001333 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001334 [(set VR128:$dst,
1335 (int_x86_sse2_cvtsi642sd VR128:$src1,
1336 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337} // isTwoAddress
1338
1339// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001340def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001341 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001343def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001344 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001345 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001346
1347let isTwoAddress = 1 in {
1348 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1349 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1350 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1351 [(set VR128:$dst,
1352 (int_x86_sse_cvtsi642ss VR128:$src1,
1353 GR64:$src2))]>;
1354 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1355 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1356 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1357 [(set VR128:$dst,
1358 (int_x86_sse_cvtsi642ss VR128:$src1,
1359 (loadi64 addr:$src2)))]>;
1360}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001361
1362// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001363def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001364 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001365 [(set GR64:$dst,
1366 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001367def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001368 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001369 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1370 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001371def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001372 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001373 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001374def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001375 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001376 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001377def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001378 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001379 [(set GR64:$dst,
1380 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001381def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001382 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001383 [(set GR64:$dst,
1384 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1385
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001386//===----------------------------------------------------------------------===//
1387// Alias Instructions
1388//===----------------------------------------------------------------------===//
1389
Dan Gohman027cd112007-09-17 14:55:08 +00001390// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1391// equivalent due to implicit zero-extending, and it sometimes has a smaller
1392// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001393// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001394// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001395let AddedComplexity = 1 in
1396def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001397 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001398
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001399
1400// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001401let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001402def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001403 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001404 [(set GR64:$dst, i64immZExt32:$src)]>;
1405
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001406//===----------------------------------------------------------------------===//
1407// Thread Local Storage Instructions
1408//===----------------------------------------------------------------------===//
1409
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001410// All calls clobber the non-callee saved registers. RSP is marked as
1411// a use to prevent stack-pointer assignments that appear immediately
1412// before calls from potentially appearing dead.
1413let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1414 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1415 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1416 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1417 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1418 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001419def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001420 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001421 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001422 ".word\t0x6666; "
1423 "rex64; "
1424 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001425 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001426 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001427
Daniel Dunbar75a07302009-08-11 22:24:40 +00001428let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001429def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1430 "movq\t%gs:$src, $dst",
1431 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1432
Daniel Dunbar75a07302009-08-11 22:24:40 +00001433let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001434def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1435 "movq\t%fs:$src, $dst",
1436 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1437
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001438//===----------------------------------------------------------------------===//
1439// Atomic Instructions
1440//===----------------------------------------------------------------------===//
1441
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001442let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001443def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001444 "lock\n\t"
1445 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001446 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1447}
1448
Dan Gohmana41a1c092008-08-06 15:52:50 +00001449let Constraints = "$val = $dst" in {
1450let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001451def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001452 "lock\n\t"
1453 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001454 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001455 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001456
Evan Chenga1e80602008-04-19 02:05:42 +00001457def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001458 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001459 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001460}
1461
Evan Chengb723fb52009-07-30 08:33:02 +00001462// Optimized codegen when the non-memory output is not used.
1463// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1464def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1465 "lock\n\t"
1466 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1467def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1468 (ins i64mem:$dst, i64i8imm :$src2),
1469 "lock\n\t"
1470 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1471def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1472 (ins i64mem:$dst, i64i32imm :$src2),
1473 "lock\n\t"
1474 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1475def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1476 "lock\n\t"
1477 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1478def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1479 (ins i64mem:$dst, i64i8imm :$src2),
1480 "lock\n\t"
1481 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1482def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1483 (ins i64mem:$dst, i64i32imm:$src2),
1484 "lock\n\t"
1485 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1486def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1487 "lock\n\t"
1488 "inc{q}\t$dst", []>, LOCK;
1489def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1490 "lock\n\t"
1491 "dec{q}\t$dst", []>, LOCK;
1492
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001493// Atomic exchange, and, or, xor
1494let Constraints = "$val = $dst", Defs = [EFLAGS],
1495 usesCustomDAGSchedInserter = 1 in {
1496def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001497 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001498 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001499def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001500 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001501 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001502def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001503 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001504 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001505def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001506 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001507 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001508def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001509 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001510 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001511def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001512 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001513 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001514def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001515 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001516 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001517def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001518 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001519 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001520}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001521
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522//===----------------------------------------------------------------------===//
1523// Non-Instruction Patterns
1524//===----------------------------------------------------------------------===//
1525
Chris Lattner0d2dad62009-07-11 22:50:33 +00001526// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1527// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1528// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001530 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001531def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001532 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001534 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001536 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001537
Chris Lattnerc04cd042009-07-11 23:17:29 +00001538// In static codegen with small code model, we can get the address of a label
1539// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1540// the MOV64ri64i32 should accept these.
1541def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1542 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1543def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1544 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1545def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1546 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1547def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1548 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1549
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001550// In kernel code model, we can get the address of a label
1551// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1552// the MOV64ri32 should accept these.
1553def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1554 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1555def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1556 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1557def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1558 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1559def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1560 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001561
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001562// If we have small model and -static mode, it is safe to store global addresses
1563// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001564// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001565def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1566 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001567 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001568def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1569 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001570 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001571def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1572 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001573 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001574def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1575 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001576 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001577
1578// Calls
1579// Direct PC relative function call for small code model. 32-bit displacement
1580// sign extended to 64-bit.
1581def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001582 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001583def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001584 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1585
1586def : Pat<(X86call (i64 tglobaladdr:$dst)),
1587 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1588def : Pat<(X86call (i64 texternalsym:$dst)),
1589 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001591// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001592def : Pat<(X86tcret GR64:$dst, imm:$off),
1593 (TCRETURNri64 GR64:$dst, imm:$off)>;
1594
1595def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1596 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1597
1598def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1599 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1600
Dan Gohmanec596042007-09-17 14:35:24 +00001601// Comparisons.
1602
1603// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001604def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001605 (TEST64rr GR64:$src1, GR64:$src1)>;
1606
Dan Gohman0a3c5222009-01-07 01:00:24 +00001607// Conditional moves with folded loads with operands swapped and conditions
1608// inverted.
1609def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1610 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1611def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1612 (CMOVB64rm GR64:$src2, addr:$src1)>;
1613def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1614 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1615def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1616 (CMOVE64rm GR64:$src2, addr:$src1)>;
1617def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1618 (CMOVA64rm GR64:$src2, addr:$src1)>;
1619def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1620 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1621def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1622 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1623def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1624 (CMOVL64rm GR64:$src2, addr:$src1)>;
1625def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1626 (CMOVG64rm GR64:$src2, addr:$src1)>;
1627def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1628 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1629def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1630 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1631def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1632 (CMOVP64rm GR64:$src2, addr:$src1)>;
1633def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1634 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1635def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1636 (CMOVS64rm GR64:$src2, addr:$src1)>;
1637def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1638 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1639def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1640 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001641
Duncan Sands082524c2008-01-23 20:39:46 +00001642// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001643def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1644
1645// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001646// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1647// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1648// partial-register updates.
1649def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1650def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1651def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1652// For other extloads, use subregs, since the high contents of the register are
1653// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001654def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001655 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001656 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001657
Dan Gohman9959b052009-08-26 14:59:13 +00001658// anyext. Define these to do an explicit zero-extend to
1659// avoid partial-register updates.
1660def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1661def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1662def : Pat<(i64 (anyext GR32:$src)),
1663 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001664
1665//===----------------------------------------------------------------------===//
1666// Some peepholes
1667//===----------------------------------------------------------------------===//
1668
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001669// Odd encoding trick: -128 fits into an 8-bit immediate field while
1670// +128 doesn't, so in this special case use a sub instead of an add.
1671def : Pat<(add GR64:$src1, 128),
1672 (SUB64ri8 GR64:$src1, -128)>;
1673def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1674 (SUB64mi8 addr:$dst, -128)>;
1675
1676// The same trick applies for 32-bit immediate fields in 64-bit
1677// instructions.
1678def : Pat<(add GR64:$src1, 0x0000000080000000),
1679 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1680def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1681 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1682
Dan Gohman47a419d2008-08-07 02:54:50 +00001683// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001684def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001685 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001686// r & (2^16-1) ==> movz
1687def : Pat<(and GR64:$src, 0xffff),
1688 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1689// r & (2^8-1) ==> movz
1690def : Pat<(and GR64:$src, 0xff),
1691 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001692// r & (2^8-1) ==> movz
1693def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001694 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001695 Requires<[In64BitMode]>;
1696// r & (2^8-1) ==> movz
1697def : Pat<(and GR16:$src1, 0xff),
1698 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1699 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001700
Dan Gohmandd612bb2008-08-20 21:27:32 +00001701// sext_inreg patterns
1702def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001703 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001704def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001705 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001706def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001707 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001708def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001709 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001710 Requires<[In64BitMode]>;
1711def : Pat<(sext_inreg GR16:$src, i8),
1712 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1713 Requires<[In64BitMode]>;
1714
1715// trunc patterns
1716def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001717 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001718def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001719 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001720def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001721 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001722def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001723 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001724 Requires<[In64BitMode]>;
1725def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001726 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1727 Requires<[In64BitMode]>;
1728
1729// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001730// For now, be conservative on x86-64 and use an h-register extract only if the
1731// value is immediately zero-extended or stored, which are somewhat common
1732// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1733// from being allocated in the same instruction as the h register, as there's
1734// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001735
1736// h-register extract and zero-extend.
1737def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1738 (SUBREG_TO_REG
1739 (i64 0),
1740 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001741 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001742 x86_subreg_8bit_hi)),
1743 x86_subreg_32bit)>;
1744def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1745 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001746 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001747 x86_subreg_8bit_hi))>,
1748 Requires<[In64BitMode]>;
1749def : Pat<(srl_su GR16:$src, (i8 8)),
1750 (EXTRACT_SUBREG
1751 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001752 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001753 x86_subreg_8bit_hi)),
1754 x86_subreg_16bit)>,
1755 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001756def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1757 (MOVZX32_NOREXrr8
1758 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1759 x86_subreg_8bit_hi))>,
1760 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001761def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1762 (MOVZX32_NOREXrr8
1763 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1764 x86_subreg_8bit_hi))>,
1765 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001766def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1767 (SUBREG_TO_REG
1768 (i64 0),
1769 (MOVZX32_NOREXrr8
1770 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1771 x86_subreg_8bit_hi)),
1772 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001773def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1774 (SUBREG_TO_REG
1775 (i64 0),
1776 (MOVZX32_NOREXrr8
1777 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1778 x86_subreg_8bit_hi)),
1779 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001780
1781// h-register extract and store.
1782def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1783 (MOV8mr_NOREX
1784 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001785 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001786 x86_subreg_8bit_hi))>;
1787def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1788 (MOV8mr_NOREX
1789 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001790 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001791 x86_subreg_8bit_hi))>,
1792 Requires<[In64BitMode]>;
1793def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1794 (MOV8mr_NOREX
1795 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001796 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001797 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001798 Requires<[In64BitMode]>;
1799
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001800// (shl x, 1) ==> (add x, x)
1801def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1802
Evan Cheng76a64c72008-08-30 02:03:58 +00001803// (shl x (and y, 63)) ==> (shl x, y)
1804def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1805 (SHL64rCL GR64:$src1)>;
1806def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1807 (SHL64mCL addr:$dst)>;
1808
1809def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1810 (SHR64rCL GR64:$src1)>;
1811def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1812 (SHR64mCL addr:$dst)>;
1813
1814def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1815 (SAR64rCL GR64:$src1)>;
1816def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1817 (SAR64mCL addr:$dst)>;
1818
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001819// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1820def : Pat<(or (srl GR64:$src1, CL:$amt),
1821 (shl GR64:$src2, (sub 64, CL:$amt))),
1822 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1823
1824def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1825 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1826 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1827
Dan Gohman921581d2008-10-17 01:23:35 +00001828def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1829 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1830 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1831
1832def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1833 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1834 addr:$dst),
1835 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1836
1837def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1838 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1839
1840def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1841 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1842 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1843
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001844// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1845def : Pat<(or (shl GR64:$src1, CL:$amt),
1846 (srl GR64:$src2, (sub 64, CL:$amt))),
1847 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1848
1849def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1850 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1851 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1852
Dan Gohman921581d2008-10-17 01:23:35 +00001853def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1854 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1855 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1856
1857def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1858 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1859 addr:$dst),
1860 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1861
1862def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1863 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1864
1865def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1866 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1867 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1868
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001869// X86 specific add which produces a flag.
1870def : Pat<(addc GR64:$src1, GR64:$src2),
1871 (ADD64rr GR64:$src1, GR64:$src2)>;
1872def : Pat<(addc GR64:$src1, (load addr:$src2)),
1873 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001874def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1875 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001876def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1877 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001878
1879def : Pat<(subc GR64:$src1, GR64:$src2),
1880 (SUB64rr GR64:$src1, GR64:$src2)>;
1881def : Pat<(subc GR64:$src1, (load addr:$src2)),
1882 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001883def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1884 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001885def : Pat<(subc GR64:$src1, imm:$src2),
1886 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001887
Bill Wendlingf5399032008-12-12 21:15:41 +00001888//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001889// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001890//===----------------------------------------------------------------------===//
1891
Dan Gohman99a12192009-03-04 19:44:21 +00001892// Register-Register Addition with EFLAGS result
1893def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001894 (implicit EFLAGS)),
1895 (ADD64rr GR64:$src1, GR64:$src2)>;
1896
Dan Gohman99a12192009-03-04 19:44:21 +00001897// Register-Integer Addition with EFLAGS result
1898def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001899 (implicit EFLAGS)),
1900 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001901def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001902 (implicit EFLAGS)),
1903 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001904
Dan Gohman99a12192009-03-04 19:44:21 +00001905// Register-Memory Addition with EFLAGS result
1906def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001907 (implicit EFLAGS)),
1908 (ADD64rm GR64:$src1, addr:$src2)>;
1909
Dan Gohman99a12192009-03-04 19:44:21 +00001910// Memory-Register Addition with EFLAGS result
1911def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001912 addr:$dst),
1913 (implicit EFLAGS)),
1914 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001915def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001916 addr:$dst),
1917 (implicit EFLAGS)),
1918 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001919def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001920 addr:$dst),
1921 (implicit EFLAGS)),
1922 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001923
Dan Gohman99a12192009-03-04 19:44:21 +00001924// Register-Register Subtraction with EFLAGS result
1925def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001926 (implicit EFLAGS)),
1927 (SUB64rr GR64:$src1, GR64:$src2)>;
1928
Dan Gohman99a12192009-03-04 19:44:21 +00001929// Register-Memory Subtraction with EFLAGS result
1930def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001931 (implicit EFLAGS)),
1932 (SUB64rm GR64:$src1, addr:$src2)>;
1933
Dan Gohman99a12192009-03-04 19:44:21 +00001934// Register-Integer Subtraction with EFLAGS result
1935def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001936 (implicit EFLAGS)),
1937 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001938def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001939 (implicit EFLAGS)),
1940 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001941
Dan Gohman99a12192009-03-04 19:44:21 +00001942// Memory-Register Subtraction with EFLAGS result
1943def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001944 addr:$dst),
1945 (implicit EFLAGS)),
1946 (SUB64mr addr:$dst, GR64:$src2)>;
1947
Dan Gohman99a12192009-03-04 19:44:21 +00001948// Memory-Integer Subtraction with EFLAGS result
1949def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001950 addr:$dst),
1951 (implicit EFLAGS)),
1952 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001953def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001954 addr:$dst),
1955 (implicit EFLAGS)),
1956 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001957
Dan Gohman99a12192009-03-04 19:44:21 +00001958// Register-Register Signed Integer Multiplication with EFLAGS result
1959def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001960 (implicit EFLAGS)),
1961 (IMUL64rr GR64:$src1, GR64:$src2)>;
1962
Dan Gohman99a12192009-03-04 19:44:21 +00001963// Register-Memory Signed Integer Multiplication with EFLAGS result
1964def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001965 (implicit EFLAGS)),
1966 (IMUL64rm GR64:$src1, addr:$src2)>;
1967
Dan Gohman99a12192009-03-04 19:44:21 +00001968// Register-Integer Signed Integer Multiplication with EFLAGS result
1969def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001970 (implicit EFLAGS)),
1971 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001972def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001973 (implicit EFLAGS)),
1974 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001975
Dan Gohman99a12192009-03-04 19:44:21 +00001976// Memory-Integer Signed Integer Multiplication with EFLAGS result
1977def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001978 (implicit EFLAGS)),
1979 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001980def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001981 (implicit EFLAGS)),
1982 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001983
Dan Gohman99a12192009-03-04 19:44:21 +00001984// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001985def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1986 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1987def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1988 (implicit EFLAGS)),
1989 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1990def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1991 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1992def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1993 (implicit EFLAGS)),
1994 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1995
1996def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1997 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1998def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1999 (implicit EFLAGS)),
2000 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2001def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
2002 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
2003def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
2004 (implicit EFLAGS)),
2005 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
2006
Dan Gohman99a12192009-03-04 19:44:21 +00002007def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
2008 (INC64r GR64:$src)>;
2009def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
2010 (implicit EFLAGS)),
2011 (INC64m addr:$dst)>;
2012def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
2013 (DEC64r GR64:$src)>;
2014def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
2015 (implicit EFLAGS)),
2016 (DEC64m addr:$dst)>;
2017
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002018//===----------------------------------------------------------------------===//
2019// X86-64 SSE Instructions
2020//===----------------------------------------------------------------------===//
2021
2022// Move instructions...
2023
Evan Chengb783fa32007-07-19 01:14:50 +00002024def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002025 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002026 [(set VR128:$dst,
2027 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002028def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002029 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002030 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
2031 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002032
Evan Chengb783fa32007-07-19 01:14:50 +00002033def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002034 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002035 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002036def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002037 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002038 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
2039
Evan Chengb783fa32007-07-19 01:14:50 +00002040def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002041 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002042 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002043def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002044 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002045 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002046
2047//===----------------------------------------------------------------------===//
2048// X86-64 SSE4.1 Instructions
2049//===----------------------------------------------------------------------===//
2050
Nate Begeman4294c1f2008-02-12 22:51:28 +00002051/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2052multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002053 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002054 (ins VR128:$src1, i32i8imm:$src2),
2055 !strconcat(OpcodeStr,
2056 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2057 [(set GR64:$dst,
2058 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002059 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002060 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2061 !strconcat(OpcodeStr,
2062 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2063 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2064 addr:$dst)]>, OpSize, REX_W;
2065}
2066
2067defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2068
2069let isTwoAddress = 1 in {
2070 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002071 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002072 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2073 !strconcat(OpcodeStr,
2074 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2075 [(set VR128:$dst,
2076 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2077 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002078 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002079 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2080 !strconcat(OpcodeStr,
2081 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2082 [(set VR128:$dst,
2083 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2084 imm:$src3)))]>, OpSize, REX_W;
2085 }
2086}
2087
2088defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;
Dan Gohmane84197b2009-09-03 17:18:51 +00002089
2090// -disable-16bit support.
2091def : Pat<(truncstorei16 (i64 imm:$src), addr:$dst),
2092 (MOV16mi addr:$dst, imm:$src)>;
2093def : Pat<(truncstorei16 GR64:$src, addr:$dst),
2094 (MOV16mr addr:$dst, (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
2095def : Pat<(i64 (sextloadi16 addr:$dst)),
2096 (MOVSX64rm16 addr:$dst)>;
2097def : Pat<(i64 (zextloadi16 addr:$dst)),
2098 (MOVZX64rm16 addr:$dst)>;
2099def : Pat<(i64 (extloadi16 addr:$dst)),
2100 (MOVZX64rm16 addr:$dst)>;