blob: 427f6db51c8064e79515f103eba71ee28784de88 [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.
31def i64i8imm : Operand<i64>;
32
33def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000034 let PrintMethod = "printlea64mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
36}
37
38def lea64_32mem : Operand<i32> {
39 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000040 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
42}
43
44//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000045// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046//
47def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Chris Lattnerc04cd042009-07-11 23:17:29 +000048 [add, mul, X86mul_imm, shl, or, frameindex,
49 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
Chris Lattnerf1940742009-06-20 20:38:48 +000051def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
52 [tglobaltlsaddr], []>;
53
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000055// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056//
57
Dan Gohmand16fdc02008-12-19 18:25:21 +000058def i64immSExt8 : PatLeaf<(i64 imm), [{
59 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60 // sign extended field.
61 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
62}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def i64immSExt32 : PatLeaf<(i64 imm), [{
65 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
66 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000067 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068}]>;
69
70def i64immZExt32 : PatLeaf<(i64 imm), [{
71 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
72 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000073 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074}]>;
75
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
77def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
78def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
79
80def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
81def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
82def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
83def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
84
85def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
86def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
87def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
88def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
89
90//===----------------------------------------------------------------------===//
91// Instruction list...
92//
93
Dan Gohman01c9f772008-10-01 18:28:06 +000094// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
95// a stack adjustment and the codegen must know that they may modify the stack
96// pointer before prolog-epilog rewriting occurs.
97// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
98// sub / add which can clobber EFLAGS.
99let Defs = [RSP, EFLAGS], Uses = [RSP] in {
100def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
101 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000102 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000103 Requires<[In64BitMode]>;
104def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
105 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000106 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000107 Requires<[In64BitMode]>;
108}
109
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110//===----------------------------------------------------------------------===//
111// Call Instructions...
112//
Evan Cheng37e7c752007-07-21 00:34:19 +0000113let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000114 // All calls clobber the non-callee saved registers. RSP is marked as
115 // a use to prevent stack-pointer assignments that appear immediately
116 // before calls from potentially appearing dead. Uses for argument
117 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000119 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000120 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
121 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000122 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
123 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000124
125 // NOTE: this pattern doesn't match "X86call imm", because we do not know
126 // that the offset between an arbitrary immediate and the call will fit in
127 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000128 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000129 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
130 "call\t$dst", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000131 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000132 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000133 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000134 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000135 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136 }
137
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000138
139
140let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000141def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
142 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000143 "#TC_RETURN $dst $offset",
144 []>;
145
146let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000147def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
148 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000149 "#TC_RETURN $dst $offset",
150 []>;
151
152
153let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000154 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
155 "jmp{q}\t{*}$dst # TAILCALL",
156 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000157
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000159let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000160 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000162 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 [(brind (loadi64 addr:$dst))]>;
164}
165
166//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000167// EH Pseudo Instructions
168//
169let isTerminator = 1, isReturn = 1, isBarrier = 1,
170 hasCtrlDep = 1 in {
171def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
172 "ret\t#eh_return, addr: $addr",
173 [(X86ehret GR64:$addr)]>;
174
175}
176
177//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178// Miscellaneous Instructions...
179//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000180let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000182 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000183let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
184let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000186 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000187let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000189 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
190}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191
Bill Wendling4c2638c2009-06-15 19:39:04 +0000192let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
193def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000194 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000195def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000196 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000197def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000198 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000199}
200
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000201let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000202def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000203let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000204def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000205
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000207 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000208 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
210
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000211let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000212def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000213 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214 [(set GR64:$dst, lea64addr:$src)]>;
215
216let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000217def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000218 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220
Evan Cheng48679f42007-12-14 02:13:44 +0000221// Bit scan instructions.
222let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000223def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000224 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000225 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000226def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000227 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000228 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
229 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000230
Evan Cheng4e33de92007-12-14 18:49:43 +0000231def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000232 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000233 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000234def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000235 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000236 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
237 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000238} // Defs = [EFLAGS]
239
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000241let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000242def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000243 [(X86rep_movs i64)]>, REP;
244let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000246 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000248// Fast system-call instructions
249def SYSCALL : I<0x05, RawFrm,
250 (outs), (ins), "syscall", []>, TB;
251def SYSENTER : I<0x34, RawFrm,
252 (outs), (ins), "sysenter", []>, TB;
253def SYSEXIT : I<0x35, RawFrm,
254 (outs), (ins), "sysexit", []>, TB;
255def SYSEXIT64 : RI<0x35, RawFrm,
256 (outs), (ins), "sysexit", []>, TB;
257def SYSRET : I<0x07, RawFrm,
258 (outs), (ins), "sysret", []>, TB;
259
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260//===----------------------------------------------------------------------===//
261// Move Instructions...
262//
263
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000264let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000265def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000266 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267
Evan Chengd2b9d302008-06-25 01:16:38 +0000268let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000269def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000270 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000272def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000273 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000275}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276
Dan Gohman5574cc72008-12-03 18:15:48 +0000277let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000278def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000279 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 [(set GR64:$dst, (load addr:$src))]>;
281
Evan Chengb783fa32007-07-19 01:14:50 +0000282def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000283 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000285def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000286 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 [(store i64immSExt32:$src, addr:$dst)]>;
288
289// Sign/Zero extenders
290
Dan Gohmanedde1992009-04-13 15:13:28 +0000291// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
292// operand, which makes it a rare instruction with an 8-bit register
293// operand that can never access an h register. If support for h registers
294// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000295def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000296 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000301def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000302 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000304def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000305 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000307def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000308 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000310def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000311 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
313
Dan Gohman9203ab42008-07-30 18:09:17 +0000314// Use movzbl instead of movzbq when the destination is a register; it's
315// equivalent due to implicit zero-extending, and it has a smaller encoding.
316def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
317 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
318 [(set GR64:$dst, (zext GR8:$src))]>, TB;
319def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
320 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
321 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
322// Use movzwl instead of movzwq when the destination is a register; it's
323// equivalent due to implicit zero-extending, and it has a smaller encoding.
324def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
325 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
326 [(set GR64:$dst, (zext GR16:$src))]>, TB;
327def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
328 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
329 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330
Dan Gohman47a419d2008-08-07 02:54:50 +0000331// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000332// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
333// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
334// zero-extension, however this isn't possible when the 32-bit value is
335// defined by a truncate or is copied from something where the high bits aren't
336// necessarily all zero. In such cases, we fall back to these explicit zext
337// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000338def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
339 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
340 [(set GR64:$dst, (zext GR32:$src))]>;
341def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
342 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
343 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
344
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000345// Any instruction that defines a 32-bit result leaves the high half of the
346// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
347// be copying from a truncate, but any other 32-bit operation will zero-extend
348// up to 64 bits.
349def def32 : PatLeaf<(i32 GR32:$src), [{
350 return N->getOpcode() != ISD::TRUNCATE &&
351 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
352 N->getOpcode() != ISD::CopyFromReg;
353}]>;
354
355// In the case of a 32-bit def that is known to implicitly zero-extend,
356// we can use a SUBREG_TO_REG.
357def : Pat<(i64 (zext def32:$src)),
358 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
359
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000360let neverHasSideEffects = 1 in {
361 let Defs = [RAX], Uses = [EAX] in
362 def CDQE : RI<0x98, RawFrm, (outs), (ins),
363 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000365 let Defs = [RAX,RDX], Uses = [RAX] in
366 def CQO : RI<0x99, RawFrm, (outs), (ins),
367 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
368}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369
370//===----------------------------------------------------------------------===//
371// Arithmetic Instructions...
372//
373
Evan Cheng55687072007-09-14 21:48:26 +0000374let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375let isTwoAddress = 1 in {
376let isConvertibleToThreeAddress = 1 in {
377let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000378// Register-Register Addition
379def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
380 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000381 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000382 (implicit EFLAGS)]>;
383
384// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000385def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
386 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000387 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
388 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000389def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
390 "add{q}\t{$src2, $dst|$dst, $src2}",
391 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
392 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393} // isConvertibleToThreeAddress
394
Bill Wendlingae034ed2008-12-12 00:56:36 +0000395// Register-Memory Addition
396def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
397 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000398 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000399 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400} // isTwoAddress
401
Bill Wendlingae034ed2008-12-12 00:56:36 +0000402// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000403def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000404 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000405 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
406 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000407def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000408 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000409 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
410 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000411def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
412 "add{q}\t{$src2, $dst|$dst, $src2}",
413 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
414 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415
Evan Cheng259471d2007-10-05 17:59:57 +0000416let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417let isTwoAddress = 1 in {
418let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000419def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000420 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000421 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422
Dale Johannesen747fe522009-06-02 03:12:52 +0000423def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000425 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426
Dale Johannesen747fe522009-06-02 03:12:52 +0000427def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000428 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000429 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
430def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000431 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000432 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433} // isTwoAddress
434
Evan Chengb783fa32007-07-19 01:14:50 +0000435def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000436 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000437 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000438def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000439 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000440 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000441def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
442 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000443 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000444} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445
446let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000447// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000448def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000450 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
451 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000452
453// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000454def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000455 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000456 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
457 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000458
459// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000460def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
461 (ins GR64:$src1, i64i8imm:$src2),
462 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000463 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
464 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000465def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
466 (ins GR64:$src1, i64i32imm:$src2),
467 "sub{q}\t{$src2, $dst|$dst, $src2}",
468 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
469 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000470} // isTwoAddress
471
Bill Wendlingae034ed2008-12-12 00:56:36 +0000472// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000473def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000474 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000475 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
476 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000477
478// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000479def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000480 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000481 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000482 addr:$dst),
483 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000484def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
485 "sub{q}\t{$src2, $dst|$dst, $src2}",
486 [(store (sub (load addr:$dst), i64immSExt32:$src2),
487 addr:$dst),
488 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489
Evan Cheng259471d2007-10-05 17:59:57 +0000490let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000492def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000493 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000494 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495
Dale Johannesen747fe522009-06-02 03:12:52 +0000496def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000497 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000498 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499
Dale Johannesen747fe522009-06-02 03:12:52 +0000500def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000502 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
503def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000504 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000505 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506} // isTwoAddress
507
Evan Chengb783fa32007-07-19 01:14:50 +0000508def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000509 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000510 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000511def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000512 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000513 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000514def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
515 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000516 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000517} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000518} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
520// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000521let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000522def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000523 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000524let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000525def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000526 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527
528// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000529def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000530 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000531let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000532def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000533 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
534}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535
Evan Cheng55687072007-09-14 21:48:26 +0000536let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537let isTwoAddress = 1 in {
538let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000539// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000540def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
541 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000542 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000543 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
544 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545
Bill Wendlingf5399032008-12-12 21:15:41 +0000546// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000547def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
548 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000549 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000550 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
551 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552} // isTwoAddress
553
554// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000555
Bill Wendlingf5399032008-12-12 21:15:41 +0000556// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000558 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000559 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000560 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
561 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000562def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
563 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
564 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
565 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
566 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000567
Bill Wendlingf5399032008-12-12 21:15:41 +0000568// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000570 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000571 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000572 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000573 i64immSExt8:$src2)),
574 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000575def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
576 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
577 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
578 [(set GR64:$dst, (mul (load addr:$src1),
579 i64immSExt32:$src2)),
580 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000581} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582
583// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000584let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000585def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000586 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000587// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000588def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000589 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000590let mayLoad = 1 in {
591def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
592 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000593def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000594 "idiv{q}\t$src", []>;
595}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000596}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597
598// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000599let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000601def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000602 [(set GR64:$dst, (ineg GR64:$src)),
603 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000604def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000605 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
606 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607
608let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000609def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000610 [(set GR64:$dst, (add GR64:$src, 1)),
611 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000612def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000613 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
614 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615
616let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000617def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000618 [(set GR64:$dst, (add GR64:$src, -1)),
619 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000620def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000621 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
622 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623
624// In 64-bit mode, single byte INC and DEC cannot be encoded.
625let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
626// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000627def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000628 [(set GR16:$dst, (add GR16:$src, 1)),
629 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000631def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000632 [(set GR32:$dst, (add GR32:$src, 1)),
633 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000635def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000636 [(set GR16:$dst, (add GR16:$src, -1)),
637 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000639def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000640 [(set GR32:$dst, (add GR32:$src, -1)),
641 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642 Requires<[In64BitMode]>;
643} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000644
645// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
646// how to unfold them.
647let isTwoAddress = 0, CodeSize = 2 in {
648 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000649 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
650 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000651 OpSize, Requires<[In64BitMode]>;
652 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000653 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
654 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000655 Requires<[In64BitMode]>;
656 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000657 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
658 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000659 OpSize, Requires<[In64BitMode]>;
660 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000661 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
662 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000663 Requires<[In64BitMode]>;
664}
Evan Cheng55687072007-09-14 21:48:26 +0000665} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666
667
Evan Cheng55687072007-09-14 21:48:26 +0000668let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669// Shift instructions
670let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000671let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000674 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000675let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000676def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000677 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000679// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
680// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681} // isTwoAddress
682
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000683let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000684def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000685 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000686 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000687def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000688 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000690def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
693
694let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000695let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000698 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000699def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000700 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000702def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000703 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
705} // isTwoAddress
706
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000708def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000710 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000714def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000715 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
717
718let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000719let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000721 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000722 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000726def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000727 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
729} // isTwoAddress
730
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000731let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000732def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000733 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000734 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000735def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000736 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000738def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000739 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000740 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
741
742// Rotate instructions
743let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000745def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000747 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000751def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
754} // isTwoAddress
755
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000757def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000759 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000763def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000764 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000765 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
766
767let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000768let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000769def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000771 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000772def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000775def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000776 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
778} // isTwoAddress
779
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000780let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000781def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000782 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000783 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000784def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000785 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000787def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000788 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000789 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
790
791// Double shift instructions (generalizations of rotate)
792let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000793let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000794def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000795 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
796 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000797def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000798 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
799 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000800}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801
802let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
803def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000804 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000805 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
806 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
807 (i8 imm:$src3)))]>,
808 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000810 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000811 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
812 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
813 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814 TB;
815} // isCommutable
816} // isTwoAddress
817
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000818let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000819def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000820 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
821 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
822 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000823def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000824 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
825 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
826 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000827}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000829 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000830 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
831 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
832 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 TB;
834def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000835 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000836 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
837 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
838 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000840} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841
842//===----------------------------------------------------------------------===//
843// Logical Instructions...
844//
845
Evan Cheng5b51c242009-01-21 19:45:31 +0000846let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000847def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000849def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
851
Evan Cheng55687072007-09-14 21:48:26 +0000852let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853let isTwoAddress = 1 in {
854let isCommutable = 1 in
855def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000856 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000857 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000858 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
859 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000861 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000862 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000863 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
864 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000866 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000867 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000868 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
869 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000870def AND64ri32 : RIi32<0x81, MRM4r,
871 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
872 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000873 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
874 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875} // isTwoAddress
876
877def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000878 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000879 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000880 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
881 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000882def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000883 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000884 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000885 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
886 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000887def AND64mi32 : RIi32<0x81, MRM4m,
888 (outs), (ins i64mem:$dst, i64i32imm:$src),
889 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000890 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
891 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000892
893let isTwoAddress = 1 in {
894let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000895def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000896 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000897 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
898 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000899def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000900 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000901 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
902 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000903def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000904 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000905 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
906 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000907def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
908 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000909 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
910 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000911} // isTwoAddress
912
Evan Chengb783fa32007-07-19 01:14:50 +0000913def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000914 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000915 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
916 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000917def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000919 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
920 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000921def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
922 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000923 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
924 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000925
926let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000927let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000928def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000930 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
931 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000932def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000933 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000934 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
935 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000936def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
937 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000938 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
939 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000940def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000941 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
944 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945} // isTwoAddress
946
Evan Chengb783fa32007-07-19 01:14:50 +0000947def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000948 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000949 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
950 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000951def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000952 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000953 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
954 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000955def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
956 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000957 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
958 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000959} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960
961//===----------------------------------------------------------------------===//
962// Comparison Instructions...
963//
964
965// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000966let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000968def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000969 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000970 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
971 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000972def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000973 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000974 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
975 (implicit EFLAGS)]>;
976def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
977 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000978 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000979 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
980 (implicit EFLAGS)]>;
981def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
982 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000983 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000984 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
985 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986
Evan Chengb783fa32007-07-19 01:14:50 +0000987def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000988 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000989 [(X86cmp GR64:$src1, GR64:$src2),
990 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000991def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000992 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000993 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
994 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000995def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000996 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000997 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
998 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000999def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1000 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1001 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1002 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001003def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001005 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001006 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001007def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001008 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001009 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001010 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001011def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1012 (ins i64mem:$src1, i64i32imm:$src2),
1013 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1014 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1015 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001016} // Defs = [EFLAGS]
1017
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001018// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001019// TODO: BTC, BTR, and BTS
1020let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001021def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001022 "bt{q}\t{$src2, $src1|$src1, $src2}",
1023 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001024 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001025
1026// Unlike with the register+register form, the memory+register form of the
1027// bt instruction does not ignore the high bits of the index. From ISel's
1028// perspective, this is pretty bizarre. Disable these instructions for now.
1029//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1030// "bt{q}\t{$src2, $src1|$src1, $src2}",
1031// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1032// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001033
1034def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1035 "bt{q}\t{$src2, $src1|$src1, $src2}",
1036 [(X86bt GR64:$src1, i64immSExt8:$src2),
1037 (implicit EFLAGS)]>, TB;
1038// Note that these instructions don't need FastBTMem because that
1039// only applies when the other operand is in a register. When it's
1040// an immediate, bt is still fast.
1041def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1042 "bt{q}\t{$src2, $src1|$src1, $src2}",
1043 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1044 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001045} // Defs = [EFLAGS]
1046
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001048let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001049let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001051 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001052 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001054 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001056 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001057 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001059 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001061 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001062 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001064 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001066 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001067 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001068 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001069 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070def CMOVBE64rr: RI<0x46, 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 "cmovbe\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_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075def CMOVA64rr : RI<0x47, 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 "cmova\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_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, 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 "cmovl\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_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, 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 "cmovge\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_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, 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 "cmovle\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_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, 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 "cmovg\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_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, 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 "cmovs\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_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, 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 "cmovns\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_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, 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 "cmovp\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_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, 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 "cmovnp\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_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001120def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1121 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1122 "cmovo\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1124 X86_COND_O, EFLAGS))]>, TB;
1125def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1126 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1127 "cmovno\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1129 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001130} // isCommutable = 1
1131
1132def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1133 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1134 "cmovb\t{$src2, $dst|$dst, $src2}",
1135 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1136 X86_COND_B, EFLAGS))]>, TB;
1137def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1138 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1139 "cmovae\t{$src2, $dst|$dst, $src2}",
1140 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1141 X86_COND_AE, EFLAGS))]>, TB;
1142def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1143 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1144 "cmove\t{$src2, $dst|$dst, $src2}",
1145 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1146 X86_COND_E, EFLAGS))]>, TB;
1147def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1148 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1149 "cmovne\t{$src2, $dst|$dst, $src2}",
1150 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1151 X86_COND_NE, EFLAGS))]>, TB;
1152def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1153 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1154 "cmovbe\t{$src2, $dst|$dst, $src2}",
1155 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1156 X86_COND_BE, EFLAGS))]>, TB;
1157def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1158 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1159 "cmova\t{$src2, $dst|$dst, $src2}",
1160 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1161 X86_COND_A, EFLAGS))]>, TB;
1162def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1163 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1164 "cmovl\t{$src2, $dst|$dst, $src2}",
1165 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1166 X86_COND_L, EFLAGS))]>, TB;
1167def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1168 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1169 "cmovge\t{$src2, $dst|$dst, $src2}",
1170 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1171 X86_COND_GE, EFLAGS))]>, TB;
1172def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1173 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1174 "cmovle\t{$src2, $dst|$dst, $src2}",
1175 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1176 X86_COND_LE, EFLAGS))]>, TB;
1177def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1178 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1179 "cmovg\t{$src2, $dst|$dst, $src2}",
1180 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1181 X86_COND_G, EFLAGS))]>, TB;
1182def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1183 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1184 "cmovs\t{$src2, $dst|$dst, $src2}",
1185 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1186 X86_COND_S, EFLAGS))]>, TB;
1187def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1188 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1189 "cmovns\t{$src2, $dst|$dst, $src2}",
1190 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1191 X86_COND_NS, EFLAGS))]>, TB;
1192def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1193 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1194 "cmovp\t{$src2, $dst|$dst, $src2}",
1195 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1196 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001198 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001199 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001201 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001202def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1203 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1204 "cmovo\t{$src2, $dst|$dst, $src2}",
1205 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1206 X86_COND_O, EFLAGS))]>, TB;
1207def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1208 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1209 "cmovno\t{$src2, $dst|$dst, $src2}",
1210 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1211 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212} // isTwoAddress
1213
1214//===----------------------------------------------------------------------===//
1215// Conversion Instructions...
1216//
1217
1218// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001219def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001220 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001221 [(set GR64:$dst,
1222 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001223def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001224 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001225 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1226 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001227def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001228 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001229 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001230def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001231 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001232 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001233def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001235 [(set GR64:$dst,
1236 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001237def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001238 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001239 [(set GR64:$dst,
1240 (int_x86_sse2_cvttsd2si64
1241 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001242
1243// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001244def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001245 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001246 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001247def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001250
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001251let isTwoAddress = 1 in {
1252def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001253 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001255 [(set VR128:$dst,
1256 (int_x86_sse2_cvtsi642sd VR128:$src1,
1257 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001259 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001261 [(set VR128:$dst,
1262 (int_x86_sse2_cvtsi642sd VR128:$src1,
1263 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001264} // isTwoAddress
1265
1266// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001267def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001270def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001273
1274let isTwoAddress = 1 in {
1275 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1276 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1277 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1278 [(set VR128:$dst,
1279 (int_x86_sse_cvtsi642ss VR128:$src1,
1280 GR64:$src2))]>;
1281 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1282 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1283 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1284 [(set VR128:$dst,
1285 (int_x86_sse_cvtsi642ss VR128:$src1,
1286 (loadi64 addr:$src2)))]>;
1287}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001288
1289// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001290def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001292 [(set GR64:$dst,
1293 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001294def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001295 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001296 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1297 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001298def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001299 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001301def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001302 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001303 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001304def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001305 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001306 [(set GR64:$dst,
1307 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001308def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001309 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001310 [(set GR64:$dst,
1311 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1312
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313//===----------------------------------------------------------------------===//
1314// Alias Instructions
1315//===----------------------------------------------------------------------===//
1316
Dan Gohman027cd112007-09-17 14:55:08 +00001317// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1318// equivalent due to implicit zero-extending, and it sometimes has a smaller
1319// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001320// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001321// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001322let AddedComplexity = 1 in
1323def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001324 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001325
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001326
1327// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001328let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001329def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001330 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001331 [(set GR64:$dst, i64immZExt32:$src)]>;
1332
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001333//===----------------------------------------------------------------------===//
1334// Thread Local Storage Instructions
1335//===----------------------------------------------------------------------===//
1336
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001337// All calls clobber the non-callee saved registers. RSP is marked as
1338// a use to prevent stack-pointer assignments that appear immediately
1339// before calls from potentially appearing dead.
1340let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1341 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1342 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1343 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1344 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1345 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001346def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001347 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001348 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001349 ".word\t0x6666; "
1350 "rex64; "
1351 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001352 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001353 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001354
sampo9cc09a32009-01-26 01:24:32 +00001355let AddedComplexity = 5 in
1356def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1357 "movq\t%gs:$src, $dst",
1358 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1359
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001360let AddedComplexity = 5 in
1361def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1362 "movq\t%fs:$src, $dst",
1363 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1364
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001365//===----------------------------------------------------------------------===//
1366// Atomic Instructions
1367//===----------------------------------------------------------------------===//
1368
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001369let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001370def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001371 "lock\n\t"
1372 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001373 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1374}
1375
Dan Gohmana41a1c092008-08-06 15:52:50 +00001376let Constraints = "$val = $dst" in {
1377let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001378def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001379 "lock\n\t"
1380 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001381 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001382 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001383
Evan Chenga1e80602008-04-19 02:05:42 +00001384def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001385 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001386 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001387}
1388
Evan Chengb723fb52009-07-30 08:33:02 +00001389// Optimized codegen when the non-memory output is not used.
1390// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1391def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1392 "lock\n\t"
1393 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1394def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1395 (ins i64mem:$dst, i64i8imm :$src2),
1396 "lock\n\t"
1397 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1398def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1399 (ins i64mem:$dst, i64i32imm :$src2),
1400 "lock\n\t"
1401 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1402def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1403 "lock\n\t"
1404 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1405def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1406 (ins i64mem:$dst, i64i8imm :$src2),
1407 "lock\n\t"
1408 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1409def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1410 (ins i64mem:$dst, i64i32imm:$src2),
1411 "lock\n\t"
1412 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1413def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1414 "lock\n\t"
1415 "inc{q}\t$dst", []>, LOCK;
1416def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1417 "lock\n\t"
1418 "dec{q}\t$dst", []>, LOCK;
1419
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001420// Atomic exchange, and, or, xor
1421let Constraints = "$val = $dst", Defs = [EFLAGS],
1422 usesCustomDAGSchedInserter = 1 in {
1423def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001424 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001425 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001426def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001427 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001428 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001429def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001430 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001431 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001432def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001433 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001434 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001435def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001436 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001437 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001438def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001439 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001440 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001441def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001442 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001443 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001444def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001445 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001446 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001447}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001448
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001449//===----------------------------------------------------------------------===//
1450// Non-Instruction Patterns
1451//===----------------------------------------------------------------------===//
1452
Chris Lattner0d2dad62009-07-11 22:50:33 +00001453// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1454// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1455// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001456def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1457 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1458def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1459 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1460def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1461 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1462def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1463 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1464
Chris Lattnerc04cd042009-07-11 23:17:29 +00001465// In static codegen with small code model, we can get the address of a label
1466// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1467// the MOV64ri64i32 should accept these.
1468def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1469 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1470def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1471 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1472def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1473 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1474def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1475 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1476
1477
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001478// If we have small model and -static mode, it is safe to store global addresses
1479// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001480// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001481def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1482 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001483 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1485 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001486 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001487def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1488 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001489 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1491 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001492 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001493
1494// Calls
1495// Direct PC relative function call for small code model. 32-bit displacement
1496// sign extended to 64-bit.
1497def : Pat<(X86call (i64 tglobaladdr:$dst)),
1498 (CALL64pcrel32 tglobaladdr:$dst)>;
1499def : Pat<(X86call (i64 texternalsym:$dst)),
1500 (CALL64pcrel32 texternalsym:$dst)>;
1501
1502def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1503 (CALL64pcrel32 tglobaladdr:$dst)>;
1504def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1505 (CALL64pcrel32 texternalsym:$dst)>;
1506
1507def : Pat<(X86tailcall GR64:$dst),
1508 (CALL64r GR64:$dst)>;
1509
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001510
1511// tailcall stuff
1512def : Pat<(X86tailcall GR32:$dst),
1513 (TAILCALL)>;
1514def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1515 (TAILCALL)>;
1516def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1517 (TAILCALL)>;
1518
1519def : Pat<(X86tcret GR64:$dst, imm:$off),
1520 (TCRETURNri64 GR64:$dst, imm:$off)>;
1521
1522def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1523 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1524
1525def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1526 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1527
Dan Gohmanec596042007-09-17 14:35:24 +00001528// Comparisons.
1529
1530// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001531def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001532 (TEST64rr GR64:$src1, GR64:$src1)>;
1533
Dan Gohman0a3c5222009-01-07 01:00:24 +00001534// Conditional moves with folded loads with operands swapped and conditions
1535// inverted.
1536def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1537 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1538def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1539 (CMOVB64rm GR64:$src2, addr:$src1)>;
1540def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1541 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1542def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1543 (CMOVE64rm GR64:$src2, addr:$src1)>;
1544def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1545 (CMOVA64rm GR64:$src2, addr:$src1)>;
1546def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1547 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1548def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1549 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1550def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1551 (CMOVL64rm GR64:$src2, addr:$src1)>;
1552def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1553 (CMOVG64rm GR64:$src2, addr:$src1)>;
1554def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1555 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1556def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1557 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1558def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1559 (CMOVP64rm GR64:$src2, addr:$src1)>;
1560def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1561 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1562def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1563 (CMOVS64rm GR64:$src2, addr:$src1)>;
1564def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1565 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1566def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1567 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001568
Duncan Sands082524c2008-01-23 20:39:46 +00001569// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001570def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1571
1572// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001573// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1574// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1575// partial-register updates.
1576def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1577def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1578def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1579// For other extloads, use subregs, since the high contents of the register are
1580// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001581def : Pat<(extloadi64i32 addr:$src),
1582 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1583 x86_subreg_32bit)>;
1584def : Pat<(extloadi16i1 addr:$src),
1585 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1586 x86_subreg_8bit)>,
1587 Requires<[In64BitMode]>;
1588def : Pat<(extloadi16i8 addr:$src),
1589 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1590 x86_subreg_8bit)>,
1591 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001592
Dan Gohmandd612bb2008-08-20 21:27:32 +00001593// anyext
1594def : Pat<(i64 (anyext GR8:$src)),
1595 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1596def : Pat<(i64 (anyext GR16:$src)),
1597 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001598def : Pat<(i64 (anyext GR32:$src)),
1599 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001600def : Pat<(i16 (anyext GR8:$src)),
1601 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1602 Requires<[In64BitMode]>;
1603def : Pat<(i32 (anyext GR8:$src)),
1604 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1605 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001606
1607//===----------------------------------------------------------------------===//
1608// Some peepholes
1609//===----------------------------------------------------------------------===//
1610
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001611// Odd encoding trick: -128 fits into an 8-bit immediate field while
1612// +128 doesn't, so in this special case use a sub instead of an add.
1613def : Pat<(add GR64:$src1, 128),
1614 (SUB64ri8 GR64:$src1, -128)>;
1615def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1616 (SUB64mi8 addr:$dst, -128)>;
1617
1618// The same trick applies for 32-bit immediate fields in 64-bit
1619// instructions.
1620def : Pat<(add GR64:$src1, 0x0000000080000000),
1621 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1622def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1623 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1624
Dan Gohman47a419d2008-08-07 02:54:50 +00001625// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001626def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001627 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001628// r & (2^16-1) ==> movz
1629def : Pat<(and GR64:$src, 0xffff),
1630 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1631// r & (2^8-1) ==> movz
1632def : Pat<(and GR64:$src, 0xff),
1633 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001634// r & (2^8-1) ==> movz
1635def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001636 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001637 Requires<[In64BitMode]>;
1638// r & (2^8-1) ==> movz
1639def : Pat<(and GR16:$src1, 0xff),
1640 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1641 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001642
Dan Gohmandd612bb2008-08-20 21:27:32 +00001643// sext_inreg patterns
1644def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001645 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001646def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001647 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001648def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001649 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001650def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001651 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001652 Requires<[In64BitMode]>;
1653def : Pat<(sext_inreg GR16:$src, i8),
1654 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1655 Requires<[In64BitMode]>;
1656
1657// trunc patterns
1658def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001659 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001660def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001661 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001662def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001663 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001664def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001665 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001666 Requires<[In64BitMode]>;
1667def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001668 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1669 Requires<[In64BitMode]>;
1670
1671// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001672// For now, be conservative on x86-64 and use an h-register extract only if the
1673// value is immediately zero-extended or stored, which are somewhat common
1674// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1675// from being allocated in the same instruction as the h register, as there's
1676// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001677
1678// h-register extract and zero-extend.
1679def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1680 (SUBREG_TO_REG
1681 (i64 0),
1682 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001683 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001684 x86_subreg_8bit_hi)),
1685 x86_subreg_32bit)>;
1686def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1687 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001688 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001689 x86_subreg_8bit_hi))>,
1690 Requires<[In64BitMode]>;
1691def : Pat<(srl_su GR16:$src, (i8 8)),
1692 (EXTRACT_SUBREG
1693 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001694 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001695 x86_subreg_8bit_hi)),
1696 x86_subreg_16bit)>,
1697 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001698def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1699 (MOVZX32_NOREXrr8
1700 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1701 x86_subreg_8bit_hi))>,
1702 Requires<[In64BitMode]>;
1703def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1704 (SUBREG_TO_REG
1705 (i64 0),
1706 (MOVZX32_NOREXrr8
1707 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1708 x86_subreg_8bit_hi)),
1709 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001710
1711// h-register extract and store.
1712def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1713 (MOV8mr_NOREX
1714 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001715 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001716 x86_subreg_8bit_hi))>;
1717def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1718 (MOV8mr_NOREX
1719 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001720 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001721 x86_subreg_8bit_hi))>,
1722 Requires<[In64BitMode]>;
1723def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1724 (MOV8mr_NOREX
1725 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001726 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001727 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001728 Requires<[In64BitMode]>;
1729
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001730// (shl x, 1) ==> (add x, x)
1731def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1732
Evan Cheng76a64c72008-08-30 02:03:58 +00001733// (shl x (and y, 63)) ==> (shl x, y)
1734def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1735 (SHL64rCL GR64:$src1)>;
1736def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1737 (SHL64mCL addr:$dst)>;
1738
1739def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1740 (SHR64rCL GR64:$src1)>;
1741def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1742 (SHR64mCL addr:$dst)>;
1743
1744def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1745 (SAR64rCL GR64:$src1)>;
1746def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1747 (SAR64mCL addr:$dst)>;
1748
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001749// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1750def : Pat<(or (srl GR64:$src1, CL:$amt),
1751 (shl GR64:$src2, (sub 64, CL:$amt))),
1752 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1753
1754def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1755 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1756 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1757
Dan Gohman921581d2008-10-17 01:23:35 +00001758def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1759 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1760 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1761
1762def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1763 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1764 addr:$dst),
1765 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1766
1767def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1768 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1769
1770def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1771 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1772 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1773
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001774// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1775def : Pat<(or (shl GR64:$src1, CL:$amt),
1776 (srl GR64:$src2, (sub 64, CL:$amt))),
1777 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1778
1779def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1780 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1781 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1782
Dan Gohman921581d2008-10-17 01:23:35 +00001783def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1784 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1785 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1786
1787def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1788 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1789 addr:$dst),
1790 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1791
1792def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1793 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1794
1795def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1796 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1797 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1798
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001799// X86 specific add which produces a flag.
1800def : Pat<(addc GR64:$src1, GR64:$src2),
1801 (ADD64rr GR64:$src1, GR64:$src2)>;
1802def : Pat<(addc GR64:$src1, (load addr:$src2)),
1803 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001804def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1805 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001806def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1807 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001808
1809def : Pat<(subc GR64:$src1, GR64:$src2),
1810 (SUB64rr GR64:$src1, GR64:$src2)>;
1811def : Pat<(subc GR64:$src1, (load addr:$src2)),
1812 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001813def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1814 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001815def : Pat<(subc GR64:$src1, imm:$src2),
1816 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001817
Bill Wendlingf5399032008-12-12 21:15:41 +00001818//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001819// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001820//===----------------------------------------------------------------------===//
1821
Dan Gohman99a12192009-03-04 19:44:21 +00001822// Register-Register Addition with EFLAGS result
1823def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001824 (implicit EFLAGS)),
1825 (ADD64rr GR64:$src1, GR64:$src2)>;
1826
Dan Gohman99a12192009-03-04 19:44:21 +00001827// Register-Integer Addition with EFLAGS result
1828def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001829 (implicit EFLAGS)),
1830 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001831def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001832 (implicit EFLAGS)),
1833 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001834
Dan Gohman99a12192009-03-04 19:44:21 +00001835// Register-Memory Addition with EFLAGS result
1836def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001837 (implicit EFLAGS)),
1838 (ADD64rm GR64:$src1, addr:$src2)>;
1839
Dan Gohman99a12192009-03-04 19:44:21 +00001840// Memory-Register Addition with EFLAGS result
1841def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001842 addr:$dst),
1843 (implicit EFLAGS)),
1844 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001845def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001846 addr:$dst),
1847 (implicit EFLAGS)),
1848 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001849def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001850 addr:$dst),
1851 (implicit EFLAGS)),
1852 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001853
Dan Gohman99a12192009-03-04 19:44:21 +00001854// Register-Register Subtraction with EFLAGS result
1855def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001856 (implicit EFLAGS)),
1857 (SUB64rr GR64:$src1, GR64:$src2)>;
1858
Dan Gohman99a12192009-03-04 19:44:21 +00001859// Register-Memory Subtraction with EFLAGS result
1860def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001861 (implicit EFLAGS)),
1862 (SUB64rm GR64:$src1, addr:$src2)>;
1863
Dan Gohman99a12192009-03-04 19:44:21 +00001864// Register-Integer Subtraction with EFLAGS result
1865def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001866 (implicit EFLAGS)),
1867 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001868def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001869 (implicit EFLAGS)),
1870 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001871
Dan Gohman99a12192009-03-04 19:44:21 +00001872// Memory-Register Subtraction with EFLAGS result
1873def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001874 addr:$dst),
1875 (implicit EFLAGS)),
1876 (SUB64mr addr:$dst, GR64:$src2)>;
1877
Dan Gohman99a12192009-03-04 19:44:21 +00001878// Memory-Integer Subtraction with EFLAGS result
1879def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001880 addr:$dst),
1881 (implicit EFLAGS)),
1882 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001883def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001884 addr:$dst),
1885 (implicit EFLAGS)),
1886 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001887
Dan Gohman99a12192009-03-04 19:44:21 +00001888// Register-Register Signed Integer Multiplication with EFLAGS result
1889def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001890 (implicit EFLAGS)),
1891 (IMUL64rr GR64:$src1, GR64:$src2)>;
1892
Dan Gohman99a12192009-03-04 19:44:21 +00001893// Register-Memory Signed Integer Multiplication with EFLAGS result
1894def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001895 (implicit EFLAGS)),
1896 (IMUL64rm GR64:$src1, addr:$src2)>;
1897
Dan Gohman99a12192009-03-04 19:44:21 +00001898// Register-Integer Signed Integer Multiplication with EFLAGS result
1899def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001900 (implicit EFLAGS)),
1901 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001902def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001903 (implicit EFLAGS)),
1904 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001905
Dan Gohman99a12192009-03-04 19:44:21 +00001906// Memory-Integer Signed Integer Multiplication with EFLAGS result
1907def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001908 (implicit EFLAGS)),
1909 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001910def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001911 (implicit EFLAGS)),
1912 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001913
Dan Gohman99a12192009-03-04 19:44:21 +00001914// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001915def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1916 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1917def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1918 (implicit EFLAGS)),
1919 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1920def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1921 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1922def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1923 (implicit EFLAGS)),
1924 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1925
1926def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1927 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1928def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1929 (implicit EFLAGS)),
1930 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1931def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1932 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1933def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1934 (implicit EFLAGS)),
1935 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1936
Dan Gohman99a12192009-03-04 19:44:21 +00001937def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1938 (INC64r GR64:$src)>;
1939def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1940 (implicit EFLAGS)),
1941 (INC64m addr:$dst)>;
1942def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1943 (DEC64r GR64:$src)>;
1944def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1945 (implicit EFLAGS)),
1946 (DEC64m addr:$dst)>;
1947
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001948//===----------------------------------------------------------------------===//
1949// X86-64 SSE Instructions
1950//===----------------------------------------------------------------------===//
1951
1952// Move instructions...
1953
Evan Chengb783fa32007-07-19 01:14:50 +00001954def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001955 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001956 [(set VR128:$dst,
1957 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001958def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001959 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001960 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1961 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001962
Evan Chengb783fa32007-07-19 01:14:50 +00001963def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001964 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001965 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001966def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001967 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001968 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1969
Evan Chengb783fa32007-07-19 01:14:50 +00001970def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001971 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001972 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001973def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001974 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001975 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001976
1977//===----------------------------------------------------------------------===//
1978// X86-64 SSE4.1 Instructions
1979//===----------------------------------------------------------------------===//
1980
Nate Begeman4294c1f2008-02-12 22:51:28 +00001981/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1982multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001983 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001984 (ins VR128:$src1, i32i8imm:$src2),
1985 !strconcat(OpcodeStr,
1986 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1987 [(set GR64:$dst,
1988 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001989 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001990 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1991 !strconcat(OpcodeStr,
1992 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1993 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1994 addr:$dst)]>, OpSize, REX_W;
1995}
1996
1997defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1998
1999let isTwoAddress = 1 in {
2000 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002001 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002002 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2003 !strconcat(OpcodeStr,
2004 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2005 [(set VR128:$dst,
2006 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2007 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002008 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002009 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2010 !strconcat(OpcodeStr,
2011 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2012 [(set VR128:$dst,
2013 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2014 imm:$src3)))]>, OpSize, REX_W;
2015 }
2016}
2017
2018defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;