blob: 53935689f178cde8ef831b19f5b1fd8882e0e398 [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
277def SYSCALL : I<0x05, RawFrm,
278 (outs), (ins), "syscall", []>, TB;
279def SYSENTER : I<0x34, RawFrm,
280 (outs), (ins), "sysenter", []>, TB;
281def SYSEXIT : I<0x35, RawFrm,
282 (outs), (ins), "sysexit", []>, TB;
283def SYSEXIT64 : RI<0x35, RawFrm,
284 (outs), (ins), "sysexit", []>, TB;
285def SYSRET : I<0x07, RawFrm,
286 (outs), (ins), "sysret", []>, TB;
287
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288//===----------------------------------------------------------------------===//
289// Move Instructions...
290//
291
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000292let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000293def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000294 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295
Evan Chengd2b9d302008-06-25 01:16:38 +0000296let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000297def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000298 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000300def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000301 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000303}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304
Dan Gohman5574cc72008-12-03 18:15:48 +0000305let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000306def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000307 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308 [(set GR64:$dst, (load addr:$src))]>;
309
Evan Chengb783fa32007-07-19 01:14:50 +0000310def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000311 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000313def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000314 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 [(store i64immSExt32:$src, addr:$dst)]>;
316
317// Sign/Zero extenders
318
Dan Gohmanedde1992009-04-13 15:13:28 +0000319// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
320// operand, which makes it a rare instruction with an 8-bit register
321// operand that can never access an h register. If support for h registers
322// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000323def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000324 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000326def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000332def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000333 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000335def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000336 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000338def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000339 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
341
Dan Gohman9203ab42008-07-30 18:09:17 +0000342// Use movzbl instead of movzbq when the destination is a register; it's
343// equivalent due to implicit zero-extending, and it has a smaller encoding.
344def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
345 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
346 [(set GR64:$dst, (zext GR8:$src))]>, TB;
347def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
348 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
349 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
350// Use movzwl instead of movzwq when the destination is a register; it's
351// equivalent due to implicit zero-extending, and it has a smaller encoding.
352def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
353 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
354 [(set GR64:$dst, (zext GR16:$src))]>, TB;
355def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
356 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
357 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000358
Dan Gohman47a419d2008-08-07 02:54:50 +0000359// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000360// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
361// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
362// zero-extension, however this isn't possible when the 32-bit value is
363// defined by a truncate or is copied from something where the high bits aren't
364// necessarily all zero. In such cases, we fall back to these explicit zext
365// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000366def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
367 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
368 [(set GR64:$dst, (zext GR32:$src))]>;
369def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
370 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
371 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
372
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000373// Any instruction that defines a 32-bit result leaves the high half of the
374// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
375// be copying from a truncate, but any other 32-bit operation will zero-extend
376// up to 64 bits.
377def def32 : PatLeaf<(i32 GR32:$src), [{
378 return N->getOpcode() != ISD::TRUNCATE &&
379 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
380 N->getOpcode() != ISD::CopyFromReg;
381}]>;
382
383// In the case of a 32-bit def that is known to implicitly zero-extend,
384// we can use a SUBREG_TO_REG.
385def : Pat<(i64 (zext def32:$src)),
386 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
387
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000388let neverHasSideEffects = 1 in {
389 let Defs = [RAX], Uses = [EAX] in
390 def CDQE : RI<0x98, RawFrm, (outs), (ins),
391 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000393 let Defs = [RAX,RDX], Uses = [RAX] in
394 def CQO : RI<0x99, RawFrm, (outs), (ins),
395 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
396}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397
398//===----------------------------------------------------------------------===//
399// Arithmetic Instructions...
400//
401
Evan Cheng55687072007-09-14 21:48:26 +0000402let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403let isTwoAddress = 1 in {
404let isConvertibleToThreeAddress = 1 in {
405let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000406// Register-Register Addition
407def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
408 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000409 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000410 (implicit EFLAGS)]>;
411
412// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000413def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
414 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000415 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
416 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000417def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
418 "add{q}\t{$src2, $dst|$dst, $src2}",
419 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
420 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421} // isConvertibleToThreeAddress
422
Bill Wendlingae034ed2008-12-12 00:56:36 +0000423// Register-Memory Addition
424def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
425 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000426 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000427 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428} // isTwoAddress
429
Bill Wendlingae034ed2008-12-12 00:56:36 +0000430// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000431def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000432 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000433 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
434 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000435def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000436 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000437 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
438 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000439def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
440 "add{q}\t{$src2, $dst|$dst, $src2}",
441 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
442 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000443
Evan Cheng259471d2007-10-05 17:59:57 +0000444let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445let isTwoAddress = 1 in {
446let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000447def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$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, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450
Dale Johannesen747fe522009-06-02 03:12:52 +0000451def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000452 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000453 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454
Dale Johannesen747fe522009-06-02 03:12:52 +0000455def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000457 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
458def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000459 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000460 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461} // isTwoAddress
462
Evan Chengb783fa32007-07-19 01:14:50 +0000463def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000464 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000465 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000466def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000467 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000468 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000469def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
470 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000471 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000472} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
474let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000475// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000476def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000477 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000478 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
479 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000480
481// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000482def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000483 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000484 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
485 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000486
487// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000488def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
489 (ins GR64:$src1, i64i8imm:$src2),
490 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000491 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
492 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000493def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
494 (ins GR64:$src1, i64i32imm:$src2),
495 "sub{q}\t{$src2, $dst|$dst, $src2}",
496 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
497 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498} // isTwoAddress
499
Bill Wendlingae034ed2008-12-12 00:56:36 +0000500// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000501def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000502 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000503 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
504 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000505
506// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000507def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000508 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000509 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000510 addr:$dst),
511 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000512def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
513 "sub{q}\t{$src2, $dst|$dst, $src2}",
514 [(store (sub (load addr:$dst), i64immSExt32:$src2),
515 addr:$dst),
516 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517
Evan Cheng259471d2007-10-05 17:59:57 +0000518let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000520def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$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, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523
Dale Johannesen747fe522009-06-02 03:12:52 +0000524def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000525 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000526 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527
Dale Johannesen747fe522009-06-02 03:12:52 +0000528def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000529 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000530 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
531def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000532 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000533 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534} // isTwoAddress
535
Evan Chengb783fa32007-07-19 01:14:50 +0000536def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000537 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000538 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000539def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000540 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000541 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000542def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
543 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000544 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000545} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000546} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
548// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000549let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000550def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000551 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000552let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000553def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000554 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555
556// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000557def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000558 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000559let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000560def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000561 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
562}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563
Evan Cheng55687072007-09-14 21:48:26 +0000564let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565let isTwoAddress = 1 in {
566let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000567// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000568def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
569 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000570 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000571 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
572 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573
Bill Wendlingf5399032008-12-12 21:15:41 +0000574// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000575def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
576 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000577 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000578 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
579 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580} // isTwoAddress
581
582// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000583
Bill Wendlingf5399032008-12-12 21:15:41 +0000584// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000586 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000587 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000588 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
589 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000590def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
591 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
592 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
593 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
594 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000595
Bill Wendlingf5399032008-12-12 21:15:41 +0000596// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000598 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000599 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000600 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000601 i64immSExt8:$src2)),
602 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000603def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
604 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
605 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
606 [(set GR64:$dst, (mul (load addr:$src1),
607 i64immSExt32:$src2)),
608 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000609} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610
611// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000612let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000613def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000614 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000616def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000617 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000618let mayLoad = 1 in {
619def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
620 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000621def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000622 "idiv{q}\t$src", []>;
623}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000624}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625
626// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000627let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000629def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000630 [(set GR64:$dst, (ineg GR64:$src)),
631 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000632def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000633 [(store (ineg (loadi64 addr:$dst)), 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 INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{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 INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{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
644let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000645def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000646 [(set GR64:$dst, (add GR64:$src, -1)),
647 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000648def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000649 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
650 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651
652// In 64-bit mode, single byte INC and DEC cannot be encoded.
653let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
654// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000655def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{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 INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{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]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000663def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000664 [(set GR16:$dst, (add GR16:$src, -1)),
665 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000667def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000668 [(set GR32:$dst, (add GR32:$src, -1)),
669 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670 Requires<[In64BitMode]>;
671} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000672
673// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
674// how to unfold them.
675let isTwoAddress = 0, CodeSize = 2 in {
676 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{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 INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{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 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000685 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
686 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000687 OpSize, Requires<[In64BitMode]>;
688 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000689 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
690 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000691 Requires<[In64BitMode]>;
692}
Evan Cheng55687072007-09-14 21:48:26 +0000693} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694
695
Evan Cheng55687072007-09-14 21:48:26 +0000696let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697// Shift instructions
698let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000699let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000700def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000702 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000703let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000704def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000705 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000706 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000707// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
708// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709} // isTwoAddress
710
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000711let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000712def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000713 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000714 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000715def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000717 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000718def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000719 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
721
722let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000724def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000725 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000726 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000727def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000730def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000731 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000732 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
733} // isTwoAddress
734
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000735let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000736def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000737 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000738 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000739def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000743 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
745
746let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000747let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000748def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000750 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000751def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000754def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
757} // isTwoAddress
758
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000759let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000760def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000762 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000763def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000764 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000765 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000766def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
769
770// Rotate instructions
771let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000772let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000773def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000774 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000775 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000776def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000777 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000779def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
782} // isTwoAddress
783
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000784let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000785def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000786 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000787 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000788def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000789 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000791def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000792 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
794
795let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000796let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000797def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000798 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000799 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000800def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000801 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000802 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000803def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000804 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000805 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
806} // isTwoAddress
807
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000808let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000809def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000810 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000811 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000812def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000813 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000815def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000816 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
818
819// Double shift instructions (generalizations of rotate)
820let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000821let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000822def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000823 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
824 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000825def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000826 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
827 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000828}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829
830let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
831def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000832 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000833 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
834 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
835 (i8 imm:$src3)))]>,
836 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000838 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000839 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
840 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
841 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 TB;
843} // isCommutable
844} // isTwoAddress
845
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000846let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000847def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000848 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
849 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
850 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000851def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000852 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
853 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
854 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000855}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000857 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000858 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
859 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
860 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 TB;
862def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000863 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000864 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
865 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
866 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000868} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869
870//===----------------------------------------------------------------------===//
871// Logical Instructions...
872//
873
Evan Cheng5b51c242009-01-21 19:45:31 +0000874let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000875def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000876 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000877def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
879
Evan Cheng55687072007-09-14 21:48:26 +0000880let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881let isTwoAddress = 1 in {
882let isCommutable = 1 in
883def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000884 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000886 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
887 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000889 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000890 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000891 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
892 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000893def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000894 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000895 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000896 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
897 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000898def AND64ri32 : RIi32<0x81, MRM4r,
899 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
900 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000901 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
902 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903} // isTwoAddress
904
905def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000906 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000907 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000908 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
909 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000910def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000911 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000912 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000913 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
914 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000915def AND64mi32 : RIi32<0x81, MRM4m,
916 (outs), (ins i64mem:$dst, i64i32imm:$src),
917 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000918 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
919 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920
921let isTwoAddress = 1 in {
922let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000923def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$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, GR64:$src2)),
926 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000927def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
930 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000931def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000932 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000933 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
934 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000935def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
936 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000937 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
938 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000939} // isTwoAddress
940
Evan Chengb783fa32007-07-19 01:14:50 +0000941def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
944 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000945def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000947 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
948 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000949def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
950 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000951 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
952 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953
954let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000955let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000956def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000957 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000958 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
959 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000960def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000962 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
963 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000964def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
965 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000966 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
967 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000969 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000970 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000971 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
972 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973} // isTwoAddress
974
Evan Chengb783fa32007-07-19 01:14:50 +0000975def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000976 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000977 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
978 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000979def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000981 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
982 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000983def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
984 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000985 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
986 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000987} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000988
989//===----------------------------------------------------------------------===//
990// Comparison Instructions...
991//
992
993// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000994let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000996def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000997 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000998 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
999 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001000def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001001 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001002 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1003 (implicit EFLAGS)]>;
1004def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1005 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001006 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001007 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1008 (implicit EFLAGS)]>;
1009def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1010 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001011 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001012 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1013 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001014
Evan Chengb783fa32007-07-19 01:14:50 +00001015def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001016 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001017 [(X86cmp GR64:$src1, GR64:$src2),
1018 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001019def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001020 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001021 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1022 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001023def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001024 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001025 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1026 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001027def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1028 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1029 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1030 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001031def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001032 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001033 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001034 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001035def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001036 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001037 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001038 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001039def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1040 (ins i64mem:$src1, i64i32imm:$src2),
1041 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1042 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1043 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001044} // Defs = [EFLAGS]
1045
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001046// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001047// TODO: BTC, BTR, and BTS
1048let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001049def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001050 "bt{q}\t{$src2, $src1|$src1, $src2}",
1051 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001052 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001053
1054// Unlike with the register+register form, the memory+register form of the
1055// bt instruction does not ignore the high bits of the index. From ISel's
1056// perspective, this is pretty bizarre. Disable these instructions for now.
1057//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1058// "bt{q}\t{$src2, $src1|$src1, $src2}",
1059// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1060// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001061
1062def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1063 "bt{q}\t{$src2, $src1|$src1, $src2}",
1064 [(X86bt GR64:$src1, i64immSExt8:$src2),
1065 (implicit EFLAGS)]>, TB;
1066// Note that these instructions don't need FastBTMem because that
1067// only applies when the other operand is in a register. When it's
1068// an immediate, bt is still fast.
1069def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1070 "bt{q}\t{$src2, $src1|$src1, $src2}",
1071 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1072 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001073} // Defs = [EFLAGS]
1074
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001076let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001077let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001079 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001080 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001082 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001084 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001085 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001087 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001089 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001090 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001092 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001094 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001097 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001099 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001100 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001102 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001104 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001105 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001107 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001108def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001109 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001110 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001112 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001114 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001115 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001117 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001119 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001120 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001122 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001124 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001125 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001127 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001129 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001130 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001132 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001134 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001137 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001139 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001140 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001142 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001144 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001145 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001147 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001148def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1149 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1150 "cmovo\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1152 X86_COND_O, EFLAGS))]>, TB;
1153def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1154 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1155 "cmovno\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1157 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001158} // isCommutable = 1
1159
1160def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1161 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1162 "cmovb\t{$src2, $dst|$dst, $src2}",
1163 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1164 X86_COND_B, EFLAGS))]>, TB;
1165def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1166 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1167 "cmovae\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1169 X86_COND_AE, EFLAGS))]>, TB;
1170def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1171 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1172 "cmove\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1174 X86_COND_E, EFLAGS))]>, TB;
1175def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1176 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1177 "cmovne\t{$src2, $dst|$dst, $src2}",
1178 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1179 X86_COND_NE, EFLAGS))]>, TB;
1180def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1181 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1182 "cmovbe\t{$src2, $dst|$dst, $src2}",
1183 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1184 X86_COND_BE, EFLAGS))]>, TB;
1185def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1186 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1187 "cmova\t{$src2, $dst|$dst, $src2}",
1188 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1189 X86_COND_A, EFLAGS))]>, TB;
1190def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1191 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1192 "cmovl\t{$src2, $dst|$dst, $src2}",
1193 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1194 X86_COND_L, EFLAGS))]>, TB;
1195def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1196 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1197 "cmovge\t{$src2, $dst|$dst, $src2}",
1198 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1199 X86_COND_GE, EFLAGS))]>, TB;
1200def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1201 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1202 "cmovle\t{$src2, $dst|$dst, $src2}",
1203 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1204 X86_COND_LE, EFLAGS))]>, TB;
1205def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1206 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1207 "cmovg\t{$src2, $dst|$dst, $src2}",
1208 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1209 X86_COND_G, EFLAGS))]>, TB;
1210def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1211 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1212 "cmovs\t{$src2, $dst|$dst, $src2}",
1213 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1214 X86_COND_S, EFLAGS))]>, TB;
1215def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1216 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1217 "cmovns\t{$src2, $dst|$dst, $src2}",
1218 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1219 X86_COND_NS, EFLAGS))]>, TB;
1220def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1221 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1222 "cmovp\t{$src2, $dst|$dst, $src2}",
1223 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1224 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001226 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001227 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001228 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001229 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001230def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1231 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1232 "cmovo\t{$src2, $dst|$dst, $src2}",
1233 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1234 X86_COND_O, EFLAGS))]>, TB;
1235def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1236 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1237 "cmovno\t{$src2, $dst|$dst, $src2}",
1238 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1239 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240} // isTwoAddress
1241
1242//===----------------------------------------------------------------------===//
1243// Conversion Instructions...
1244//
1245
1246// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001247def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001249 [(set GR64:$dst,
1250 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001251def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001252 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001253 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1254 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001255def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001256 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001257 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001258def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001259 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001261def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001262 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001263 [(set GR64:$dst,
1264 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001265def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001266 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001267 [(set GR64:$dst,
1268 (int_x86_sse2_cvttsd2si64
1269 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001270
1271// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001272def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001273 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001274 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001275def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001276 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001278
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279let isTwoAddress = 1 in {
1280def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001281 (outs VR128:$dst), (ins VR128:$src1, GR64:$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 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001287 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001288 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001289 [(set VR128:$dst,
1290 (int_x86_sse2_cvtsi642sd VR128:$src1,
1291 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001292} // isTwoAddress
1293
1294// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001295def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001296 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001297 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001298def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001299 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001301
1302let isTwoAddress = 1 in {
1303 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1304 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1305 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1306 [(set VR128:$dst,
1307 (int_x86_sse_cvtsi642ss VR128:$src1,
1308 GR64:$src2))]>;
1309 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1310 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1311 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1312 [(set VR128:$dst,
1313 (int_x86_sse_cvtsi642ss VR128:$src1,
1314 (loadi64 addr:$src2)))]>;
1315}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001316
1317// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001318def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001319 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001320 [(set GR64:$dst,
1321 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001322def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001323 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001324 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1325 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001326def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001327 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001328 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001329def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001330 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001331 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001332def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001333 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001334 [(set GR64:$dst,
1335 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001336def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001337 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001338 [(set GR64:$dst,
1339 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1340
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001341//===----------------------------------------------------------------------===//
1342// Alias Instructions
1343//===----------------------------------------------------------------------===//
1344
Dan Gohman027cd112007-09-17 14:55:08 +00001345// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1346// equivalent due to implicit zero-extending, and it sometimes has a smaller
1347// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001348// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001350let AddedComplexity = 1 in
1351def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001352 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001353
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001354
1355// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001356let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001357def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001358 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359 [(set GR64:$dst, i64immZExt32:$src)]>;
1360
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001361//===----------------------------------------------------------------------===//
1362// Thread Local Storage Instructions
1363//===----------------------------------------------------------------------===//
1364
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001365// All calls clobber the non-callee saved registers. RSP is marked as
1366// a use to prevent stack-pointer assignments that appear immediately
1367// before calls from potentially appearing dead.
1368let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1369 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1370 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1371 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1372 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1373 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001374def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001375 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001376 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001377 ".word\t0x6666; "
1378 "rex64; "
1379 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001380 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001381 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001382
sampo9cc09a32009-01-26 01:24:32 +00001383let AddedComplexity = 5 in
1384def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1385 "movq\t%gs:$src, $dst",
1386 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1387
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001388let AddedComplexity = 5 in
1389def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1390 "movq\t%fs:$src, $dst",
1391 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1392
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001393//===----------------------------------------------------------------------===//
1394// Atomic Instructions
1395//===----------------------------------------------------------------------===//
1396
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001397let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001398def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001399 "lock\n\t"
1400 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001401 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1402}
1403
Dan Gohmana41a1c092008-08-06 15:52:50 +00001404let Constraints = "$val = $dst" in {
1405let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001406def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001407 "lock\n\t"
1408 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001409 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001410 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001411
Evan Chenga1e80602008-04-19 02:05:42 +00001412def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001413 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001414 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001415}
1416
Evan Chengb723fb52009-07-30 08:33:02 +00001417// Optimized codegen when the non-memory output is not used.
1418// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1419def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1420 "lock\n\t"
1421 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1422def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1423 (ins i64mem:$dst, i64i8imm :$src2),
1424 "lock\n\t"
1425 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1426def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1427 (ins i64mem:$dst, i64i32imm :$src2),
1428 "lock\n\t"
1429 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1430def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1431 "lock\n\t"
1432 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1433def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1434 (ins i64mem:$dst, i64i8imm :$src2),
1435 "lock\n\t"
1436 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1437def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1438 (ins i64mem:$dst, i64i32imm:$src2),
1439 "lock\n\t"
1440 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1441def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1442 "lock\n\t"
1443 "inc{q}\t$dst", []>, LOCK;
1444def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1445 "lock\n\t"
1446 "dec{q}\t$dst", []>, LOCK;
1447
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001448// Atomic exchange, and, or, xor
1449let Constraints = "$val = $dst", Defs = [EFLAGS],
1450 usesCustomDAGSchedInserter = 1 in {
1451def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001452 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001453 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001454def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001455 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001456 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001457def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001458 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001459 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001460def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001461 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001462 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001463def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001464 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001465 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001466def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001467 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001468 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001469def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001470 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001471 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001472def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001473 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001474 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001475}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001476
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001477//===----------------------------------------------------------------------===//
1478// Non-Instruction Patterns
1479//===----------------------------------------------------------------------===//
1480
Chris Lattner0d2dad62009-07-11 22:50:33 +00001481// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1482// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1483// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001485 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001487 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001488def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001489 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001491 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001492
Chris Lattnerc04cd042009-07-11 23:17:29 +00001493// In static codegen with small code model, we can get the address of a label
1494// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1495// the MOV64ri64i32 should accept these.
1496def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1497 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1498def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1499 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1500def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1501 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1502def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1503 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1504
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001505// In kernel code model, we can get the address of a label
1506// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1507// the MOV64ri32 should accept these.
1508def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1509 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1510def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1511 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1512def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1513 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1514def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1515 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001516
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001517// If we have small model and -static mode, it is safe to store global addresses
1518// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001519// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1521 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001522 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001523def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1524 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001525 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001526def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1527 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001528 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1530 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001531 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001532
1533// Calls
1534// Direct PC relative function call for small code model. 32-bit displacement
1535// sign extended to 64-bit.
1536def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001537 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001539 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1540
1541def : Pat<(X86call (i64 tglobaladdr:$dst)),
1542 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1543def : Pat<(X86call (i64 texternalsym:$dst)),
1544 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001545
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001546// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001547def : Pat<(X86tcret GR64:$dst, imm:$off),
1548 (TCRETURNri64 GR64:$dst, imm:$off)>;
1549
1550def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1551 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1552
1553def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1554 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1555
Dan Gohmanec596042007-09-17 14:35:24 +00001556// Comparisons.
1557
1558// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001559def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001560 (TEST64rr GR64:$src1, GR64:$src1)>;
1561
Dan Gohman0a3c5222009-01-07 01:00:24 +00001562// Conditional moves with folded loads with operands swapped and conditions
1563// inverted.
1564def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1565 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1566def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1567 (CMOVB64rm GR64:$src2, addr:$src1)>;
1568def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1569 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1570def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1571 (CMOVE64rm GR64:$src2, addr:$src1)>;
1572def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1573 (CMOVA64rm GR64:$src2, addr:$src1)>;
1574def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1575 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1576def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1577 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1578def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1579 (CMOVL64rm GR64:$src2, addr:$src1)>;
1580def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1581 (CMOVG64rm GR64:$src2, addr:$src1)>;
1582def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1583 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1584def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1585 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1586def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1587 (CMOVP64rm GR64:$src2, addr:$src1)>;
1588def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1589 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1590def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1591 (CMOVS64rm GR64:$src2, addr:$src1)>;
1592def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1593 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1594def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1595 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001596
Duncan Sands082524c2008-01-23 20:39:46 +00001597// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001598def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1599
1600// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001601// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1602// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1603// partial-register updates.
1604def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1605def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1606def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1607// For other extloads, use subregs, since the high contents of the register are
1608// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001609def : Pat<(extloadi64i32 addr:$src),
1610 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1611 x86_subreg_32bit)>;
1612def : Pat<(extloadi16i1 addr:$src),
1613 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1614 x86_subreg_8bit)>,
1615 Requires<[In64BitMode]>;
1616def : Pat<(extloadi16i8 addr:$src),
1617 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1618 x86_subreg_8bit)>,
1619 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001620
Dan Gohmandd612bb2008-08-20 21:27:32 +00001621// anyext
1622def : Pat<(i64 (anyext GR8:$src)),
1623 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1624def : Pat<(i64 (anyext GR16:$src)),
1625 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001626def : Pat<(i64 (anyext GR32:$src)),
1627 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001628def : Pat<(i16 (anyext GR8:$src)),
1629 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1630 Requires<[In64BitMode]>;
1631def : Pat<(i32 (anyext GR8:$src)),
1632 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1633 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001634
1635//===----------------------------------------------------------------------===//
1636// Some peepholes
1637//===----------------------------------------------------------------------===//
1638
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001639// Odd encoding trick: -128 fits into an 8-bit immediate field while
1640// +128 doesn't, so in this special case use a sub instead of an add.
1641def : Pat<(add GR64:$src1, 128),
1642 (SUB64ri8 GR64:$src1, -128)>;
1643def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1644 (SUB64mi8 addr:$dst, -128)>;
1645
1646// The same trick applies for 32-bit immediate fields in 64-bit
1647// instructions.
1648def : Pat<(add GR64:$src1, 0x0000000080000000),
1649 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1650def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1651 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1652
Dan Gohman47a419d2008-08-07 02:54:50 +00001653// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001654def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001655 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001656// r & (2^16-1) ==> movz
1657def : Pat<(and GR64:$src, 0xffff),
1658 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1659// r & (2^8-1) ==> movz
1660def : Pat<(and GR64:$src, 0xff),
1661 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001662// r & (2^8-1) ==> movz
1663def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001664 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001665 Requires<[In64BitMode]>;
1666// r & (2^8-1) ==> movz
1667def : Pat<(and GR16:$src1, 0xff),
1668 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1669 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001670
Dan Gohmandd612bb2008-08-20 21:27:32 +00001671// sext_inreg patterns
1672def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001673 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001674def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001675 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001676def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001677 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001678def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001679 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001680 Requires<[In64BitMode]>;
1681def : Pat<(sext_inreg GR16:$src, i8),
1682 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1683 Requires<[In64BitMode]>;
1684
1685// trunc patterns
1686def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001687 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001688def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001689 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001690def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001691 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001692def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001693 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001694 Requires<[In64BitMode]>;
1695def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001696 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1697 Requires<[In64BitMode]>;
1698
1699// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001700// For now, be conservative on x86-64 and use an h-register extract only if the
1701// value is immediately zero-extended or stored, which are somewhat common
1702// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1703// from being allocated in the same instruction as the h register, as there's
1704// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001705
1706// h-register extract and zero-extend.
1707def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1708 (SUBREG_TO_REG
1709 (i64 0),
1710 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001711 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001712 x86_subreg_8bit_hi)),
1713 x86_subreg_32bit)>;
1714def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1715 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001716 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001717 x86_subreg_8bit_hi))>,
1718 Requires<[In64BitMode]>;
1719def : Pat<(srl_su GR16:$src, (i8 8)),
1720 (EXTRACT_SUBREG
1721 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001722 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001723 x86_subreg_8bit_hi)),
1724 x86_subreg_16bit)>,
1725 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001726def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1727 (MOVZX32_NOREXrr8
1728 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1729 x86_subreg_8bit_hi))>,
1730 Requires<[In64BitMode]>;
1731def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1732 (SUBREG_TO_REG
1733 (i64 0),
1734 (MOVZX32_NOREXrr8
1735 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1736 x86_subreg_8bit_hi)),
1737 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001738
1739// h-register extract and store.
1740def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1741 (MOV8mr_NOREX
1742 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001743 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001744 x86_subreg_8bit_hi))>;
1745def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1746 (MOV8mr_NOREX
1747 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001748 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001749 x86_subreg_8bit_hi))>,
1750 Requires<[In64BitMode]>;
1751def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1752 (MOV8mr_NOREX
1753 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001754 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001755 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001756 Requires<[In64BitMode]>;
1757
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001758// (shl x, 1) ==> (add x, x)
1759def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1760
Evan Cheng76a64c72008-08-30 02:03:58 +00001761// (shl x (and y, 63)) ==> (shl x, y)
1762def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1763 (SHL64rCL GR64:$src1)>;
1764def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1765 (SHL64mCL addr:$dst)>;
1766
1767def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1768 (SHR64rCL GR64:$src1)>;
1769def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1770 (SHR64mCL addr:$dst)>;
1771
1772def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1773 (SAR64rCL GR64:$src1)>;
1774def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1775 (SAR64mCL addr:$dst)>;
1776
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001777// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1778def : Pat<(or (srl GR64:$src1, CL:$amt),
1779 (shl GR64:$src2, (sub 64, CL:$amt))),
1780 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1781
1782def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1783 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1784 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1785
Dan Gohman921581d2008-10-17 01:23:35 +00001786def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1787 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1788 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1789
1790def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1791 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1792 addr:$dst),
1793 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1794
1795def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1796 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1797
1798def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1799 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1800 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1801
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001802// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1803def : Pat<(or (shl GR64:$src1, CL:$amt),
1804 (srl GR64:$src2, (sub 64, CL:$amt))),
1805 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1806
1807def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1808 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1809 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1810
Dan Gohman921581d2008-10-17 01:23:35 +00001811def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1812 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1813 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1814
1815def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1816 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1817 addr:$dst),
1818 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1819
1820def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1821 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1822
1823def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1824 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1825 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1826
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001827// X86 specific add which produces a flag.
1828def : Pat<(addc GR64:$src1, GR64:$src2),
1829 (ADD64rr GR64:$src1, GR64:$src2)>;
1830def : Pat<(addc GR64:$src1, (load addr:$src2)),
1831 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001832def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1833 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001834def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1835 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001836
1837def : Pat<(subc GR64:$src1, GR64:$src2),
1838 (SUB64rr GR64:$src1, GR64:$src2)>;
1839def : Pat<(subc GR64:$src1, (load addr:$src2)),
1840 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001841def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1842 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001843def : Pat<(subc GR64:$src1, imm:$src2),
1844 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001845
Bill Wendlingf5399032008-12-12 21:15:41 +00001846//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001847// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001848//===----------------------------------------------------------------------===//
1849
Dan Gohman99a12192009-03-04 19:44:21 +00001850// Register-Register Addition with EFLAGS result
1851def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001852 (implicit EFLAGS)),
1853 (ADD64rr GR64:$src1, GR64:$src2)>;
1854
Dan Gohman99a12192009-03-04 19:44:21 +00001855// Register-Integer Addition with EFLAGS result
1856def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001857 (implicit EFLAGS)),
1858 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001859def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001860 (implicit EFLAGS)),
1861 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001862
Dan Gohman99a12192009-03-04 19:44:21 +00001863// Register-Memory Addition with EFLAGS result
1864def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001865 (implicit EFLAGS)),
1866 (ADD64rm GR64:$src1, addr:$src2)>;
1867
Dan Gohman99a12192009-03-04 19:44:21 +00001868// Memory-Register Addition with EFLAGS result
1869def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001870 addr:$dst),
1871 (implicit EFLAGS)),
1872 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001873def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001874 addr:$dst),
1875 (implicit EFLAGS)),
1876 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001877def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001878 addr:$dst),
1879 (implicit EFLAGS)),
1880 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001881
Dan Gohman99a12192009-03-04 19:44:21 +00001882// Register-Register Subtraction with EFLAGS result
1883def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001884 (implicit EFLAGS)),
1885 (SUB64rr GR64:$src1, GR64:$src2)>;
1886
Dan Gohman99a12192009-03-04 19:44:21 +00001887// Register-Memory Subtraction with EFLAGS result
1888def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001889 (implicit EFLAGS)),
1890 (SUB64rm GR64:$src1, addr:$src2)>;
1891
Dan Gohman99a12192009-03-04 19:44:21 +00001892// Register-Integer Subtraction with EFLAGS result
1893def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001894 (implicit EFLAGS)),
1895 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001896def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001897 (implicit EFLAGS)),
1898 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001899
Dan Gohman99a12192009-03-04 19:44:21 +00001900// Memory-Register Subtraction with EFLAGS result
1901def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001902 addr:$dst),
1903 (implicit EFLAGS)),
1904 (SUB64mr addr:$dst, GR64:$src2)>;
1905
Dan Gohman99a12192009-03-04 19:44:21 +00001906// Memory-Integer Subtraction with EFLAGS result
1907def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001908 addr:$dst),
1909 (implicit EFLAGS)),
1910 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001911def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001912 addr:$dst),
1913 (implicit EFLAGS)),
1914 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001915
Dan Gohman99a12192009-03-04 19:44:21 +00001916// Register-Register Signed Integer Multiplication with EFLAGS result
1917def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001918 (implicit EFLAGS)),
1919 (IMUL64rr GR64:$src1, GR64:$src2)>;
1920
Dan Gohman99a12192009-03-04 19:44:21 +00001921// Register-Memory Signed Integer Multiplication with EFLAGS result
1922def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001923 (implicit EFLAGS)),
1924 (IMUL64rm GR64:$src1, addr:$src2)>;
1925
Dan Gohman99a12192009-03-04 19:44:21 +00001926// Register-Integer Signed Integer Multiplication with EFLAGS result
1927def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001928 (implicit EFLAGS)),
1929 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001930def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001931 (implicit EFLAGS)),
1932 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001933
Dan Gohman99a12192009-03-04 19:44:21 +00001934// Memory-Integer Signed Integer Multiplication with EFLAGS result
1935def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001936 (implicit EFLAGS)),
1937 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001938def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001939 (implicit EFLAGS)),
1940 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001941
Dan Gohman99a12192009-03-04 19:44:21 +00001942// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001943def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1944 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1945def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1946 (implicit EFLAGS)),
1947 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1948def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1949 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1950def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1951 (implicit EFLAGS)),
1952 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1953
1954def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1955 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1956def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1957 (implicit EFLAGS)),
1958 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1959def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1960 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1961def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1962 (implicit EFLAGS)),
1963 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1964
Dan Gohman99a12192009-03-04 19:44:21 +00001965def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1966 (INC64r GR64:$src)>;
1967def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1968 (implicit EFLAGS)),
1969 (INC64m addr:$dst)>;
1970def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1971 (DEC64r GR64:$src)>;
1972def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1973 (implicit EFLAGS)),
1974 (DEC64m addr:$dst)>;
1975
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001976//===----------------------------------------------------------------------===//
1977// X86-64 SSE Instructions
1978//===----------------------------------------------------------------------===//
1979
1980// Move instructions...
1981
Evan Chengb783fa32007-07-19 01:14:50 +00001982def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$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 VR128:$dst,
1985 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001986def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001987 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001988 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1989 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001990
Evan Chengb783fa32007-07-19 01:14:50 +00001991def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001992 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001993 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001994def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001995 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001996 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1997
Evan Chengb783fa32007-07-19 01:14:50 +00001998def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001999 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002000 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002001def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002002 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002003 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002004
2005//===----------------------------------------------------------------------===//
2006// X86-64 SSE4.1 Instructions
2007//===----------------------------------------------------------------------===//
2008
Nate Begeman4294c1f2008-02-12 22:51:28 +00002009/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2010multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002011 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002012 (ins VR128:$src1, i32i8imm:$src2),
2013 !strconcat(OpcodeStr,
2014 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2015 [(set GR64:$dst,
2016 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002017 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002018 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2019 !strconcat(OpcodeStr,
2020 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2021 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2022 addr:$dst)]>, OpSize, REX_W;
2023}
2024
2025defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2026
2027let isTwoAddress = 1 in {
2028 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002029 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002030 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2031 !strconcat(OpcodeStr,
2032 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2033 [(set VR128:$dst,
2034 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2035 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002036 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002037 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2038 !strconcat(OpcodeStr,
2039 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2040 [(set VR128:$dst,
2041 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2042 imm:$src3)))]>, OpSize, REX_W;
2043 }
2044}
2045
2046defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;