blob: 0155e0c5719af6a9df2813bf76c4084766056b25 [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]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142 }
143
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000144 // FIXME: We need to teach codegen about single list of call-clobbered registers.
145let isCall = 1 in
146 // All calls clobber the non-callee saved registers. RSP is marked as
147 // a use to prevent stack-pointer assignments that appear immediately
148 // before calls from potentially appearing dead. Uses for argument
149 // registers are added manually.
150 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
151 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
152 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
153 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
154 Uses = [RSP] in {
155 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000156 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
157 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000158 Requires<[IsWin64]>;
159 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
160 "call\t{*}$dst",
161 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
162 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
163 "call\t{*}$dst",
164 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
165 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000166
167
168let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000169def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
170 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000171 "#TC_RETURN $dst $offset",
172 []>;
173
174let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000175def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
176 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000177 "#TC_RETURN $dst $offset",
178 []>;
179
180
181let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000182 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
183 "jmp{q}\t{*}$dst # TAILCALL",
184 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000185
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000187let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000188 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000190 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191 [(brind (loadi64 addr:$dst))]>;
192}
193
194//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000195// EH Pseudo Instructions
196//
197let isTerminator = 1, isReturn = 1, isBarrier = 1,
198 hasCtrlDep = 1 in {
199def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
200 "ret\t#eh_return, addr: $addr",
201 [(X86ehret GR64:$addr)]>;
202
203}
204
205//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206// Miscellaneous Instructions...
207//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000208let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000210 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000211let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
212let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000214 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000215let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000217 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
218}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
Bill Wendling4c2638c2009-06-15 19:39:04 +0000220let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
221def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000222 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000223def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000224 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000225def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000226 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000227}
228
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000229let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000230def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000231let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000232def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000233
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000235 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000236 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
238
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000239let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000240def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000241 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 [(set GR64:$dst, lea64addr:$src)]>;
243
244let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248
Evan Cheng48679f42007-12-14 02:13:44 +0000249// Bit scan instructions.
250let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000251def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000252 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000253 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000254def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000255 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000256 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
257 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000258
Evan Cheng4e33de92007-12-14 18:49:43 +0000259def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000260 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000261 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000262def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000263 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000264 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
265 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000266} // Defs = [EFLAGS]
267
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000269let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000270def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000271 [(X86rep_movs i64)]>, REP;
272let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000273def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000274 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000276// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000277def SYSEXIT64 : RI<0x35, RawFrm,
278 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000279
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280//===----------------------------------------------------------------------===//
281// Move Instructions...
282//
283
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000284let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000285def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000286 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287
Evan Chengd2b9d302008-06-25 01:16:38 +0000288let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000289def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000290 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000292def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000293 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000295}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296
Dan Gohman5574cc72008-12-03 18:15:48 +0000297let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set GR64:$dst, (load addr:$src))]>;
301
Evan Chengb783fa32007-07-19 01:14:50 +0000302def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000303 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000305def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000306 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 [(store i64immSExt32:$src, addr:$dst)]>;
308
309// Sign/Zero extenders
310
Dan Gohmanedde1992009-04-13 15:13:28 +0000311// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
312// operand, which makes it a rare instruction with an 8-bit register
313// operand that can never access an h register. If support for h registers
314// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000315def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000316 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000318def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000319 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000321def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000322 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000324def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000325 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000327def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000328 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000330def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000331 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
333
Dan Gohman9203ab42008-07-30 18:09:17 +0000334// Use movzbl instead of movzbq when the destination is a register; it's
335// equivalent due to implicit zero-extending, and it has a smaller encoding.
336def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
337 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
338 [(set GR64:$dst, (zext GR8:$src))]>, TB;
339def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
340 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
341 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
342// Use movzwl instead of movzwq when the destination is a register; it's
343// equivalent due to implicit zero-extending, and it has a smaller encoding.
344def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
345 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
346 [(set GR64:$dst, (zext GR16:$src))]>, TB;
347def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
348 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
349 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350
Dan Gohman47a419d2008-08-07 02:54:50 +0000351// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000352// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
353// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
354// zero-extension, however this isn't possible when the 32-bit value is
355// defined by a truncate or is copied from something where the high bits aren't
356// necessarily all zero. In such cases, we fall back to these explicit zext
357// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000358def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
359 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
360 [(set GR64:$dst, (zext GR32:$src))]>;
361def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
362 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
363 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
364
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000365// Any instruction that defines a 32-bit result leaves the high half of the
366// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
367// be copying from a truncate, but any other 32-bit operation will zero-extend
368// up to 64 bits.
369def def32 : PatLeaf<(i32 GR32:$src), [{
370 return N->getOpcode() != ISD::TRUNCATE &&
371 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
372 N->getOpcode() != ISD::CopyFromReg;
373}]>;
374
375// In the case of a 32-bit def that is known to implicitly zero-extend,
376// we can use a SUBREG_TO_REG.
377def : Pat<(i64 (zext def32:$src)),
378 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
379
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000380let neverHasSideEffects = 1 in {
381 let Defs = [RAX], Uses = [EAX] in
382 def CDQE : RI<0x98, RawFrm, (outs), (ins),
383 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000385 let Defs = [RAX,RDX], Uses = [RAX] in
386 def CQO : RI<0x99, RawFrm, (outs), (ins),
387 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
388}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
390//===----------------------------------------------------------------------===//
391// Arithmetic Instructions...
392//
393
Evan Cheng55687072007-09-14 21:48:26 +0000394let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395let isTwoAddress = 1 in {
396let isConvertibleToThreeAddress = 1 in {
397let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000398// Register-Register Addition
399def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
400 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000401 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000402 (implicit EFLAGS)]>;
403
404// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000405def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
406 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000407 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
408 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000409def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
410 "add{q}\t{$src2, $dst|$dst, $src2}",
411 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
412 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413} // isConvertibleToThreeAddress
414
Bill Wendlingae034ed2008-12-12 00:56:36 +0000415// Register-Memory Addition
416def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
417 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000418 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000419 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420} // isTwoAddress
421
Bill Wendlingae034ed2008-12-12 00:56:36 +0000422// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000423def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000425 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
426 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000427def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000428 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000429 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
430 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000431def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
432 "add{q}\t{$src2, $dst|$dst, $src2}",
433 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
434 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435
Evan Cheng259471d2007-10-05 17:59:57 +0000436let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437let isTwoAddress = 1 in {
438let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000439def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000440 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000441 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442
Dale Johannesen747fe522009-06-02 03:12:52 +0000443def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000444 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000445 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446
Dale Johannesen747fe522009-06-02 03:12:52 +0000447def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000448 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000449 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
450def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000451 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000452 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453} // isTwoAddress
454
Evan Chengb783fa32007-07-19 01:14:50 +0000455def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000457 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000458def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000460 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000461def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
462 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000463 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000464} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465
466let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000467// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000468def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000469 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000470 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
471 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000472
473// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000474def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000475 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000476 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
477 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000478
479// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000480def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
481 (ins GR64:$src1, i64i8imm:$src2),
482 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000483 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
484 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000485def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
486 (ins GR64:$src1, i64i32imm:$src2),
487 "sub{q}\t{$src2, $dst|$dst, $src2}",
488 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
489 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490} // isTwoAddress
491
Bill Wendlingae034ed2008-12-12 00:56:36 +0000492// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000493def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000494 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000495 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
496 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000497
498// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000499def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000501 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000502 addr:$dst),
503 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000504def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
505 "sub{q}\t{$src2, $dst|$dst, $src2}",
506 [(store (sub (load addr:$dst), i64immSExt32:$src2),
507 addr:$dst),
508 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509
Evan Cheng259471d2007-10-05 17:59:57 +0000510let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000512def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000513 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000514 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515
Dale Johannesen747fe522009-06-02 03:12:52 +0000516def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000517 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000518 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
Dale Johannesen747fe522009-06-02 03:12:52 +0000520def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000521 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000522 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
523def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000524 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000525 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526} // isTwoAddress
527
Evan Chengb783fa32007-07-19 01:14:50 +0000528def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000529 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000530 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000531def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000532 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000533 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000534def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
535 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000536 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000537} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000538} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
540// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000541let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000542def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000543 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000544let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000545def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000546 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
548// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000549def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000550 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000551let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000552def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000553 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
554}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555
Evan Cheng55687072007-09-14 21:48:26 +0000556let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557let isTwoAddress = 1 in {
558let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000559// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000560def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
561 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000562 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000563 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
564 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565
Bill Wendlingf5399032008-12-12 21:15:41 +0000566// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000567def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
568 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000569 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000570 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
571 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572} // isTwoAddress
573
574// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000575
Bill Wendlingf5399032008-12-12 21:15:41 +0000576// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000578 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000579 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000580 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
581 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000582def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
583 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
584 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
585 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
586 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000587
Bill Wendlingf5399032008-12-12 21:15:41 +0000588// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000590 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000591 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000592 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000593 i64immSExt8:$src2)),
594 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000595def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
596 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
597 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
598 [(set GR64:$dst, (mul (load addr:$src1),
599 i64immSExt32:$src2)),
600 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000601} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602
603// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000604let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000605def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000606 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000608def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000609 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000610let mayLoad = 1 in {
611def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
612 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000613def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000614 "idiv{q}\t$src", []>;
615}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000616}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000619let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000621def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000622 [(set GR64:$dst, (ineg GR64:$src)),
623 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000624def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000625 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
626 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627
628let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000629def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000630 [(set GR64:$dst, (add GR64:$src, 1)),
631 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000632def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000633 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
634 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635
636let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000637def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000638 [(set GR64:$dst, (add GR64:$src, -1)),
639 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000640def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000641 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
642 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643
644// In 64-bit mode, single byte INC and DEC cannot be encoded.
645let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
646// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000647def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000648 [(set GR16:$dst, (add GR16:$src, 1)),
649 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000650 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000651def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000652 [(set GR32:$dst, (add GR32:$src, 1)),
653 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000655def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000656 [(set GR16:$dst, (add GR16:$src, -1)),
657 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000659def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000660 [(set GR32:$dst, (add GR32:$src, -1)),
661 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662 Requires<[In64BitMode]>;
663} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000664
665// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
666// how to unfold them.
667let isTwoAddress = 0, CodeSize = 2 in {
668 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000669 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
670 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000671 OpSize, Requires<[In64BitMode]>;
672 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000673 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
674 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000675 Requires<[In64BitMode]>;
676 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000677 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
678 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000679 OpSize, Requires<[In64BitMode]>;
680 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000681 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
682 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000683 Requires<[In64BitMode]>;
684}
Evan Cheng55687072007-09-14 21:48:26 +0000685} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686
687
Evan Cheng55687072007-09-14 21:48:26 +0000688let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689// Shift instructions
690let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000691let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000692def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000693 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000694 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000695let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000699// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
700// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701} // isTwoAddress
702
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000703let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000704def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000705 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000706 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000707def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000710def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
713
714let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000715let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000716def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000717 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000718 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000719def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000720 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000722def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
725} // isTwoAddress
726
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000727let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000728def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000730 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000731def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000732 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000733 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
737
738let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000739let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000742 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
749} // isTwoAddress
750
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000751let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000752def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000754 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000755def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000758def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
761
762// Rotate instructions
763let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000764let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000765def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000766 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000767 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000768def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000769 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000770 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000771def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000772 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
774} // isTwoAddress
775
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000776let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000777def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000778 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000779 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000780def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000781 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000783def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
786
787let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000788let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000789def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000791 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000792def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000793 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000795def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
798} // isTwoAddress
799
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000800let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000801def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000804def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000807def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
810
811// Double shift instructions (generalizations of rotate)
812let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000813let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000814def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000815 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
816 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000817def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000818 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
819 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000820}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821
822let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
823def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000824 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000825 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
826 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
827 (i8 imm:$src3)))]>,
828 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000830 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000831 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
832 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
833 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834 TB;
835} // isCommutable
836} // isTwoAddress
837
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000838let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000839def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000840 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
841 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
842 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000843def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000844 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
845 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
846 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000847}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000849 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000850 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
851 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
852 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853 TB;
854def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000856 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
857 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
858 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000860} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861
862//===----------------------------------------------------------------------===//
863// Logical Instructions...
864//
865
Evan Cheng5b51c242009-01-21 19:45:31 +0000866let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000867def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000869def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
871
Evan Cheng55687072007-09-14 21:48:26 +0000872let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873let isTwoAddress = 1 in {
874let isCommutable = 1 in
875def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000876 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000877 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
879 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000881 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000882 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000883 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
884 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000886 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000887 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000888 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
889 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000890def AND64ri32 : RIi32<0x81, MRM4r,
891 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
892 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000893 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
894 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895} // isTwoAddress
896
897def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000898 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000899 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000900 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
901 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000903 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000904 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000905 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
906 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000907def AND64mi32 : RIi32<0x81, MRM4m,
908 (outs), (ins i64mem:$dst, i64i32imm:$src),
909 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000910 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
911 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912
913let isTwoAddress = 1 in {
914let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000915def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000916 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000917 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
918 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000919def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000920 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000921 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
922 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000923def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000924 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000925 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
926 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000927def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
928 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
930 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000931} // isTwoAddress
932
Evan Chengb783fa32007-07-19 01:14:50 +0000933def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000935 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
936 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000937def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000939 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
940 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000941def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
942 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
944 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945
946let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000947let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000948def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000950 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
951 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000952def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000953 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000954 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
955 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000956def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
957 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000958 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
959 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000961 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000963 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
964 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965} // isTwoAddress
966
Evan Chengb783fa32007-07-19 01:14:50 +0000967def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000969 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
970 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000971def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000972 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000973 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
974 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000975def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
976 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000977 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
978 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000979} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980
981//===----------------------------------------------------------------------===//
982// Comparison Instructions...
983//
984
985// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000986let Defs = [EFLAGS] in {
Sean Callanan3e4b1a32009-09-01 18:14:18 +0000987def TEST64i32 : RI<0xa9, RawFrm, (outs), (ins i32imm:$src),
988 "test{q}\t{$src, %rax|%rax, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000989let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000990def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000991 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000992 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
993 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000994def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000995 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000996 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
997 (implicit EFLAGS)]>;
998def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
999 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001000 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001001 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1002 (implicit EFLAGS)]>;
1003def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1004 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001005 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001006 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1007 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001008
Evan Chengb783fa32007-07-19 01:14:50 +00001009def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001010 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001011 [(X86cmp GR64:$src1, GR64:$src2),
1012 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001013def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001014 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001015 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1016 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001017def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001018 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001019 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1020 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001021def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1022 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1023 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1024 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001025def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001026 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001027 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001028 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001029def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001030 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001031 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001032 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001033def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1034 (ins i64mem:$src1, i64i32imm:$src2),
1035 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1036 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1037 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001038} // Defs = [EFLAGS]
1039
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001040// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001041// TODO: BTC, BTR, and BTS
1042let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001043def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001044 "bt{q}\t{$src2, $src1|$src1, $src2}",
1045 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001046 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001047
1048// Unlike with the register+register form, the memory+register form of the
1049// bt instruction does not ignore the high bits of the index. From ISel's
1050// perspective, this is pretty bizarre. Disable these instructions for now.
1051//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1052// "bt{q}\t{$src2, $src1|$src1, $src2}",
1053// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1054// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001055
1056def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1057 "bt{q}\t{$src2, $src1|$src1, $src2}",
1058 [(X86bt GR64:$src1, i64immSExt8:$src2),
1059 (implicit EFLAGS)]>, TB;
1060// Note that these instructions don't need FastBTMem because that
1061// only applies when the other operand is in a register. When it's
1062// an immediate, bt is still fast.
1063def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1064 "bt{q}\t{$src2, $src1|$src1, $src2}",
1065 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1066 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001067} // Defs = [EFLAGS]
1068
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001070let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001071let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001073 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001074 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001076 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001077def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001078 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001079 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001081 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001083 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001084 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001086 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001088 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001089 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001091 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001093 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001094 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001096 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001097def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001098 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001099 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001101 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001103 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001104 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001106 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001107def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001108 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001109 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001111 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001112def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001113 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001114 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001116 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001117def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001118 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001119 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001120 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001121 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001123 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001124 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001126 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001127def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001128 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001129 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001131 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001132def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001133 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001134 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001135 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001136 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001137def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001138 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001139 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001141 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001142def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1143 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1144 "cmovo\t{$src2, $dst|$dst, $src2}",
1145 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1146 X86_COND_O, EFLAGS))]>, TB;
1147def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1148 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1149 "cmovno\t{$src2, $dst|$dst, $src2}",
1150 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1151 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001152} // isCommutable = 1
1153
1154def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1155 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1156 "cmovb\t{$src2, $dst|$dst, $src2}",
1157 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1158 X86_COND_B, EFLAGS))]>, TB;
1159def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1160 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1161 "cmovae\t{$src2, $dst|$dst, $src2}",
1162 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1163 X86_COND_AE, EFLAGS))]>, TB;
1164def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1165 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1166 "cmove\t{$src2, $dst|$dst, $src2}",
1167 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1168 X86_COND_E, EFLAGS))]>, TB;
1169def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1170 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1171 "cmovne\t{$src2, $dst|$dst, $src2}",
1172 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1173 X86_COND_NE, EFLAGS))]>, TB;
1174def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1175 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1176 "cmovbe\t{$src2, $dst|$dst, $src2}",
1177 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1178 X86_COND_BE, EFLAGS))]>, TB;
1179def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1180 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1181 "cmova\t{$src2, $dst|$dst, $src2}",
1182 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1183 X86_COND_A, EFLAGS))]>, TB;
1184def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1185 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1186 "cmovl\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1188 X86_COND_L, EFLAGS))]>, TB;
1189def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1190 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1191 "cmovge\t{$src2, $dst|$dst, $src2}",
1192 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1193 X86_COND_GE, EFLAGS))]>, TB;
1194def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1195 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1196 "cmovle\t{$src2, $dst|$dst, $src2}",
1197 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1198 X86_COND_LE, EFLAGS))]>, TB;
1199def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1200 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1201 "cmovg\t{$src2, $dst|$dst, $src2}",
1202 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1203 X86_COND_G, EFLAGS))]>, TB;
1204def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1205 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1206 "cmovs\t{$src2, $dst|$dst, $src2}",
1207 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1208 X86_COND_S, EFLAGS))]>, TB;
1209def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1210 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1211 "cmovns\t{$src2, $dst|$dst, $src2}",
1212 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1213 X86_COND_NS, EFLAGS))]>, TB;
1214def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1215 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1216 "cmovp\t{$src2, $dst|$dst, $src2}",
1217 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1218 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001219def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001220 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001221 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001223 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001224def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1225 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1226 "cmovo\t{$src2, $dst|$dst, $src2}",
1227 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1228 X86_COND_O, EFLAGS))]>, TB;
1229def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1230 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1231 "cmovno\t{$src2, $dst|$dst, $src2}",
1232 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1233 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234} // isTwoAddress
1235
1236//===----------------------------------------------------------------------===//
1237// Conversion Instructions...
1238//
1239
1240// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001241def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001242 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001243 [(set GR64:$dst,
1244 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001245def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001246 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001247 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1248 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001249def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001250 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001251 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001252def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001253 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001254 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001255def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001256 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001257 [(set GR64:$dst,
1258 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001259def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001261 [(set GR64:$dst,
1262 (int_x86_sse2_cvttsd2si64
1263 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001264
1265// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001266def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001267 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001268 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001269def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001270 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001271 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001272
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273let isTwoAddress = 1 in {
1274def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001275 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001276 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001277 [(set VR128:$dst,
1278 (int_x86_sse2_cvtsi642sd VR128:$src1,
1279 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001280def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001281 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001282 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001283 [(set VR128:$dst,
1284 (int_x86_sse2_cvtsi642sd VR128:$src1,
1285 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286} // isTwoAddress
1287
1288// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001289def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001290 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001291 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001292def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001293 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001294 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001295
1296let isTwoAddress = 1 in {
1297 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1298 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1299 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1300 [(set VR128:$dst,
1301 (int_x86_sse_cvtsi642ss VR128:$src1,
1302 GR64:$src2))]>;
1303 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1304 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1305 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1306 [(set VR128:$dst,
1307 (int_x86_sse_cvtsi642ss VR128:$src1,
1308 (loadi64 addr:$src2)))]>;
1309}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310
1311// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001312def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001313 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001314 [(set GR64:$dst,
1315 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001316def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001317 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001318 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1319 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001320def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001323def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001324 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001326def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001327 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001328 [(set GR64:$dst,
1329 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001330def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001331 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001332 [(set GR64:$dst,
1333 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1334
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001335//===----------------------------------------------------------------------===//
1336// Alias Instructions
1337//===----------------------------------------------------------------------===//
1338
Dan Gohman027cd112007-09-17 14:55:08 +00001339// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1340// equivalent due to implicit zero-extending, and it sometimes has a smaller
1341// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001342// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001343// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001344let AddedComplexity = 1 in
1345def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001346 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001347
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001348
1349// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001350let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001351def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001352 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001353 [(set GR64:$dst, i64immZExt32:$src)]>;
1354
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001355//===----------------------------------------------------------------------===//
1356// Thread Local Storage Instructions
1357//===----------------------------------------------------------------------===//
1358
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001359// All calls clobber the non-callee saved registers. RSP is marked as
1360// a use to prevent stack-pointer assignments that appear immediately
1361// before calls from potentially appearing dead.
1362let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1363 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1364 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1365 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1366 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1367 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001368def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001369 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001370 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001371 ".word\t0x6666; "
1372 "rex64; "
1373 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001374 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001375 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001376
Daniel Dunbar75a07302009-08-11 22:24:40 +00001377let AddedComplexity = 5, isCodeGenOnly = 1 in
sampo9cc09a32009-01-26 01:24:32 +00001378def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1379 "movq\t%gs:$src, $dst",
1380 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1381
Daniel Dunbar75a07302009-08-11 22:24:40 +00001382let AddedComplexity = 5, isCodeGenOnly = 1 in
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001383def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1384 "movq\t%fs:$src, $dst",
1385 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1386
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001387//===----------------------------------------------------------------------===//
1388// Atomic Instructions
1389//===----------------------------------------------------------------------===//
1390
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001391let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001392def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001393 "lock\n\t"
1394 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001395 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1396}
1397
Dan Gohmana41a1c092008-08-06 15:52:50 +00001398let Constraints = "$val = $dst" in {
1399let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001400def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001401 "lock\n\t"
1402 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001403 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001404 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001405
Evan Chenga1e80602008-04-19 02:05:42 +00001406def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001407 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001408 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001409}
1410
Evan Chengb723fb52009-07-30 08:33:02 +00001411// Optimized codegen when the non-memory output is not used.
1412// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1413def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1414 "lock\n\t"
1415 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1416def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1417 (ins i64mem:$dst, i64i8imm :$src2),
1418 "lock\n\t"
1419 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1420def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1421 (ins i64mem:$dst, i64i32imm :$src2),
1422 "lock\n\t"
1423 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1424def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1425 "lock\n\t"
1426 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1427def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1428 (ins i64mem:$dst, i64i8imm :$src2),
1429 "lock\n\t"
1430 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1431def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1432 (ins i64mem:$dst, i64i32imm:$src2),
1433 "lock\n\t"
1434 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1435def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1436 "lock\n\t"
1437 "inc{q}\t$dst", []>, LOCK;
1438def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1439 "lock\n\t"
1440 "dec{q}\t$dst", []>, LOCK;
1441
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001442// Atomic exchange, and, or, xor
1443let Constraints = "$val = $dst", Defs = [EFLAGS],
1444 usesCustomDAGSchedInserter = 1 in {
1445def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001446 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001447 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001448def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001449 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001450 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001451def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001452 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001453 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001454def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001455 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001456 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001457def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001458 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001459 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001460def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001461 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001462 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001463def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001464 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001465 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001466def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001467 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001468 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001469}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001470
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001471//===----------------------------------------------------------------------===//
1472// Non-Instruction Patterns
1473//===----------------------------------------------------------------------===//
1474
Chris Lattner0d2dad62009-07-11 22:50:33 +00001475// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1476// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1477// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001478def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001479 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001480def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001481 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001483 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001485 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486
Chris Lattnerc04cd042009-07-11 23:17:29 +00001487// In static codegen with small code model, we can get the address of a label
1488// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1489// the MOV64ri64i32 should accept these.
1490def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1491 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1492def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1493 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1494def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1495 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1496def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1497 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1498
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001499// In kernel code model, we can get the address of a label
1500// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1501// the MOV64ri32 should accept these.
1502def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1503 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1504def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1505 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1506def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1507 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1508def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1509 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001510
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001511// If we have small model and -static mode, it is safe to store global addresses
1512// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001513// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001514def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1515 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001516 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001517def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1518 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001519 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1521 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001522 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001523def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1524 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001525 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001526
1527// Calls
1528// Direct PC relative function call for small code model. 32-bit displacement
1529// sign extended to 64-bit.
1530def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001531 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001532def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001533 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1534
1535def : Pat<(X86call (i64 tglobaladdr:$dst)),
1536 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1537def : Pat<(X86call (i64 texternalsym:$dst)),
1538 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001539
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001540// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001541def : Pat<(X86tcret GR64:$dst, imm:$off),
1542 (TCRETURNri64 GR64:$dst, imm:$off)>;
1543
1544def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1545 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1546
1547def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1548 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1549
Dan Gohmanec596042007-09-17 14:35:24 +00001550// Comparisons.
1551
1552// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001553def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001554 (TEST64rr GR64:$src1, GR64:$src1)>;
1555
Dan Gohman0a3c5222009-01-07 01:00:24 +00001556// Conditional moves with folded loads with operands swapped and conditions
1557// inverted.
1558def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1559 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1560def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1561 (CMOVB64rm GR64:$src2, addr:$src1)>;
1562def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1563 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1564def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1565 (CMOVE64rm GR64:$src2, addr:$src1)>;
1566def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1567 (CMOVA64rm GR64:$src2, addr:$src1)>;
1568def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1569 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1570def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1571 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1572def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1573 (CMOVL64rm GR64:$src2, addr:$src1)>;
1574def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1575 (CMOVG64rm GR64:$src2, addr:$src1)>;
1576def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1577 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1578def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1579 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1580def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1581 (CMOVP64rm GR64:$src2, addr:$src1)>;
1582def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1583 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1584def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1585 (CMOVS64rm GR64:$src2, addr:$src1)>;
1586def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1587 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1588def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1589 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001590
Duncan Sands082524c2008-01-23 20:39:46 +00001591// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001592def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1593
1594// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001595// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1596// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1597// partial-register updates.
1598def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1599def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1600def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1601// For other extloads, use subregs, since the high contents of the register are
1602// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001603def : Pat<(extloadi64i32 addr:$src),
Dan Gohman9959b052009-08-26 14:59:13 +00001604 (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src),
Dan Gohmandd612bb2008-08-20 21:27:32 +00001605 x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001606
Dan Gohman9959b052009-08-26 14:59:13 +00001607// anyext. Define these to do an explicit zero-extend to
1608// avoid partial-register updates.
1609def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1610def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16 :$src)>;
1611def : Pat<(i64 (anyext GR32:$src)),
1612 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001613
1614//===----------------------------------------------------------------------===//
1615// Some peepholes
1616//===----------------------------------------------------------------------===//
1617
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001618// Odd encoding trick: -128 fits into an 8-bit immediate field while
1619// +128 doesn't, so in this special case use a sub instead of an add.
1620def : Pat<(add GR64:$src1, 128),
1621 (SUB64ri8 GR64:$src1, -128)>;
1622def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1623 (SUB64mi8 addr:$dst, -128)>;
1624
1625// The same trick applies for 32-bit immediate fields in 64-bit
1626// instructions.
1627def : Pat<(add GR64:$src1, 0x0000000080000000),
1628 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1629def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1630 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1631
Dan Gohman47a419d2008-08-07 02:54:50 +00001632// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001633def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001634 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001635// r & (2^16-1) ==> movz
1636def : Pat<(and GR64:$src, 0xffff),
1637 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1638// r & (2^8-1) ==> movz
1639def : Pat<(and GR64:$src, 0xff),
1640 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001641// r & (2^8-1) ==> movz
1642def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001643 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001644 Requires<[In64BitMode]>;
1645// r & (2^8-1) ==> movz
1646def : Pat<(and GR16:$src1, 0xff),
1647 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1648 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001649
Dan Gohmandd612bb2008-08-20 21:27:32 +00001650// sext_inreg patterns
1651def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001652 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001653def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001654 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001655def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001656 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001657def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001658 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001659 Requires<[In64BitMode]>;
1660def : Pat<(sext_inreg GR16:$src, i8),
1661 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1662 Requires<[In64BitMode]>;
1663
1664// trunc patterns
1665def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001666 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001667def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001668 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001669def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001670 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001671def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001672 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001673 Requires<[In64BitMode]>;
1674def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001675 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1676 Requires<[In64BitMode]>;
1677
1678// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001679// For now, be conservative on x86-64 and use an h-register extract only if the
1680// value is immediately zero-extended or stored, which are somewhat common
1681// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1682// from being allocated in the same instruction as the h register, as there's
1683// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001684
1685// h-register extract and zero-extend.
1686def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1687 (SUBREG_TO_REG
1688 (i64 0),
1689 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001690 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001691 x86_subreg_8bit_hi)),
1692 x86_subreg_32bit)>;
1693def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1694 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001695 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001696 x86_subreg_8bit_hi))>,
1697 Requires<[In64BitMode]>;
1698def : Pat<(srl_su GR16:$src, (i8 8)),
1699 (EXTRACT_SUBREG
1700 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001701 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001702 x86_subreg_8bit_hi)),
1703 x86_subreg_16bit)>,
1704 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001705def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1706 (MOVZX32_NOREXrr8
1707 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1708 x86_subreg_8bit_hi))>,
1709 Requires<[In64BitMode]>;
Dan Gohman9959b052009-08-26 14:59:13 +00001710def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
1711 (MOVZX32_NOREXrr8
1712 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1713 x86_subreg_8bit_hi))>,
1714 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001715def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1716 (SUBREG_TO_REG
1717 (i64 0),
1718 (MOVZX32_NOREXrr8
1719 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1720 x86_subreg_8bit_hi)),
1721 x86_subreg_32bit)>;
Dan Gohman9959b052009-08-26 14:59:13 +00001722def : Pat<(i64 (anyext (srl_su GR16:$src, (i8 8)))),
1723 (SUBREG_TO_REG
1724 (i64 0),
1725 (MOVZX32_NOREXrr8
1726 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1727 x86_subreg_8bit_hi)),
1728 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001729
1730// h-register extract and store.
1731def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1732 (MOV8mr_NOREX
1733 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001734 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001735 x86_subreg_8bit_hi))>;
1736def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1737 (MOV8mr_NOREX
1738 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001739 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001740 x86_subreg_8bit_hi))>,
1741 Requires<[In64BitMode]>;
1742def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1743 (MOV8mr_NOREX
1744 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001745 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001746 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001747 Requires<[In64BitMode]>;
1748
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001749// (shl x, 1) ==> (add x, x)
1750def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1751
Evan Cheng76a64c72008-08-30 02:03:58 +00001752// (shl x (and y, 63)) ==> (shl x, y)
1753def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1754 (SHL64rCL GR64:$src1)>;
1755def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1756 (SHL64mCL addr:$dst)>;
1757
1758def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1759 (SHR64rCL GR64:$src1)>;
1760def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1761 (SHR64mCL addr:$dst)>;
1762
1763def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1764 (SAR64rCL GR64:$src1)>;
1765def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1766 (SAR64mCL addr:$dst)>;
1767
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001768// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1769def : Pat<(or (srl GR64:$src1, CL:$amt),
1770 (shl GR64:$src2, (sub 64, CL:$amt))),
1771 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1772
1773def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1774 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1775 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1776
Dan Gohman921581d2008-10-17 01:23:35 +00001777def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1778 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1779 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1780
1781def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1782 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1783 addr:$dst),
1784 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1785
1786def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1787 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1788
1789def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1790 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1791 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1792
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001793// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1794def : Pat<(or (shl GR64:$src1, CL:$amt),
1795 (srl GR64:$src2, (sub 64, CL:$amt))),
1796 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1797
1798def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1799 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1800 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1801
Dan Gohman921581d2008-10-17 01:23:35 +00001802def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1803 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1804 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1805
1806def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1807 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1808 addr:$dst),
1809 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1810
1811def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1812 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1813
1814def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1815 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1816 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1817
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001818// X86 specific add which produces a flag.
1819def : Pat<(addc GR64:$src1, GR64:$src2),
1820 (ADD64rr GR64:$src1, GR64:$src2)>;
1821def : Pat<(addc GR64:$src1, (load addr:$src2)),
1822 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001823def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1824 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001825def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1826 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001827
1828def : Pat<(subc GR64:$src1, GR64:$src2),
1829 (SUB64rr GR64:$src1, GR64:$src2)>;
1830def : Pat<(subc GR64:$src1, (load addr:$src2)),
1831 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001832def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1833 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001834def : Pat<(subc GR64:$src1, imm:$src2),
1835 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001836
Bill Wendlingf5399032008-12-12 21:15:41 +00001837//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001838// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001839//===----------------------------------------------------------------------===//
1840
Dan Gohman99a12192009-03-04 19:44:21 +00001841// Register-Register Addition with EFLAGS result
1842def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001843 (implicit EFLAGS)),
1844 (ADD64rr GR64:$src1, GR64:$src2)>;
1845
Dan Gohman99a12192009-03-04 19:44:21 +00001846// Register-Integer Addition with EFLAGS result
1847def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001848 (implicit EFLAGS)),
1849 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001850def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001851 (implicit EFLAGS)),
1852 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001853
Dan Gohman99a12192009-03-04 19:44:21 +00001854// Register-Memory Addition with EFLAGS result
1855def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001856 (implicit EFLAGS)),
1857 (ADD64rm GR64:$src1, addr:$src2)>;
1858
Dan Gohman99a12192009-03-04 19:44:21 +00001859// Memory-Register Addition with EFLAGS result
1860def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001861 addr:$dst),
1862 (implicit EFLAGS)),
1863 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001864def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001865 addr:$dst),
1866 (implicit EFLAGS)),
1867 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001868def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001869 addr:$dst),
1870 (implicit EFLAGS)),
1871 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001872
Dan Gohman99a12192009-03-04 19:44:21 +00001873// Register-Register Subtraction with EFLAGS result
1874def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001875 (implicit EFLAGS)),
1876 (SUB64rr GR64:$src1, GR64:$src2)>;
1877
Dan Gohman99a12192009-03-04 19:44:21 +00001878// Register-Memory Subtraction with EFLAGS result
1879def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001880 (implicit EFLAGS)),
1881 (SUB64rm GR64:$src1, addr:$src2)>;
1882
Dan Gohman99a12192009-03-04 19:44:21 +00001883// Register-Integer Subtraction with EFLAGS result
1884def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001885 (implicit EFLAGS)),
1886 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001887def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001888 (implicit EFLAGS)),
1889 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001890
Dan Gohman99a12192009-03-04 19:44:21 +00001891// Memory-Register Subtraction with EFLAGS result
1892def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001893 addr:$dst),
1894 (implicit EFLAGS)),
1895 (SUB64mr addr:$dst, GR64:$src2)>;
1896
Dan Gohman99a12192009-03-04 19:44:21 +00001897// Memory-Integer Subtraction with EFLAGS result
1898def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001899 addr:$dst),
1900 (implicit EFLAGS)),
1901 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001902def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001903 addr:$dst),
1904 (implicit EFLAGS)),
1905 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001906
Dan Gohman99a12192009-03-04 19:44:21 +00001907// Register-Register Signed Integer Multiplication with EFLAGS result
1908def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001909 (implicit EFLAGS)),
1910 (IMUL64rr GR64:$src1, GR64:$src2)>;
1911
Dan Gohman99a12192009-03-04 19:44:21 +00001912// Register-Memory Signed Integer Multiplication with EFLAGS result
1913def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001914 (implicit EFLAGS)),
1915 (IMUL64rm GR64:$src1, addr:$src2)>;
1916
Dan Gohman99a12192009-03-04 19:44:21 +00001917// Register-Integer Signed Integer Multiplication with EFLAGS result
1918def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001919 (implicit EFLAGS)),
1920 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001921def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001922 (implicit EFLAGS)),
1923 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001924
Dan Gohman99a12192009-03-04 19:44:21 +00001925// Memory-Integer Signed Integer Multiplication with EFLAGS result
1926def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001927 (implicit EFLAGS)),
1928 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001929def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001930 (implicit EFLAGS)),
1931 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001932
Dan Gohman99a12192009-03-04 19:44:21 +00001933// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001934def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1935 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1936def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1937 (implicit EFLAGS)),
1938 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1939def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1940 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1941def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1942 (implicit EFLAGS)),
1943 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1944
1945def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1946 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1947def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1948 (implicit EFLAGS)),
1949 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1950def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1951 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1952def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1953 (implicit EFLAGS)),
1954 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1955
Dan Gohman99a12192009-03-04 19:44:21 +00001956def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1957 (INC64r GR64:$src)>;
1958def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1959 (implicit EFLAGS)),
1960 (INC64m addr:$dst)>;
1961def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1962 (DEC64r GR64:$src)>;
1963def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1964 (implicit EFLAGS)),
1965 (DEC64m addr:$dst)>;
1966
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001967//===----------------------------------------------------------------------===//
1968// X86-64 SSE Instructions
1969//===----------------------------------------------------------------------===//
1970
1971// Move instructions...
1972
Evan Chengb783fa32007-07-19 01:14:50 +00001973def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001974 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001975 [(set VR128:$dst,
1976 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001977def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001978 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001979 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1980 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001981
Evan Chengb783fa32007-07-19 01:14:50 +00001982def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001983 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001984 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001985def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001986 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001987 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1988
Evan Chengb783fa32007-07-19 01:14:50 +00001989def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001990 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001991 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001992def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001993 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001994 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001995
1996//===----------------------------------------------------------------------===//
1997// X86-64 SSE4.1 Instructions
1998//===----------------------------------------------------------------------===//
1999
Nate Begeman4294c1f2008-02-12 22:51:28 +00002000/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2001multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002002 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002003 (ins VR128:$src1, i32i8imm:$src2),
2004 !strconcat(OpcodeStr,
2005 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2006 [(set GR64:$dst,
2007 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002008 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002009 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2010 !strconcat(OpcodeStr,
2011 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2012 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2013 addr:$dst)]>, OpSize, REX_W;
2014}
2015
2016defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2017
2018let isTwoAddress = 1 in {
2019 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002020 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002021 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2022 !strconcat(OpcodeStr,
2023 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2024 [(set VR128:$dst,
2025 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2026 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002027 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002028 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2029 !strconcat(OpcodeStr,
2030 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2031 [(set VR128:$dst,
2032 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2033 imm:$src3)))]>, OpSize, REX_W;
2034 }
2035}
2036
2037defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;