blob: f2821287e6fe9476f43de06e92ab3c982b4354ef [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>;
22// 64-bits but only 8 bits are significant.
23def i64i8imm : Operand<i64>;
24
25def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000026 let PrintMethod = "printlea64mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
28}
29
30def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000032 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
34}
35
36//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000037// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038//
39def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Evan Chengc3495762009-03-30 21:36:47 +000040 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
41 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042
43//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000044// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045//
46
Dan Gohmand16fdc02008-12-19 18:25:21 +000047def i64immSExt8 : PatLeaf<(i64 imm), [{
48 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
49 // sign extended field.
50 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
51}]>;
52
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053def i64immSExt32 : PatLeaf<(i64 imm), [{
54 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
55 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000056 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057}]>;
58
59def i64immZExt32 : PatLeaf<(i64 imm), [{
60 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
61 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000062 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063}]>;
64
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
66def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
67def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
68
69def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
70def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
71def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
72def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
73
74def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
75def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
76def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
77def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
78
79//===----------------------------------------------------------------------===//
80// Instruction list...
81//
82
Dan Gohman01c9f772008-10-01 18:28:06 +000083// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
84// a stack adjustment and the codegen must know that they may modify the stack
85// pointer before prolog-epilog rewriting occurs.
86// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
87// sub / add which can clobber EFLAGS.
88let Defs = [RSP, EFLAGS], Uses = [RSP] in {
89def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
90 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000091 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000092 Requires<[In64BitMode]>;
93def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
94 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000095 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000096 Requires<[In64BitMode]>;
97}
98
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099//===----------------------------------------------------------------------===//
100// Call Instructions...
101//
Evan Cheng37e7c752007-07-21 00:34:19 +0000102let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000103 // All calls clobber the non-callee saved registers. RSP is marked as
104 // a use to prevent stack-pointer assignments that appear immediately
105 // before calls from potentially appearing dead. Uses for argument
106 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000107 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000108 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
110 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000111 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
112 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000113
114 // NOTE: this pattern doesn't match "X86call imm", because we do not know
115 // that the offset between an arbitrary immediate and the call will fit in
116 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000117 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Evan Cheng0af5a042009-03-12 18:15:39 +0000118 (outs), (ins i64i32imm:$dst, variable_ops),
Chris Lattner79552392009-03-18 00:43:52 +0000119 "call\t${dst:call}", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000120 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000121 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000122 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000123 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000124 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000125 }
126
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000127
128
129let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000130def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
131 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000132 "#TC_RETURN $dst $offset",
133 []>;
134
135let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000136def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
137 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000138 "#TC_RETURN $dst $offset",
139 []>;
140
141
142let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000143 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
144 "jmp{q}\t{*}$dst # TAILCALL",
145 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000146
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000147// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000148let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000149 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000151 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000152 [(brind (loadi64 addr:$dst))]>;
153}
154
155//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000156// EH Pseudo Instructions
157//
158let isTerminator = 1, isReturn = 1, isBarrier = 1,
159 hasCtrlDep = 1 in {
160def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
161 "ret\t#eh_return, addr: $addr",
162 [(X86ehret GR64:$addr)]>;
163
164}
165
166//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167// Miscellaneous Instructions...
168//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000169let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000171 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000172let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
173let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000175 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000176let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000178 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
179}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180
Bill Wendling4c2638c2009-06-15 19:39:04 +0000181let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
182def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000183 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000184def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000185 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000186def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000187 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000188}
189
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000190let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000191def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000192let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000193def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000194
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000196 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000197 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
199
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000200let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000201def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000202 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 [(set GR64:$dst, lea64addr:$src)]>;
204
205let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000206def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000207 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209
Evan Cheng48679f42007-12-14 02:13:44 +0000210// Bit scan instructions.
211let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000212def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000213 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000214 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000215def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000216 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000217 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
218 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000219
Evan Cheng4e33de92007-12-14 18:49:43 +0000220def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000221 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000222 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000223def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000224 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000225 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
226 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000227} // Defs = [EFLAGS]
228
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000230let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000231def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000232 [(X86rep_movs i64)]>, REP;
233let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000234def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000235 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236
237//===----------------------------------------------------------------------===//
238// Move Instructions...
239//
240
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000241let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000242def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000243 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244
Evan Chengd2b9d302008-06-25 01:16:38 +0000245let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000246def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000247 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000249def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000250 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000252}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253
Dan Gohman5574cc72008-12-03 18:15:48 +0000254let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000255def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000256 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 [(set GR64:$dst, (load addr:$src))]>;
258
Evan Chengb783fa32007-07-19 01:14:50 +0000259def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000260 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000262def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000263 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 [(store i64immSExt32:$src, addr:$dst)]>;
265
266// Sign/Zero extenders
267
Dan Gohmanedde1992009-04-13 15:13:28 +0000268// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
269// operand, which makes it a rare instruction with an 8-bit register
270// operand that can never access an h register. If support for h registers
271// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000272def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000273 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000275def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000276 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000278def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000279 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000281def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000282 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000283 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000284def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000285 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000287def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000288 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
290
Dan Gohman9203ab42008-07-30 18:09:17 +0000291// Use movzbl instead of movzbq when the destination is a register; it's
292// equivalent due to implicit zero-extending, and it has a smaller encoding.
293def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
294 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zext GR8:$src))]>, TB;
296def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
297 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
298 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
299// Use movzwl instead of movzwq when the destination is a register; it's
300// equivalent due to implicit zero-extending, and it has a smaller encoding.
301def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
302 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
303 [(set GR64:$dst, (zext GR16:$src))]>, TB;
304def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
305 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307
Dan Gohman47a419d2008-08-07 02:54:50 +0000308// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000309// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
310// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
311// zero-extension, however this isn't possible when the 32-bit value is
312// defined by a truncate or is copied from something where the high bits aren't
313// necessarily all zero. In such cases, we fall back to these explicit zext
314// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000315def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
316 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
317 [(set GR64:$dst, (zext GR32:$src))]>;
318def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
319 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
320 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
321
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000322// Any instruction that defines a 32-bit result leaves the high half of the
323// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
324// be copying from a truncate, but any other 32-bit operation will zero-extend
325// up to 64 bits.
326def def32 : PatLeaf<(i32 GR32:$src), [{
327 return N->getOpcode() != ISD::TRUNCATE &&
328 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
329 N->getOpcode() != ISD::CopyFromReg;
330}]>;
331
332// In the case of a 32-bit def that is known to implicitly zero-extend,
333// we can use a SUBREG_TO_REG.
334def : Pat<(i64 (zext def32:$src)),
335 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
336
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000337let neverHasSideEffects = 1 in {
338 let Defs = [RAX], Uses = [EAX] in
339 def CDQE : RI<0x98, RawFrm, (outs), (ins),
340 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000342 let Defs = [RAX,RDX], Uses = [RAX] in
343 def CQO : RI<0x99, RawFrm, (outs), (ins),
344 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
345}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346
347//===----------------------------------------------------------------------===//
348// Arithmetic Instructions...
349//
350
Evan Cheng55687072007-09-14 21:48:26 +0000351let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352let isTwoAddress = 1 in {
353let isConvertibleToThreeAddress = 1 in {
354let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000355// Register-Register Addition
356def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
357 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000358 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000359 (implicit EFLAGS)]>;
360
361// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000362def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
363 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000364 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
365 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000366def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
367 "add{q}\t{$src2, $dst|$dst, $src2}",
368 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
369 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370} // isConvertibleToThreeAddress
371
Bill Wendlingae034ed2008-12-12 00:56:36 +0000372// Register-Memory Addition
373def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
374 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000375 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000376 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377} // isTwoAddress
378
Bill Wendlingae034ed2008-12-12 00:56:36 +0000379// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000380def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000381 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000382 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
383 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000384def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000385 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000386 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
387 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000388def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
389 "add{q}\t{$src2, $dst|$dst, $src2}",
390 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
391 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392
Evan Cheng259471d2007-10-05 17:59:57 +0000393let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394let isTwoAddress = 1 in {
395let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000396def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000397 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000398 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399
Dale Johannesen747fe522009-06-02 03:12:52 +0000400def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000401 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000402 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403
Dale Johannesen747fe522009-06-02 03:12:52 +0000404def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000405 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000406 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
407def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000408 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000409 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410} // isTwoAddress
411
Evan Chengb783fa32007-07-19 01:14:50 +0000412def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000413 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000414 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000415def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000416 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000417 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000418def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
419 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000420 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000421} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422
423let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000424// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000425def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000426 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000427 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
428 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000429
430// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000431def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000432 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000433 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
434 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000435
436// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000437def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
438 (ins GR64:$src1, i64i8imm:$src2),
439 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000440 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
441 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000442def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
443 (ins GR64:$src1, i64i32imm:$src2),
444 "sub{q}\t{$src2, $dst|$dst, $src2}",
445 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
446 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447} // isTwoAddress
448
Bill Wendlingae034ed2008-12-12 00:56:36 +0000449// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000450def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000451 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000452 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
453 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000454
455// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000456def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000457 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000458 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000459 addr:$dst),
460 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000461def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
462 "sub{q}\t{$src2, $dst|$dst, $src2}",
463 [(store (sub (load addr:$dst), i64immSExt32:$src2),
464 addr:$dst),
465 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466
Evan Cheng259471d2007-10-05 17:59:57 +0000467let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000469def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000470 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000471 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
Dale Johannesen747fe522009-06-02 03:12:52 +0000473def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000474 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000475 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476
Dale Johannesen747fe522009-06-02 03:12:52 +0000477def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000479 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
480def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000481 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000482 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483} // isTwoAddress
484
Evan Chengb783fa32007-07-19 01:14:50 +0000485def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000487 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000488def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000490 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000491def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
492 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000493 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000494} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000495} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496
497// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000498let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000499def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000500 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000501let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000502def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000503 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504
505// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000506def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000507 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000508let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000509def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000510 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
511}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512
Evan Cheng55687072007-09-14 21:48:26 +0000513let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514let isTwoAddress = 1 in {
515let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000516// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000517def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
518 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000519 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000520 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
521 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522
Bill Wendlingf5399032008-12-12 21:15:41 +0000523// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000524def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
525 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000526 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000527 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
528 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529} // isTwoAddress
530
531// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000532
Bill Wendlingf5399032008-12-12 21:15:41 +0000533// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000535 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000536 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000537 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
538 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000539def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
540 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
541 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
542 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
543 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000544
Bill Wendlingf5399032008-12-12 21:15:41 +0000545// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000547 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000548 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000549 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000550 i64immSExt8:$src2)),
551 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000552def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
553 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
554 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
555 [(set GR64:$dst, (mul (load addr:$src1),
556 i64immSExt32:$src2)),
557 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000558} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559
560// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000561let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000562def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000563 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000565def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000566 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000567let mayLoad = 1 in {
568def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
569 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000570def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000571 "idiv{q}\t$src", []>;
572}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000573}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574
575// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000576let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000578def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000579 [(set GR64:$dst, (ineg GR64:$src)),
580 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000581def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000582 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
583 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584
585let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000586def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000587 [(set GR64:$dst, (add GR64:$src, 1)),
588 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000589def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000590 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
591 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592
593let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000594def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000595 [(set GR64:$dst, (add GR64:$src, -1)),
596 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000597def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000598 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
599 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600
601// In 64-bit mode, single byte INC and DEC cannot be encoded.
602let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
603// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000604def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000605 [(set GR16:$dst, (add GR16:$src, 1)),
606 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000608def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000609 [(set GR32:$dst, (add GR32:$src, 1)),
610 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000612def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000613 [(set GR16:$dst, (add GR16:$src, -1)),
614 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000616def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000617 [(set GR32:$dst, (add GR32:$src, -1)),
618 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619 Requires<[In64BitMode]>;
620} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000621
622// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
623// how to unfold them.
624let isTwoAddress = 0, CodeSize = 2 in {
625 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000626 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
627 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000628 OpSize, Requires<[In64BitMode]>;
629 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000630 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
631 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000632 Requires<[In64BitMode]>;
633 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000634 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
635 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000636 OpSize, Requires<[In64BitMode]>;
637 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000638 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
639 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000640 Requires<[In64BitMode]>;
641}
Evan Cheng55687072007-09-14 21:48:26 +0000642} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643
644
Evan Cheng55687072007-09-14 21:48:26 +0000645let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646// Shift instructions
647let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000648let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000649def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000650 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000651 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000652let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000653def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000654 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000656// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
657// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658} // isTwoAddress
659
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000660let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000661def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000662 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000663 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000664def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000665 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000667def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000668 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
670
671let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000672let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000673def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000674 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000675 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000676def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000677 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000679def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000680 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
682} // isTwoAddress
683
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000684let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000685def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000687 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000688def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000689 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000691def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000692 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
694
695let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000696let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000697def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000699 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000700def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000703def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000704 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000705 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
706} // isTwoAddress
707
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000708let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000709def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000710 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000711 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000712def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000713 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000715def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000717 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
718
719// Rotate instructions
720let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000721let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000722def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000724 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000725def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000726 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000728def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
731} // isTwoAddress
732
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000733let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000734def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000736 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000737def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000738 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000740def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000742 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
743
744let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000745let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000746def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000748 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000749def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000750 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000752def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
755} // isTwoAddress
756
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000757let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000758def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000760 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000761def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000763 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000764def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000765 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000766 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
767
768// Double shift instructions (generalizations of rotate)
769let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000770let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000771def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000772 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
773 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000774def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000775 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
776 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000777}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778
779let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
780def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000781 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000782 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
783 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
784 (i8 imm:$src3)))]>,
785 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000787 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000788 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
789 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
790 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 TB;
792} // isCommutable
793} // isTwoAddress
794
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000795let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000796def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000797 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
798 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
799 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000800def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000801 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
802 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
803 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000804}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000805def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000806 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000807 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
808 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
809 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000810 TB;
811def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000812 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000813 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
814 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
815 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000817} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818
819//===----------------------------------------------------------------------===//
820// Logical Instructions...
821//
822
Evan Cheng5b51c242009-01-21 19:45:31 +0000823let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000824def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000825 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000826def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
828
Evan Cheng55687072007-09-14 21:48:26 +0000829let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830let isTwoAddress = 1 in {
831let isCommutable = 1 in
832def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000833 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000834 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000835 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
836 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000838 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000839 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000840 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
841 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000843 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000844 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000845 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
846 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000847def AND64ri32 : RIi32<0x81, MRM4r,
848 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
849 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000850 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
851 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000852} // isTwoAddress
853
854def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000856 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000857 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
858 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000860 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000861 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000862 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
863 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000864def AND64mi32 : RIi32<0x81, MRM4m,
865 (outs), (ins i64mem:$dst, i64i32imm:$src),
866 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000867 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
868 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869
870let isTwoAddress = 1 in {
871let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000872def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000873 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000874 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
875 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000876def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000877 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
879 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000880def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000881 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000882 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
883 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000884def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
885 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000886 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
887 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888} // isTwoAddress
889
Evan Chengb783fa32007-07-19 01:14:50 +0000890def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000891 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000892 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
893 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000894def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000895 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000896 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
897 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000898def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
899 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000900 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
901 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902
903let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000904let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000905def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000906 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000907 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
908 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000909def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000910 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000911 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
912 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000913def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
914 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000915 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
916 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000917def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000918 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000919 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000920 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
921 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000922} // isTwoAddress
923
Evan Chengb783fa32007-07-19 01:14:50 +0000924def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000925 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000926 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
927 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000928def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000930 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
931 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000932def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
933 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000934 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
935 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000936} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937
938//===----------------------------------------------------------------------===//
939// Comparison Instructions...
940//
941
942// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000943let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000944let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000945def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000947 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
948 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000949def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000950 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000951 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
952 (implicit EFLAGS)]>;
953def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
954 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000956 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
957 (implicit EFLAGS)]>;
958def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
959 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000960 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000961 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
962 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963
Evan Chengb783fa32007-07-19 01:14:50 +0000964def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000966 [(X86cmp GR64:$src1, GR64:$src2),
967 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000968def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000969 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000970 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
971 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000972def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000973 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000974 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
975 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000976def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
977 "cmp{q}\t{$src2, $src1|$src1, $src2}",
978 [(X86cmp GR64:$src1, i64immSExt8:$src2),
979 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000980def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000981 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000982 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000983 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000984def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000985 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000986 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000987 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000988def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
989 (ins i64mem:$src1, i64i32imm:$src2),
990 "cmp{q}\t{$src2, $src1|$src1, $src2}",
991 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
992 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000993} // Defs = [EFLAGS]
994
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000995// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000996// TODO: BTC, BTR, and BTS
997let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000998def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000999 "bt{q}\t{$src2, $src1|$src1, $src2}",
1000 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001001 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001002
1003// Unlike with the register+register form, the memory+register form of the
1004// bt instruction does not ignore the high bits of the index. From ISel's
1005// perspective, this is pretty bizarre. Disable these instructions for now.
1006//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1007// "bt{q}\t{$src2, $src1|$src1, $src2}",
1008// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1009// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001010
1011def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1012 "bt{q}\t{$src2, $src1|$src1, $src2}",
1013 [(X86bt GR64:$src1, i64immSExt8:$src2),
1014 (implicit EFLAGS)]>, TB;
1015// Note that these instructions don't need FastBTMem because that
1016// only applies when the other operand is in a register. When it's
1017// an immediate, bt is still fast.
1018def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1019 "bt{q}\t{$src2, $src1|$src1, $src2}",
1020 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1021 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001022} // Defs = [EFLAGS]
1023
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001024// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001025let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001026let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001027def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001028 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001029 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001031 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001032def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001033 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001034 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001036 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001037def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001038 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001039 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001041 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001042def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001043 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001044 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001046 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001048 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001049 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001051 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001053 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001054 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001056 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001057def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001058 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001059 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001061 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001062def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001063 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001064 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001066 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001068 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001069 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001071 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001073 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001074 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001076 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001077def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001078 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001079 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001081 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001083 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001084 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001086 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001088 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001089 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001091 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001093 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001094 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001096 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001097def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1098 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1099 "cmovo\t{$src2, $dst|$dst, $src2}",
1100 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1101 X86_COND_O, EFLAGS))]>, TB;
1102def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1103 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1104 "cmovno\t{$src2, $dst|$dst, $src2}",
1105 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1106 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001107} // isCommutable = 1
1108
1109def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1110 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1111 "cmovb\t{$src2, $dst|$dst, $src2}",
1112 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1113 X86_COND_B, EFLAGS))]>, TB;
1114def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1115 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1116 "cmovae\t{$src2, $dst|$dst, $src2}",
1117 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1118 X86_COND_AE, EFLAGS))]>, TB;
1119def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1120 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1121 "cmove\t{$src2, $dst|$dst, $src2}",
1122 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1123 X86_COND_E, EFLAGS))]>, TB;
1124def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1125 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1126 "cmovne\t{$src2, $dst|$dst, $src2}",
1127 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1128 X86_COND_NE, EFLAGS))]>, TB;
1129def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1130 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1131 "cmovbe\t{$src2, $dst|$dst, $src2}",
1132 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1133 X86_COND_BE, EFLAGS))]>, TB;
1134def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1135 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1136 "cmova\t{$src2, $dst|$dst, $src2}",
1137 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1138 X86_COND_A, EFLAGS))]>, TB;
1139def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1140 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1141 "cmovl\t{$src2, $dst|$dst, $src2}",
1142 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1143 X86_COND_L, EFLAGS))]>, TB;
1144def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1145 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1146 "cmovge\t{$src2, $dst|$dst, $src2}",
1147 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1148 X86_COND_GE, EFLAGS))]>, TB;
1149def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1150 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1151 "cmovle\t{$src2, $dst|$dst, $src2}",
1152 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1153 X86_COND_LE, EFLAGS))]>, TB;
1154def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1155 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1156 "cmovg\t{$src2, $dst|$dst, $src2}",
1157 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1158 X86_COND_G, EFLAGS))]>, TB;
1159def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1160 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1161 "cmovs\t{$src2, $dst|$dst, $src2}",
1162 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1163 X86_COND_S, EFLAGS))]>, TB;
1164def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1165 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1166 "cmovns\t{$src2, $dst|$dst, $src2}",
1167 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1168 X86_COND_NS, EFLAGS))]>, TB;
1169def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1170 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1171 "cmovp\t{$src2, $dst|$dst, $src2}",
1172 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1173 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001174def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001175 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001176 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001178 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001179def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1180 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1181 "cmovo\t{$src2, $dst|$dst, $src2}",
1182 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1183 X86_COND_O, EFLAGS))]>, TB;
1184def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1185 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1186 "cmovno\t{$src2, $dst|$dst, $src2}",
1187 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1188 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001189} // isTwoAddress
1190
1191//===----------------------------------------------------------------------===//
1192// Conversion Instructions...
1193//
1194
1195// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001196def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001197 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001198 [(set GR64:$dst,
1199 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001200def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001202 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1203 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001204def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001205 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001207def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001208 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001210def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001212 [(set GR64:$dst,
1213 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001214def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001215 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001216 [(set GR64:$dst,
1217 (int_x86_sse2_cvttsd2si64
1218 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001219
1220// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001221def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001222 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001223 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001224def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001225 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001226 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001227
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001228let isTwoAddress = 1 in {
1229def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001230 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001231 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001232 [(set VR128:$dst,
1233 (int_x86_sse2_cvtsi642sd VR128:$src1,
1234 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001236 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001237 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001238 [(set VR128:$dst,
1239 (int_x86_sse2_cvtsi642sd VR128:$src1,
1240 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001241} // isTwoAddress
1242
1243// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001244def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001245 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001246 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001247def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001250
1251let isTwoAddress = 1 in {
1252 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1253 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1254 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1255 [(set VR128:$dst,
1256 (int_x86_sse_cvtsi642ss VR128:$src1,
1257 GR64:$src2))]>;
1258 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1259 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1260 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1261 [(set VR128:$dst,
1262 (int_x86_sse_cvtsi642ss VR128:$src1,
1263 (loadi64 addr:$src2)))]>;
1264}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265
1266// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001267def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001269 [(set GR64:$dst,
1270 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001271def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001272 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001273 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1274 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001275def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001276 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001278def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001279 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001280 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001281def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001282 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001283 [(set GR64:$dst,
1284 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001285def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001286 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001287 [(set GR64:$dst,
1288 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1289
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001290//===----------------------------------------------------------------------===//
1291// Alias Instructions
1292//===----------------------------------------------------------------------===//
1293
Dan Gohman027cd112007-09-17 14:55:08 +00001294// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1295// equivalent due to implicit zero-extending, and it sometimes has a smaller
1296// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001297// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1298// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1299// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001300let Defs = [EFLAGS], AddedComplexity = 1,
1301 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001302def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1303 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1304 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305
1306// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001307let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001308def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001309 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310 [(set GR64:$dst, i64immZExt32:$src)]>;
1311
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001312//===----------------------------------------------------------------------===//
1313// Thread Local Storage Instructions
1314//===----------------------------------------------------------------------===//
1315
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001316// All calls clobber the non-callee saved registers. RSP is marked as
1317// a use to prevent stack-pointer assignments that appear immediately
1318// before calls from potentially appearing dead.
1319let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1320 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1321 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1322 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1323 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1324 Uses = [RSP] in
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001325def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001326 ".byte\t0x66; "
1327 "leaq\t${sym:mem}(%rip), %rdi; "
1328 ".word\t0x6666; "
1329 "rex64; "
1330 "call\t__tls_get_addr@PLT",
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001331 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1332 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001333
sampo9cc09a32009-01-26 01:24:32 +00001334let AddedComplexity = 5 in
1335def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1336 "movq\t%gs:$src, $dst",
1337 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1338
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001339let AddedComplexity = 5 in
1340def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1341 "movq\t%fs:$src, $dst",
1342 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1343
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001344//===----------------------------------------------------------------------===//
1345// Atomic Instructions
1346//===----------------------------------------------------------------------===//
1347
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001348let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001349def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001350 "lock\n\t"
1351 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001352 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1353}
1354
Dan Gohmana41a1c092008-08-06 15:52:50 +00001355let Constraints = "$val = $dst" in {
1356let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001357def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001358 "lock\n\t"
1359 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001360 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001361 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001362def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001363 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001364 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001365}
1366
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001367// Atomic exchange, and, or, xor
1368let Constraints = "$val = $dst", Defs = [EFLAGS],
1369 usesCustomDAGSchedInserter = 1 in {
1370def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001371 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001372 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001373def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001374 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001375 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001376def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001377 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001378 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001379def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001380 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001381 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001382def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001383 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001384 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001385def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001386 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001387 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001388def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001389 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001390 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001391def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001392 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001393 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001394}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001395
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001396//===----------------------------------------------------------------------===//
1397// Non-Instruction Patterns
1398//===----------------------------------------------------------------------===//
1399
Bill Wendlingfef06052008-09-16 21:48:12 +00001400// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001401def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1402 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1403def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1404 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1405def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1406 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1407def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1408 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1409
1410def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1411 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001412 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001413def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1414 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001415 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001416def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1417 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001418 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001419def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1420 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001421 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001422
1423// Calls
1424// Direct PC relative function call for small code model. 32-bit displacement
1425// sign extended to 64-bit.
1426def : Pat<(X86call (i64 tglobaladdr:$dst)),
1427 (CALL64pcrel32 tglobaladdr:$dst)>;
1428def : Pat<(X86call (i64 texternalsym:$dst)),
1429 (CALL64pcrel32 texternalsym:$dst)>;
1430
1431def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1432 (CALL64pcrel32 tglobaladdr:$dst)>;
1433def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1434 (CALL64pcrel32 texternalsym:$dst)>;
1435
1436def : Pat<(X86tailcall GR64:$dst),
1437 (CALL64r GR64:$dst)>;
1438
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001439
1440// tailcall stuff
1441def : Pat<(X86tailcall GR32:$dst),
1442 (TAILCALL)>;
1443def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1444 (TAILCALL)>;
1445def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1446 (TAILCALL)>;
1447
1448def : Pat<(X86tcret GR64:$dst, imm:$off),
1449 (TCRETURNri64 GR64:$dst, imm:$off)>;
1450
1451def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1452 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1453
1454def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1455 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1456
Dan Gohmanec596042007-09-17 14:35:24 +00001457// Comparisons.
1458
1459// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001460def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001461 (TEST64rr GR64:$src1, GR64:$src1)>;
1462
Dan Gohman0a3c5222009-01-07 01:00:24 +00001463// Conditional moves with folded loads with operands swapped and conditions
1464// inverted.
1465def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1466 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1467def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1468 (CMOVB64rm GR64:$src2, addr:$src1)>;
1469def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1470 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1471def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1472 (CMOVE64rm GR64:$src2, addr:$src1)>;
1473def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1474 (CMOVA64rm GR64:$src2, addr:$src1)>;
1475def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1476 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1477def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1478 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1479def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1480 (CMOVL64rm GR64:$src2, addr:$src1)>;
1481def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1482 (CMOVG64rm GR64:$src2, addr:$src1)>;
1483def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1484 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1485def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1486 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1487def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1488 (CMOVP64rm GR64:$src2, addr:$src1)>;
1489def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1490 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1491def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1492 (CMOVS64rm GR64:$src2, addr:$src1)>;
1493def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1494 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1495def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1496 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001497
Duncan Sands082524c2008-01-23 20:39:46 +00001498// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001499def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1500
1501// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001502// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1503// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1504// partial-register updates.
1505def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1506def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1507def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1508// For other extloads, use subregs, since the high contents of the register are
1509// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001510def : Pat<(extloadi64i32 addr:$src),
1511 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1512 x86_subreg_32bit)>;
1513def : Pat<(extloadi16i1 addr:$src),
1514 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1515 x86_subreg_8bit)>,
1516 Requires<[In64BitMode]>;
1517def : Pat<(extloadi16i8 addr:$src),
1518 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1519 x86_subreg_8bit)>,
1520 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001521
Dan Gohmandd612bb2008-08-20 21:27:32 +00001522// anyext
1523def : Pat<(i64 (anyext GR8:$src)),
1524 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1525def : Pat<(i64 (anyext GR16:$src)),
1526 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001527def : Pat<(i64 (anyext GR32:$src)),
1528 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001529def : Pat<(i16 (anyext GR8:$src)),
1530 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1531 Requires<[In64BitMode]>;
1532def : Pat<(i32 (anyext GR8:$src)),
1533 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1534 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535
1536//===----------------------------------------------------------------------===//
1537// Some peepholes
1538//===----------------------------------------------------------------------===//
1539
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001540// Odd encoding trick: -128 fits into an 8-bit immediate field while
1541// +128 doesn't, so in this special case use a sub instead of an add.
1542def : Pat<(add GR64:$src1, 128),
1543 (SUB64ri8 GR64:$src1, -128)>;
1544def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1545 (SUB64mi8 addr:$dst, -128)>;
1546
1547// The same trick applies for 32-bit immediate fields in 64-bit
1548// instructions.
1549def : Pat<(add GR64:$src1, 0x0000000080000000),
1550 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1551def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1552 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1553
Dan Gohman47a419d2008-08-07 02:54:50 +00001554// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001555def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001556 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001557// r & (2^16-1) ==> movz
1558def : Pat<(and GR64:$src, 0xffff),
1559 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1560// r & (2^8-1) ==> movz
1561def : Pat<(and GR64:$src, 0xff),
1562 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001563// r & (2^8-1) ==> movz
1564def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001565 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001566 Requires<[In64BitMode]>;
1567// r & (2^8-1) ==> movz
1568def : Pat<(and GR16:$src1, 0xff),
1569 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1570 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001571
Dan Gohmandd612bb2008-08-20 21:27:32 +00001572// sext_inreg patterns
1573def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001574 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001575def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001576 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001577def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001578 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001579def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001580 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001581 Requires<[In64BitMode]>;
1582def : Pat<(sext_inreg GR16:$src, i8),
1583 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1584 Requires<[In64BitMode]>;
1585
1586// trunc patterns
1587def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001588 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001589def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001590 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001591def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001592 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001593def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001594 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001595 Requires<[In64BitMode]>;
1596def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001597 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1598 Requires<[In64BitMode]>;
1599
1600// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001601// For now, be conservative on x86-64 and use an h-register extract only if the
1602// value is immediately zero-extended or stored, which are somewhat common
1603// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1604// from being allocated in the same instruction as the h register, as there's
1605// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001606
1607// h-register extract and zero-extend.
1608def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1609 (SUBREG_TO_REG
1610 (i64 0),
1611 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001612 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001613 x86_subreg_8bit_hi)),
1614 x86_subreg_32bit)>;
1615def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1616 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001617 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001618 x86_subreg_8bit_hi))>,
1619 Requires<[In64BitMode]>;
1620def : Pat<(srl_su GR16:$src, (i8 8)),
1621 (EXTRACT_SUBREG
1622 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001623 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001624 x86_subreg_8bit_hi)),
1625 x86_subreg_16bit)>,
1626 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001627def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1628 (MOVZX32_NOREXrr8
1629 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1630 x86_subreg_8bit_hi))>,
1631 Requires<[In64BitMode]>;
1632def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1633 (SUBREG_TO_REG
1634 (i64 0),
1635 (MOVZX32_NOREXrr8
1636 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1637 x86_subreg_8bit_hi)),
1638 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001639
1640// h-register extract and store.
1641def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1642 (MOV8mr_NOREX
1643 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001644 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001645 x86_subreg_8bit_hi))>;
1646def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1647 (MOV8mr_NOREX
1648 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001649 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001650 x86_subreg_8bit_hi))>,
1651 Requires<[In64BitMode]>;
1652def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1653 (MOV8mr_NOREX
1654 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001655 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001656 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001657 Requires<[In64BitMode]>;
1658
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001659// (shl x, 1) ==> (add x, x)
1660def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1661
Evan Cheng76a64c72008-08-30 02:03:58 +00001662// (shl x (and y, 63)) ==> (shl x, y)
1663def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1664 (SHL64rCL GR64:$src1)>;
1665def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1666 (SHL64mCL addr:$dst)>;
1667
1668def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1669 (SHR64rCL GR64:$src1)>;
1670def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1671 (SHR64mCL addr:$dst)>;
1672
1673def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1674 (SAR64rCL GR64:$src1)>;
1675def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1676 (SAR64mCL addr:$dst)>;
1677
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001678// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1679def : Pat<(or (srl GR64:$src1, CL:$amt),
1680 (shl GR64:$src2, (sub 64, CL:$amt))),
1681 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1682
1683def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1684 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1685 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1686
Dan Gohman921581d2008-10-17 01:23:35 +00001687def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1688 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1689 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1690
1691def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1692 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1693 addr:$dst),
1694 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1695
1696def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1697 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1698
1699def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1700 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1701 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1702
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001703// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1704def : Pat<(or (shl GR64:$src1, CL:$amt),
1705 (srl GR64:$src2, (sub 64, CL:$amt))),
1706 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1707
1708def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1709 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1710 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1711
Dan Gohman921581d2008-10-17 01:23:35 +00001712def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1713 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1714 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1715
1716def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1717 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1718 addr:$dst),
1719 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1720
1721def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1722 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1723
1724def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1725 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1726 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1727
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001728// X86 specific add which produces a flag.
1729def : Pat<(addc GR64:$src1, GR64:$src2),
1730 (ADD64rr GR64:$src1, GR64:$src2)>;
1731def : Pat<(addc GR64:$src1, (load addr:$src2)),
1732 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001733def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1734 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001735def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1736 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001737
1738def : Pat<(subc GR64:$src1, GR64:$src2),
1739 (SUB64rr GR64:$src1, GR64:$src2)>;
1740def : Pat<(subc GR64:$src1, (load addr:$src2)),
1741 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001742def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1743 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001744def : Pat<(subc GR64:$src1, imm:$src2),
1745 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001746
Bill Wendlingf5399032008-12-12 21:15:41 +00001747//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001748// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001749//===----------------------------------------------------------------------===//
1750
Dan Gohman99a12192009-03-04 19:44:21 +00001751// Register-Register Addition with EFLAGS result
1752def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001753 (implicit EFLAGS)),
1754 (ADD64rr GR64:$src1, GR64:$src2)>;
1755
Dan Gohman99a12192009-03-04 19:44:21 +00001756// Register-Integer Addition with EFLAGS result
1757def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001758 (implicit EFLAGS)),
1759 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001760def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001761 (implicit EFLAGS)),
1762 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001763
Dan Gohman99a12192009-03-04 19:44:21 +00001764// Register-Memory Addition with EFLAGS result
1765def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001766 (implicit EFLAGS)),
1767 (ADD64rm GR64:$src1, addr:$src2)>;
1768
Dan Gohman99a12192009-03-04 19:44:21 +00001769// Memory-Register Addition with EFLAGS result
1770def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001771 addr:$dst),
1772 (implicit EFLAGS)),
1773 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001774def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001775 addr:$dst),
1776 (implicit EFLAGS)),
1777 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001778def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001779 addr:$dst),
1780 (implicit EFLAGS)),
1781 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001782
Dan Gohman99a12192009-03-04 19:44:21 +00001783// Register-Register Subtraction with EFLAGS result
1784def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001785 (implicit EFLAGS)),
1786 (SUB64rr GR64:$src1, GR64:$src2)>;
1787
Dan Gohman99a12192009-03-04 19:44:21 +00001788// Register-Memory Subtraction with EFLAGS result
1789def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001790 (implicit EFLAGS)),
1791 (SUB64rm GR64:$src1, addr:$src2)>;
1792
Dan Gohman99a12192009-03-04 19:44:21 +00001793// Register-Integer Subtraction with EFLAGS result
1794def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001795 (implicit EFLAGS)),
1796 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001797def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001798 (implicit EFLAGS)),
1799 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001800
Dan Gohman99a12192009-03-04 19:44:21 +00001801// Memory-Register Subtraction with EFLAGS result
1802def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001803 addr:$dst),
1804 (implicit EFLAGS)),
1805 (SUB64mr addr:$dst, GR64:$src2)>;
1806
Dan Gohman99a12192009-03-04 19:44:21 +00001807// Memory-Integer Subtraction with EFLAGS result
1808def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001809 addr:$dst),
1810 (implicit EFLAGS)),
1811 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001812def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001813 addr:$dst),
1814 (implicit EFLAGS)),
1815 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001816
Dan Gohman99a12192009-03-04 19:44:21 +00001817// Register-Register Signed Integer Multiplication with EFLAGS result
1818def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001819 (implicit EFLAGS)),
1820 (IMUL64rr GR64:$src1, GR64:$src2)>;
1821
Dan Gohman99a12192009-03-04 19:44:21 +00001822// Register-Memory Signed Integer Multiplication with EFLAGS result
1823def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001824 (implicit EFLAGS)),
1825 (IMUL64rm GR64:$src1, addr:$src2)>;
1826
Dan Gohman99a12192009-03-04 19:44:21 +00001827// Register-Integer Signed Integer Multiplication with EFLAGS result
1828def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001829 (implicit EFLAGS)),
1830 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001831def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001832 (implicit EFLAGS)),
1833 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001834
Dan Gohman99a12192009-03-04 19:44:21 +00001835// Memory-Integer Signed Integer Multiplication with EFLAGS result
1836def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001837 (implicit EFLAGS)),
1838 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001839def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001840 (implicit EFLAGS)),
1841 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001842
Dan Gohman99a12192009-03-04 19:44:21 +00001843// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001844def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1845 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1846def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1847 (implicit EFLAGS)),
1848 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1849def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1850 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1851def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1852 (implicit EFLAGS)),
1853 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1854
1855def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1856 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1857def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1858 (implicit EFLAGS)),
1859 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1860def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1861 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1862def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1863 (implicit EFLAGS)),
1864 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1865
Dan Gohman99a12192009-03-04 19:44:21 +00001866def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1867 (INC64r GR64:$src)>;
1868def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1869 (implicit EFLAGS)),
1870 (INC64m addr:$dst)>;
1871def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1872 (DEC64r GR64:$src)>;
1873def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1874 (implicit EFLAGS)),
1875 (DEC64m addr:$dst)>;
1876
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001877//===----------------------------------------------------------------------===//
1878// X86-64 SSE Instructions
1879//===----------------------------------------------------------------------===//
1880
1881// Move instructions...
1882
Evan Chengb783fa32007-07-19 01:14:50 +00001883def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001884 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001885 [(set VR128:$dst,
1886 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001887def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001888 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1890 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001891
Evan Chengb783fa32007-07-19 01:14:50 +00001892def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001893 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001894 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001895def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001896 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001897 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1898
Evan Chengb783fa32007-07-19 01:14:50 +00001899def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001900 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001901 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001902def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001903 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001904 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001905
1906//===----------------------------------------------------------------------===//
1907// X86-64 SSE4.1 Instructions
1908//===----------------------------------------------------------------------===//
1909
Nate Begeman4294c1f2008-02-12 22:51:28 +00001910/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1911multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001912 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001913 (ins VR128:$src1, i32i8imm:$src2),
1914 !strconcat(OpcodeStr,
1915 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1916 [(set GR64:$dst,
1917 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001918 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001919 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1920 !strconcat(OpcodeStr,
1921 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1922 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1923 addr:$dst)]>, OpSize, REX_W;
1924}
1925
1926defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1927
1928let isTwoAddress = 1 in {
1929 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001930 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001931 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1932 !strconcat(OpcodeStr,
1933 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1934 [(set VR128:$dst,
1935 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1936 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001937 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001938 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1939 !strconcat(OpcodeStr,
1940 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1941 [(set VR128:$dst,
1942 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1943 imm:$src3)))]>, OpSize, REX_W;
1944 }
1945}
1946
1947defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;