blob: 9e0cea23e74709e2b3b05561f101dfe79aacc682 [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
Chris Lattner357a0ca2009-06-20 19:34:09 +000022
23// 64-bits but only 32 bits are significant, and those bits are treated as being
24// pc relative.
25def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27}
28
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// 64-bits but only 8 bits are significant.
Daniel Dunbaraa097b62009-08-10 21:06:41 +000031def i64i8imm : Operand<i64> {
32 let ParserMatchClass = ImmSExt8AsmOperand;
33}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034
35def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000036 let PrintMethod = "printlea64mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000037 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000038 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}
40
41def lea64_32mem : Operand<i32> {
42 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000043 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000044 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000045 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}
47
48//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000049// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050//
51def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Dan Gohman0c0d7412009-08-02 16:09:17 +000052 [add, sub, mul, X86mul_imm, shl, or, frameindex,
Chris Lattnerc04cd042009-07-11 23:17:29 +000053 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Chris Lattnerf1940742009-06-20 20:38:48 +000055def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
56 [tglobaltlsaddr], []>;
57
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000059// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060//
61
Dan Gohmand16fdc02008-12-19 18:25:21 +000062def i64immSExt8 : PatLeaf<(i64 imm), [{
63 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
64 // sign extended field.
65 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
66}]>;
67
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068def i64immSExt32 : PatLeaf<(i64 imm), [{
69 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
70 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000071 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072}]>;
73
74def i64immZExt32 : PatLeaf<(i64 imm), [{
75 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
76 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000077 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078}]>;
79
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
81def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
82def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
83
84def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
85def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
86def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
87def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
88
89def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
90def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
91def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
92def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
93
94//===----------------------------------------------------------------------===//
95// Instruction list...
96//
97
Dan Gohman01c9f772008-10-01 18:28:06 +000098// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
99// a stack adjustment and the codegen must know that they may modify the stack
100// pointer before prolog-epilog rewriting occurs.
101// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
102// sub / add which can clobber EFLAGS.
103let Defs = [RSP, EFLAGS], Uses = [RSP] in {
104def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
105 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000106 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000107 Requires<[In64BitMode]>;
108def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
109 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000110 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000111 Requires<[In64BitMode]>;
112}
113
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114//===----------------------------------------------------------------------===//
115// Call Instructions...
116//
Evan Cheng37e7c752007-07-21 00:34:19 +0000117let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000118 // All calls clobber the non-callee saved registers. RSP is marked as
119 // a use to prevent stack-pointer assignments that appear immediately
120 // before calls from potentially appearing dead. Uses for argument
121 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000123 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
125 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000126 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
127 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000128
129 // NOTE: this pattern doesn't match "X86call imm", because we do not know
130 // that the offset between an arbitrary immediate and the call will fit in
131 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000132 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000133 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
134 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000135 Requires<[In64BitMode, NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000136 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000137 "call\t{*}$dst", [(X86call GR64:$dst)]>,
138 Requires<[NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000139 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000140 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
141 Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142 }
143
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000144 // FIXME: We need to teach codegen about single list of call-clobbered registers.
145let isCall = 1 in
146 // All calls clobber the non-callee saved registers. RSP is marked as
147 // a use to prevent stack-pointer assignments that appear immediately
148 // before calls from potentially appearing dead. Uses for argument
149 // registers are added manually.
150 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
151 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
152 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
153 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
154 Uses = [RSP] in {
155 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000156 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
157 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000158 Requires<[IsWin64]>;
159 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
160 "call\t{*}$dst",
161 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
162 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
163 "call\t{*}$dst",
164 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
165 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000166
167
168let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000169def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
170 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000171 "#TC_RETURN $dst $offset",
172 []>;
173
174let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000175def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
176 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000177 "#TC_RETURN $dst $offset",
178 []>;
179
180
181let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000182 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
183 "jmp{q}\t{*}$dst # TAILCALL",
184 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000185
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000187let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000188 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000190 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191 [(brind (loadi64 addr:$dst))]>;
192}
193
194//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000195// EH Pseudo Instructions
196//
197let isTerminator = 1, isReturn = 1, isBarrier = 1,
198 hasCtrlDep = 1 in {
199def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
200 "ret\t#eh_return, addr: $addr",
201 [(X86ehret GR64:$addr)]>;
202
203}
204
205//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206// Miscellaneous Instructions...
207//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000208let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000210 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000211let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
212let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000214 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000215let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000217 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
218}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
Bill Wendling4c2638c2009-06-15 19:39:04 +0000220let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
221def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000222 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000223def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000224 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000225def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000226 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000227}
228
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000229let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000230def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000231let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000232def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000233
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000235 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000236 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
238
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000239let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000240def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000241 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 [(set GR64:$dst, lea64addr:$src)]>;
243
244let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248
Evan Cheng48679f42007-12-14 02:13:44 +0000249// Bit scan instructions.
250let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000251def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000252 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000253 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000254def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000255 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000256 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
257 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000258
Evan Cheng4e33de92007-12-14 18:49:43 +0000259def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000260 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000261 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000262def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000263 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000264 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
265 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000266} // Defs = [EFLAGS]
267
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000269let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000270def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000271 [(X86rep_movs i64)]>, REP;
272let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000273def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000274 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000276// Fast system-call instructions
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000277def SYSEXIT64 : RI<0x35, RawFrm,
278 (outs), (ins), "sysexit", []>, TB;
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000279
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280//===----------------------------------------------------------------------===//
281// Move Instructions...
282//
283
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000284let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000285def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000286 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287
Evan Chengd2b9d302008-06-25 01:16:38 +0000288let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000289def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000290 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000292def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000293 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000295}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296
Dan Gohman5574cc72008-12-03 18:15:48 +0000297let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set GR64:$dst, (load addr:$src))]>;
301
Evan Chengb783fa32007-07-19 01:14:50 +0000302def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000303 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000305def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000306 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 [(store i64immSExt32:$src, addr:$dst)]>;
308
309// Sign/Zero extenders
310
Dan Gohmanedde1992009-04-13 15:13:28 +0000311// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
312// operand, which makes it a rare instruction with an 8-bit register
313// operand that can never access an h register. If support for h registers
314// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000315def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000316 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000318def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000319 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000321def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000322 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000324def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000325 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000327def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000328 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000330def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000331 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
333
Dan Gohman9203ab42008-07-30 18:09:17 +0000334// Use movzbl instead of movzbq when the destination is a register; it's
335// equivalent due to implicit zero-extending, and it has a smaller encoding.
336def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
337 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
338 [(set GR64:$dst, (zext GR8:$src))]>, TB;
339def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
340 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
341 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
342// Use movzwl instead of movzwq when the destination is a register; it's
343// equivalent due to implicit zero-extending, and it has a smaller encoding.
344def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
345 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
346 [(set GR64:$dst, (zext GR16:$src))]>, TB;
347def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
348 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
349 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350
Dan Gohman47a419d2008-08-07 02:54:50 +0000351// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000352// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
353// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
354// zero-extension, however this isn't possible when the 32-bit value is
355// defined by a truncate or is copied from something where the high bits aren't
356// necessarily all zero. In such cases, we fall back to these explicit zext
357// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000358def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
359 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
360 [(set GR64:$dst, (zext GR32:$src))]>;
361def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
362 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
363 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
364
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000365// Any instruction that defines a 32-bit result leaves the high half of the
366// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
367// be copying from a truncate, but any other 32-bit operation will zero-extend
368// up to 64 bits.
369def def32 : PatLeaf<(i32 GR32:$src), [{
370 return N->getOpcode() != ISD::TRUNCATE &&
371 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
372 N->getOpcode() != ISD::CopyFromReg;
373}]>;
374
375// In the case of a 32-bit def that is known to implicitly zero-extend,
376// we can use a SUBREG_TO_REG.
377def : Pat<(i64 (zext def32:$src)),
378 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
379
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000380let neverHasSideEffects = 1 in {
381 let Defs = [RAX], Uses = [EAX] in
382 def CDQE : RI<0x98, RawFrm, (outs), (ins),
383 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000385 let Defs = [RAX,RDX], Uses = [RAX] in
386 def CQO : RI<0x99, RawFrm, (outs), (ins),
387 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
388}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
390//===----------------------------------------------------------------------===//
391// Arithmetic Instructions...
392//
393
Evan Cheng55687072007-09-14 21:48:26 +0000394let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395let isTwoAddress = 1 in {
396let isConvertibleToThreeAddress = 1 in {
397let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000398// Register-Register Addition
399def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
400 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000401 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000402 (implicit EFLAGS)]>;
403
404// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000405def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
406 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000407 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
408 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000409def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
410 "add{q}\t{$src2, $dst|$dst, $src2}",
411 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
412 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413} // isConvertibleToThreeAddress
414
Bill Wendlingae034ed2008-12-12 00:56:36 +0000415// Register-Memory Addition
416def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
417 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000418 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000419 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420} // isTwoAddress
421
Bill Wendlingae034ed2008-12-12 00:56:36 +0000422// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000423def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000425 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
426 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000427def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000428 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000429 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
430 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000431def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
432 "add{q}\t{$src2, $dst|$dst, $src2}",
433 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
434 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435
Evan Cheng259471d2007-10-05 17:59:57 +0000436let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437let isTwoAddress = 1 in {
438let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000439def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000440 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000441 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442
Dale Johannesen747fe522009-06-02 03:12:52 +0000443def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000444 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000445 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446
Dale Johannesen747fe522009-06-02 03:12:52 +0000447def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000448 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000449 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
450def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000451 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000452 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453} // isTwoAddress
454
Evan Chengb783fa32007-07-19 01:14:50 +0000455def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000457 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000458def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000460 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000461def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
462 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000463 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000464} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465
466let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000467// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000468def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000469 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000470 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
471 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000472
473// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000474def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000475 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000476 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
477 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000478
479// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000480def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
481 (ins GR64:$src1, i64i8imm:$src2),
482 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000483 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
484 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000485def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
486 (ins GR64:$src1, i64i32imm:$src2),
487 "sub{q}\t{$src2, $dst|$dst, $src2}",
488 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
489 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490} // isTwoAddress
491
Bill Wendlingae034ed2008-12-12 00:56:36 +0000492// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000493def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000494 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000495 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
496 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000497
498// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000499def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000501 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000502 addr:$dst),
503 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000504def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
505 "sub{q}\t{$src2, $dst|$dst, $src2}",
506 [(store (sub (load addr:$dst), i64immSExt32:$src2),
507 addr:$dst),
508 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509
Evan Cheng259471d2007-10-05 17:59:57 +0000510let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000512def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000513 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000514 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515
Dale Johannesen747fe522009-06-02 03:12:52 +0000516def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000517 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000518 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
Dale Johannesen747fe522009-06-02 03:12:52 +0000520def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000521 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000522 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
523def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000524 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000525 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526} // isTwoAddress
527
Evan Chengb783fa32007-07-19 01:14:50 +0000528def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000529 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000530 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000531def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000532 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000533 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000534def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
535 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000536 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000537} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000538} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
540// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000541let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000542def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000543 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000544let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000545def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000546 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
548// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000549def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000550 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000551let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000552def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000553 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
554}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555
Evan Cheng55687072007-09-14 21:48:26 +0000556let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557let isTwoAddress = 1 in {
558let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000559// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000560def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
561 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000562 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000563 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
564 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565
Bill Wendlingf5399032008-12-12 21:15:41 +0000566// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000567def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
568 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000569 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000570 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
571 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572} // isTwoAddress
573
574// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000575
Bill Wendlingf5399032008-12-12 21:15:41 +0000576// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000578 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000579 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000580 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
581 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000582def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
583 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
584 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
585 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
586 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000587
Bill Wendlingf5399032008-12-12 21:15:41 +0000588// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000590 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000591 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000592 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000593 i64immSExt8:$src2)),
594 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000595def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
596 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
597 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
598 [(set GR64:$dst, (mul (load addr:$src1),
599 i64immSExt32:$src2)),
600 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000601} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602
603// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000604let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000605def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000606 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000608def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000609 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000610let mayLoad = 1 in {
611def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
612 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000613def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000614 "idiv{q}\t$src", []>;
615}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000616}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000619let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000621def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000622 [(set GR64:$dst, (ineg GR64:$src)),
623 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000624def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000625 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
626 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627
628let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000629def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000630 [(set GR64:$dst, (add GR64:$src, 1)),
631 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000632def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000633 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
634 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635
636let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000637def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000638 [(set GR64:$dst, (add GR64:$src, -1)),
639 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000640def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000641 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
642 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643
644// In 64-bit mode, single byte INC and DEC cannot be encoded.
645let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
646// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000647def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000648 [(set GR16:$dst, (add GR16:$src, 1)),
649 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000650 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000651def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000652 [(set GR32:$dst, (add GR32:$src, 1)),
653 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000655def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000656 [(set GR16:$dst, (add GR16:$src, -1)),
657 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000659def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000660 [(set GR32:$dst, (add GR32:$src, -1)),
661 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662 Requires<[In64BitMode]>;
663} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000664
665// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
666// how to unfold them.
667let isTwoAddress = 0, CodeSize = 2 in {
668 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000669 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
670 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000671 OpSize, Requires<[In64BitMode]>;
672 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000673 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
674 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000675 Requires<[In64BitMode]>;
676 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000677 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
678 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000679 OpSize, Requires<[In64BitMode]>;
680 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000681 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
682 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000683 Requires<[In64BitMode]>;
684}
Evan Cheng55687072007-09-14 21:48:26 +0000685} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686
687
Evan Cheng55687072007-09-14 21:48:26 +0000688let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689// Shift instructions
690let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000691let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000692def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000693 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000694 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000695let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000699// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
700// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701} // isTwoAddress
702
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000703let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000704def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000705 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000706 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000707def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000710def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
713
714let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000715let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000716def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000717 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000718 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000719def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000720 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000722def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
725} // isTwoAddress
726
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000727let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000728def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000730 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000731def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000732 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000733 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
737
738let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000739let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000742 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
749} // isTwoAddress
750
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000751let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000752def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000754 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000755def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000758def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
761
762// Rotate instructions
763let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000764let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000765def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000766 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000767 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000768def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000769 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000770 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000771def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000772 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
774} // isTwoAddress
775
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000776let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000777def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000778 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000779 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000780def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000781 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000783def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
786
787let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000788let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000789def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000791 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000792def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000793 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000795def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
798} // isTwoAddress
799
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000800let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000801def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000804def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000807def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
810
811// Double shift instructions (generalizations of rotate)
812let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000813let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000814def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000815 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
816 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000817def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000818 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
819 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000820}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821
822let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
823def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000824 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000825 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
826 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
827 (i8 imm:$src3)))]>,
828 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000830 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000831 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
832 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
833 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834 TB;
835} // isCommutable
836} // isTwoAddress
837
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000838let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000839def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000840 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
841 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
842 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000843def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000844 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
845 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
846 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000847}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000849 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000850 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
851 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
852 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853 TB;
854def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000856 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
857 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
858 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000860} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861
862//===----------------------------------------------------------------------===//
863// Logical Instructions...
864//
865
Evan Cheng5b51c242009-01-21 19:45:31 +0000866let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000867def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000869def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
871
Evan Cheng55687072007-09-14 21:48:26 +0000872let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873let isTwoAddress = 1 in {
874let isCommutable = 1 in
875def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000876 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000877 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
879 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000881 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000882 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000883 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
884 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000886 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000887 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000888 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
889 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000890def AND64ri32 : RIi32<0x81, MRM4r,
891 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
892 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000893 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
894 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895} // isTwoAddress
896
897def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000898 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000899 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000900 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
901 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000903 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000904 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000905 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
906 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000907def AND64mi32 : RIi32<0x81, MRM4m,
908 (outs), (ins i64mem:$dst, i64i32imm:$src),
909 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000910 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
911 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912
913let isTwoAddress = 1 in {
914let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000915def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000916 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000917 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
918 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000919def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000920 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000921 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
922 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000923def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000924 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000925 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
926 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000927def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
928 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
930 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000931} // isTwoAddress
932
Evan Chengb783fa32007-07-19 01:14:50 +0000933def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000935 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
936 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000937def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000939 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
940 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000941def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
942 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
944 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945
946let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000947let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000948def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000950 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
951 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000952def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000953 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000954 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
955 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000956def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
957 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000958 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
959 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000961 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000963 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
964 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965} // isTwoAddress
966
Evan Chengb783fa32007-07-19 01:14:50 +0000967def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000969 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
970 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000971def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000972 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000973 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
974 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000975def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
976 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000977 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
978 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000979} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980
981//===----------------------------------------------------------------------===//
982// Comparison Instructions...
983//
984
985// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000986let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000987let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000988def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000990 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
991 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000992def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000993 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000994 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
995 (implicit EFLAGS)]>;
996def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
997 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000998 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000999 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1000 (implicit EFLAGS)]>;
1001def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1002 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001003 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001004 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1005 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006
Evan Chengb783fa32007-07-19 01:14:50 +00001007def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001008 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001009 [(X86cmp GR64:$src1, GR64:$src2),
1010 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001011def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001013 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1014 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001015def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$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, (loadi64 addr:$src2)),
1018 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001019def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1020 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1021 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1022 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001023def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$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, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001026 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001027def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001028 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001029 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001030 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001031def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1032 (ins i64mem:$src1, i64i32imm:$src2),
1033 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1034 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1035 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001036} // Defs = [EFLAGS]
1037
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001038// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001039// TODO: BTC, BTR, and BTS
1040let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001041def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001042 "bt{q}\t{$src2, $src1|$src1, $src2}",
1043 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001044 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001045
1046// Unlike with the register+register form, the memory+register form of the
1047// bt instruction does not ignore the high bits of the index. From ISel's
1048// perspective, this is pretty bizarre. Disable these instructions for now.
1049//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1050// "bt{q}\t{$src2, $src1|$src1, $src2}",
1051// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1052// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001053
1054def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1055 "bt{q}\t{$src2, $src1|$src1, $src2}",
1056 [(X86bt GR64:$src1, i64immSExt8:$src2),
1057 (implicit EFLAGS)]>, TB;
1058// Note that these instructions don't need FastBTMem because that
1059// only applies when the other operand is in a register. When it's
1060// an immediate, bt is still fast.
1061def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1062 "bt{q}\t{$src2, $src1|$src1, $src2}",
1063 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1064 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001065} // Defs = [EFLAGS]
1066
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001068let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001069let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001071 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001072 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001074 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001076 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001079 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001081 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001082 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001084 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001086 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001087 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001089 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001091 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001092 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001094 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001096 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001097 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001099 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001101 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001102 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001104 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001106 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001107 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001108 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001109 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001111 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001112 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001114 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001116 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001117 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001119 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001120def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001121 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001122 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001124 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001126 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001127 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001129 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001131 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001132 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001134 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001135def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001136 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001137 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001139 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001140def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1141 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1142 "cmovo\t{$src2, $dst|$dst, $src2}",
1143 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1144 X86_COND_O, EFLAGS))]>, TB;
1145def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1146 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1147 "cmovno\t{$src2, $dst|$dst, $src2}",
1148 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1149 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001150} // isCommutable = 1
1151
1152def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1153 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1154 "cmovb\t{$src2, $dst|$dst, $src2}",
1155 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1156 X86_COND_B, EFLAGS))]>, TB;
1157def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1158 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1159 "cmovae\t{$src2, $dst|$dst, $src2}",
1160 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1161 X86_COND_AE, EFLAGS))]>, TB;
1162def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1163 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1164 "cmove\t{$src2, $dst|$dst, $src2}",
1165 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1166 X86_COND_E, EFLAGS))]>, TB;
1167def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1168 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1169 "cmovne\t{$src2, $dst|$dst, $src2}",
1170 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1171 X86_COND_NE, EFLAGS))]>, TB;
1172def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1173 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1174 "cmovbe\t{$src2, $dst|$dst, $src2}",
1175 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1176 X86_COND_BE, EFLAGS))]>, TB;
1177def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1178 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1179 "cmova\t{$src2, $dst|$dst, $src2}",
1180 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1181 X86_COND_A, EFLAGS))]>, TB;
1182def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1183 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1184 "cmovl\t{$src2, $dst|$dst, $src2}",
1185 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1186 X86_COND_L, EFLAGS))]>, TB;
1187def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1188 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1189 "cmovge\t{$src2, $dst|$dst, $src2}",
1190 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1191 X86_COND_GE, EFLAGS))]>, TB;
1192def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1193 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1194 "cmovle\t{$src2, $dst|$dst, $src2}",
1195 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1196 X86_COND_LE, EFLAGS))]>, TB;
1197def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1198 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1199 "cmovg\t{$src2, $dst|$dst, $src2}",
1200 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1201 X86_COND_G, EFLAGS))]>, TB;
1202def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1203 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1204 "cmovs\t{$src2, $dst|$dst, $src2}",
1205 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1206 X86_COND_S, EFLAGS))]>, TB;
1207def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1208 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1209 "cmovns\t{$src2, $dst|$dst, $src2}",
1210 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1211 X86_COND_NS, EFLAGS))]>, TB;
1212def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1213 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1214 "cmovp\t{$src2, $dst|$dst, $src2}",
1215 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1216 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001217def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001218 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001221 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001222def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1223 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1224 "cmovo\t{$src2, $dst|$dst, $src2}",
1225 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1226 X86_COND_O, EFLAGS))]>, TB;
1227def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1228 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1229 "cmovno\t{$src2, $dst|$dst, $src2}",
1230 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1231 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001232} // isTwoAddress
1233
1234//===----------------------------------------------------------------------===//
1235// Conversion Instructions...
1236//
1237
1238// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001239def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001240 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001241 [(set GR64:$dst,
1242 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001243def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001244 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001245 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1246 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001247def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001250def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001251 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001252 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001253def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001255 [(set GR64:$dst,
1256 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001257def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001258 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001259 [(set GR64:$dst,
1260 (int_x86_sse2_cvttsd2si64
1261 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001262
1263// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001264def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001265 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001267def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001270
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001271let isTwoAddress = 1 in {
1272def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001273 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001274 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001275 [(set VR128:$dst,
1276 (int_x86_sse2_cvtsi642sd VR128:$src1,
1277 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001278def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001279 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001281 [(set VR128:$dst,
1282 (int_x86_sse2_cvtsi642sd VR128:$src1,
1283 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001284} // isTwoAddress
1285
1286// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001287def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001288 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001290def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001292 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001293
1294let isTwoAddress = 1 in {
1295 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1296 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1297 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1298 [(set VR128:$dst,
1299 (int_x86_sse_cvtsi642ss VR128:$src1,
1300 GR64:$src2))]>;
1301 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1302 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1303 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1304 [(set VR128:$dst,
1305 (int_x86_sse_cvtsi642ss VR128:$src1,
1306 (loadi64 addr:$src2)))]>;
1307}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001308
1309// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001310def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001311 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001312 [(set GR64:$dst,
1313 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001314def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001315 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001316 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1317 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001318def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001319 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001321def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001322 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001323 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001324def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001325 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001326 [(set GR64:$dst,
1327 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001328def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001329 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001330 [(set GR64:$dst,
1331 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1332
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001333//===----------------------------------------------------------------------===//
1334// Alias Instructions
1335//===----------------------------------------------------------------------===//
1336
Dan Gohman027cd112007-09-17 14:55:08 +00001337// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1338// equivalent due to implicit zero-extending, and it sometimes has a smaller
1339// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001340// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001341// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001342let AddedComplexity = 1 in
1343def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001344 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001345
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001346
1347// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001348let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001349def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001350 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001351 [(set GR64:$dst, i64immZExt32:$src)]>;
1352
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001353//===----------------------------------------------------------------------===//
1354// Thread Local Storage Instructions
1355//===----------------------------------------------------------------------===//
1356
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001357// All calls clobber the non-callee saved registers. RSP is marked as
1358// a use to prevent stack-pointer assignments that appear immediately
1359// before calls from potentially appearing dead.
1360let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1361 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1362 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1363 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1364 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1365 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001366def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001367 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001368 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001369 ".word\t0x6666; "
1370 "rex64; "
1371 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001372 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001373 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001374
sampo9cc09a32009-01-26 01:24:32 +00001375let AddedComplexity = 5 in
1376def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1377 "movq\t%gs:$src, $dst",
1378 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1379
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001380let AddedComplexity = 5 in
1381def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1382 "movq\t%fs:$src, $dst",
1383 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1384
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001385//===----------------------------------------------------------------------===//
1386// Atomic Instructions
1387//===----------------------------------------------------------------------===//
1388
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001389let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001390def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001391 "lock\n\t"
1392 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001393 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1394}
1395
Dan Gohmana41a1c092008-08-06 15:52:50 +00001396let Constraints = "$val = $dst" in {
1397let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001398def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001399 "lock\n\t"
1400 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001401 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001402 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001403
Evan Chenga1e80602008-04-19 02:05:42 +00001404def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001405 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001406 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001407}
1408
Evan Chengb723fb52009-07-30 08:33:02 +00001409// Optimized codegen when the non-memory output is not used.
1410// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1411def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1412 "lock\n\t"
1413 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1414def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1415 (ins i64mem:$dst, i64i8imm :$src2),
1416 "lock\n\t"
1417 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1418def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1419 (ins i64mem:$dst, i64i32imm :$src2),
1420 "lock\n\t"
1421 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1422def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1423 "lock\n\t"
1424 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1425def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1426 (ins i64mem:$dst, i64i8imm :$src2),
1427 "lock\n\t"
1428 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1429def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1430 (ins i64mem:$dst, i64i32imm:$src2),
1431 "lock\n\t"
1432 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1433def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1434 "lock\n\t"
1435 "inc{q}\t$dst", []>, LOCK;
1436def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1437 "lock\n\t"
1438 "dec{q}\t$dst", []>, LOCK;
1439
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001440// Atomic exchange, and, or, xor
1441let Constraints = "$val = $dst", Defs = [EFLAGS],
1442 usesCustomDAGSchedInserter = 1 in {
1443def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001444 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001445 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001446def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001447 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001448 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001449def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001450 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001451 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001452def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001453 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001454 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001455def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001456 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001457 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001458def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001459 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001460 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001461def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001462 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001463 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001464def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001465 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001466 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001467}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001468
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001469//===----------------------------------------------------------------------===//
1470// Non-Instruction Patterns
1471//===----------------------------------------------------------------------===//
1472
Chris Lattner0d2dad62009-07-11 22:50:33 +00001473// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1474// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1475// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001476def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001477 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001478def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001479 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001480def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001481 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001483 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484
Chris Lattnerc04cd042009-07-11 23:17:29 +00001485// In static codegen with small code model, we can get the address of a label
1486// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1487// the MOV64ri64i32 should accept these.
1488def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1489 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1490def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1491 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1492def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1493 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1494def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1495 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1496
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001497// In kernel code model, we can get the address of a label
1498// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1499// the MOV64ri32 should accept these.
1500def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1501 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1502def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1503 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1504def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1505 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1506def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1507 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001508
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001509// If we have small model and -static mode, it is safe to store global addresses
1510// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001511// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001512def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1513 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001514 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001515def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1516 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001517 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1519 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001520 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001521def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1522 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001523 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001524
1525// Calls
1526// Direct PC relative function call for small code model. 32-bit displacement
1527// sign extended to 64-bit.
1528def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001529 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001530def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001531 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1532
1533def : Pat<(X86call (i64 tglobaladdr:$dst)),
1534 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1535def : Pat<(X86call (i64 texternalsym:$dst)),
1536 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001537
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001538// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001539def : Pat<(X86tcret GR64:$dst, imm:$off),
1540 (TCRETURNri64 GR64:$dst, imm:$off)>;
1541
1542def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1543 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1544
1545def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1546 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1547
Dan Gohmanec596042007-09-17 14:35:24 +00001548// Comparisons.
1549
1550// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001551def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001552 (TEST64rr GR64:$src1, GR64:$src1)>;
1553
Dan Gohman0a3c5222009-01-07 01:00:24 +00001554// Conditional moves with folded loads with operands swapped and conditions
1555// inverted.
1556def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1557 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1558def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1559 (CMOVB64rm GR64:$src2, addr:$src1)>;
1560def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1561 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1562def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1563 (CMOVE64rm GR64:$src2, addr:$src1)>;
1564def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1565 (CMOVA64rm GR64:$src2, addr:$src1)>;
1566def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1567 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1568def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1569 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1570def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1571 (CMOVL64rm GR64:$src2, addr:$src1)>;
1572def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1573 (CMOVG64rm GR64:$src2, addr:$src1)>;
1574def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1575 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1576def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1577 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1578def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1579 (CMOVP64rm GR64:$src2, addr:$src1)>;
1580def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1581 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1582def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1583 (CMOVS64rm GR64:$src2, addr:$src1)>;
1584def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1585 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1586def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1587 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001588
Duncan Sands082524c2008-01-23 20:39:46 +00001589// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1591
1592// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001593// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1594// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1595// partial-register updates.
1596def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1597def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1598def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1599// For other extloads, use subregs, since the high contents of the register are
1600// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001601def : Pat<(extloadi64i32 addr:$src),
1602 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1603 x86_subreg_32bit)>;
1604def : Pat<(extloadi16i1 addr:$src),
1605 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1606 x86_subreg_8bit)>,
1607 Requires<[In64BitMode]>;
1608def : Pat<(extloadi16i8 addr:$src),
1609 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1610 x86_subreg_8bit)>,
1611 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001612
Dan Gohmandd612bb2008-08-20 21:27:32 +00001613// anyext
1614def : Pat<(i64 (anyext GR8:$src)),
1615 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1616def : Pat<(i64 (anyext GR16:$src)),
1617 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001618def : Pat<(i64 (anyext GR32:$src)),
1619 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001620def : Pat<(i16 (anyext GR8:$src)),
1621 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1622 Requires<[In64BitMode]>;
1623def : Pat<(i32 (anyext GR8:$src)),
1624 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1625 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001626
1627//===----------------------------------------------------------------------===//
1628// Some peepholes
1629//===----------------------------------------------------------------------===//
1630
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001631// Odd encoding trick: -128 fits into an 8-bit immediate field while
1632// +128 doesn't, so in this special case use a sub instead of an add.
1633def : Pat<(add GR64:$src1, 128),
1634 (SUB64ri8 GR64:$src1, -128)>;
1635def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1636 (SUB64mi8 addr:$dst, -128)>;
1637
1638// The same trick applies for 32-bit immediate fields in 64-bit
1639// instructions.
1640def : Pat<(add GR64:$src1, 0x0000000080000000),
1641 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1642def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1643 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1644
Dan Gohman47a419d2008-08-07 02:54:50 +00001645// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001646def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001647 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001648// r & (2^16-1) ==> movz
1649def : Pat<(and GR64:$src, 0xffff),
1650 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1651// r & (2^8-1) ==> movz
1652def : Pat<(and GR64:$src, 0xff),
1653 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001654// r & (2^8-1) ==> movz
1655def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001656 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001657 Requires<[In64BitMode]>;
1658// r & (2^8-1) ==> movz
1659def : Pat<(and GR16:$src1, 0xff),
1660 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1661 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001662
Dan Gohmandd612bb2008-08-20 21:27:32 +00001663// sext_inreg patterns
1664def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001665 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001666def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001667 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001668def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001669 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001670def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001671 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001672 Requires<[In64BitMode]>;
1673def : Pat<(sext_inreg GR16:$src, i8),
1674 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1675 Requires<[In64BitMode]>;
1676
1677// trunc patterns
1678def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001679 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001680def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001681 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001682def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001683 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001684def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001685 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001686 Requires<[In64BitMode]>;
1687def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001688 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1689 Requires<[In64BitMode]>;
1690
1691// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001692// For now, be conservative on x86-64 and use an h-register extract only if the
1693// value is immediately zero-extended or stored, which are somewhat common
1694// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1695// from being allocated in the same instruction as the h register, as there's
1696// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001697
1698// h-register extract and zero-extend.
1699def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1700 (SUBREG_TO_REG
1701 (i64 0),
1702 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001703 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001704 x86_subreg_8bit_hi)),
1705 x86_subreg_32bit)>;
1706def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1707 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001708 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001709 x86_subreg_8bit_hi))>,
1710 Requires<[In64BitMode]>;
1711def : Pat<(srl_su GR16:$src, (i8 8)),
1712 (EXTRACT_SUBREG
1713 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001714 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001715 x86_subreg_8bit_hi)),
1716 x86_subreg_16bit)>,
1717 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001718def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1719 (MOVZX32_NOREXrr8
1720 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1721 x86_subreg_8bit_hi))>,
1722 Requires<[In64BitMode]>;
1723def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1724 (SUBREG_TO_REG
1725 (i64 0),
1726 (MOVZX32_NOREXrr8
1727 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1728 x86_subreg_8bit_hi)),
1729 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001730
1731// h-register extract and store.
1732def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1733 (MOV8mr_NOREX
1734 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001735 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001736 x86_subreg_8bit_hi))>;
1737def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1738 (MOV8mr_NOREX
1739 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001740 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001741 x86_subreg_8bit_hi))>,
1742 Requires<[In64BitMode]>;
1743def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1744 (MOV8mr_NOREX
1745 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001746 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001747 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001748 Requires<[In64BitMode]>;
1749
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750// (shl x, 1) ==> (add x, x)
1751def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1752
Evan Cheng76a64c72008-08-30 02:03:58 +00001753// (shl x (and y, 63)) ==> (shl x, y)
1754def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1755 (SHL64rCL GR64:$src1)>;
1756def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1757 (SHL64mCL addr:$dst)>;
1758
1759def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1760 (SHR64rCL GR64:$src1)>;
1761def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1762 (SHR64mCL addr:$dst)>;
1763
1764def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1765 (SAR64rCL GR64:$src1)>;
1766def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1767 (SAR64mCL addr:$dst)>;
1768
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001769// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1770def : Pat<(or (srl GR64:$src1, CL:$amt),
1771 (shl GR64:$src2, (sub 64, CL:$amt))),
1772 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1773
1774def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1775 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1776 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1777
Dan Gohman921581d2008-10-17 01:23:35 +00001778def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1779 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1780 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1781
1782def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1783 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1784 addr:$dst),
1785 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1786
1787def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1788 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1789
1790def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1791 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1792 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1793
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001794// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1795def : Pat<(or (shl GR64:$src1, CL:$amt),
1796 (srl GR64:$src2, (sub 64, CL:$amt))),
1797 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1798
1799def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1800 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1801 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1802
Dan Gohman921581d2008-10-17 01:23:35 +00001803def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1804 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1805 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1806
1807def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1808 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1809 addr:$dst),
1810 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1811
1812def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1813 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1814
1815def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1816 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1817 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1818
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001819// X86 specific add which produces a flag.
1820def : Pat<(addc GR64:$src1, GR64:$src2),
1821 (ADD64rr GR64:$src1, GR64:$src2)>;
1822def : Pat<(addc GR64:$src1, (load addr:$src2)),
1823 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001824def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1825 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001826def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1827 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001828
1829def : Pat<(subc GR64:$src1, GR64:$src2),
1830 (SUB64rr GR64:$src1, GR64:$src2)>;
1831def : Pat<(subc GR64:$src1, (load addr:$src2)),
1832 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001833def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1834 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001835def : Pat<(subc GR64:$src1, imm:$src2),
1836 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001837
Bill Wendlingf5399032008-12-12 21:15:41 +00001838//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001839// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001840//===----------------------------------------------------------------------===//
1841
Dan Gohman99a12192009-03-04 19:44:21 +00001842// Register-Register Addition with EFLAGS result
1843def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001844 (implicit EFLAGS)),
1845 (ADD64rr GR64:$src1, GR64:$src2)>;
1846
Dan Gohman99a12192009-03-04 19:44:21 +00001847// Register-Integer Addition with EFLAGS result
1848def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001849 (implicit EFLAGS)),
1850 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001851def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001852 (implicit EFLAGS)),
1853 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001854
Dan Gohman99a12192009-03-04 19:44:21 +00001855// Register-Memory Addition with EFLAGS result
1856def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001857 (implicit EFLAGS)),
1858 (ADD64rm GR64:$src1, addr:$src2)>;
1859
Dan Gohman99a12192009-03-04 19:44:21 +00001860// Memory-Register Addition with EFLAGS result
1861def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001862 addr:$dst),
1863 (implicit EFLAGS)),
1864 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001865def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001866 addr:$dst),
1867 (implicit EFLAGS)),
1868 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001869def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001870 addr:$dst),
1871 (implicit EFLAGS)),
1872 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001873
Dan Gohman99a12192009-03-04 19:44:21 +00001874// Register-Register Subtraction with EFLAGS result
1875def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001876 (implicit EFLAGS)),
1877 (SUB64rr GR64:$src1, GR64:$src2)>;
1878
Dan Gohman99a12192009-03-04 19:44:21 +00001879// Register-Memory Subtraction with EFLAGS result
1880def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001881 (implicit EFLAGS)),
1882 (SUB64rm GR64:$src1, addr:$src2)>;
1883
Dan Gohman99a12192009-03-04 19:44:21 +00001884// Register-Integer Subtraction with EFLAGS result
1885def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001886 (implicit EFLAGS)),
1887 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001888def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001889 (implicit EFLAGS)),
1890 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001891
Dan Gohman99a12192009-03-04 19:44:21 +00001892// Memory-Register Subtraction with EFLAGS result
1893def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001894 addr:$dst),
1895 (implicit EFLAGS)),
1896 (SUB64mr addr:$dst, GR64:$src2)>;
1897
Dan Gohman99a12192009-03-04 19:44:21 +00001898// Memory-Integer Subtraction with EFLAGS result
1899def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001900 addr:$dst),
1901 (implicit EFLAGS)),
1902 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001903def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001904 addr:$dst),
1905 (implicit EFLAGS)),
1906 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001907
Dan Gohman99a12192009-03-04 19:44:21 +00001908// Register-Register Signed Integer Multiplication with EFLAGS result
1909def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001910 (implicit EFLAGS)),
1911 (IMUL64rr GR64:$src1, GR64:$src2)>;
1912
Dan Gohman99a12192009-03-04 19:44:21 +00001913// Register-Memory Signed Integer Multiplication with EFLAGS result
1914def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001915 (implicit EFLAGS)),
1916 (IMUL64rm GR64:$src1, addr:$src2)>;
1917
Dan Gohman99a12192009-03-04 19:44:21 +00001918// Register-Integer Signed Integer Multiplication with EFLAGS result
1919def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001920 (implicit EFLAGS)),
1921 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001922def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001923 (implicit EFLAGS)),
1924 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001925
Dan Gohman99a12192009-03-04 19:44:21 +00001926// Memory-Integer Signed Integer Multiplication with EFLAGS result
1927def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001928 (implicit EFLAGS)),
1929 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001930def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001931 (implicit EFLAGS)),
1932 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001933
Dan Gohman99a12192009-03-04 19:44:21 +00001934// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001935def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1936 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1937def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1938 (implicit EFLAGS)),
1939 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1940def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1941 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1942def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1943 (implicit EFLAGS)),
1944 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1945
1946def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1947 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1948def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1949 (implicit EFLAGS)),
1950 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1951def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1952 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1953def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1954 (implicit EFLAGS)),
1955 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1956
Dan Gohman99a12192009-03-04 19:44:21 +00001957def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1958 (INC64r GR64:$src)>;
1959def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1960 (implicit EFLAGS)),
1961 (INC64m addr:$dst)>;
1962def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1963 (DEC64r GR64:$src)>;
1964def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1965 (implicit EFLAGS)),
1966 (DEC64m addr:$dst)>;
1967
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001968//===----------------------------------------------------------------------===//
1969// X86-64 SSE Instructions
1970//===----------------------------------------------------------------------===//
1971
1972// Move instructions...
1973
Evan Chengb783fa32007-07-19 01:14:50 +00001974def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001975 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001976 [(set VR128:$dst,
1977 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001978def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001979 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001980 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1981 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001982
Evan Chengb783fa32007-07-19 01:14:50 +00001983def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001984 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001985 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001986def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001987 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001988 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1989
Evan Chengb783fa32007-07-19 01:14:50 +00001990def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001991 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001992 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001993def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001994 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001995 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001996
1997//===----------------------------------------------------------------------===//
1998// X86-64 SSE4.1 Instructions
1999//===----------------------------------------------------------------------===//
2000
Nate Begeman4294c1f2008-02-12 22:51:28 +00002001/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2002multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002003 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002004 (ins VR128:$src1, i32i8imm:$src2),
2005 !strconcat(OpcodeStr,
2006 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2007 [(set GR64:$dst,
2008 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002009 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002010 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2011 !strconcat(OpcodeStr,
2012 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2013 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2014 addr:$dst)]>, OpSize, REX_W;
2015}
2016
2017defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2018
2019let isTwoAddress = 1 in {
2020 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002021 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002022 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2023 !strconcat(OpcodeStr,
2024 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2025 [(set VR128:$dst,
2026 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2027 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002028 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002029 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2030 !strconcat(OpcodeStr,
2031 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2032 [(set VR128:$dst,
2033 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2034 imm:$src3)))]>, OpSize, REX_W;
2035 }
2036}
2037
2038defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;