blob: ee0f0f43e1a9a288a810da509d73c44937359364 [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";
32 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
33}
34
35//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000036// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037//
38def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Evan Chengc3495762009-03-30 21:36:47 +000039 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
40 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041
42//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000043// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044//
45
Dan Gohmand16fdc02008-12-19 18:25:21 +000046def i64immSExt8 : PatLeaf<(i64 imm), [{
47 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
48 // sign extended field.
49 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
50}]>;
51
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052def i64immSExt32 : PatLeaf<(i64 imm), [{
53 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immZExt32 : PatLeaf<(i64 imm), [{
59 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
60 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
67
68def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
72
73def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
77
78//===----------------------------------------------------------------------===//
79// Instruction list...
80//
81
Dan Gohman01c9f772008-10-01 18:28:06 +000082// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83// a stack adjustment and the codegen must know that they may modify the stack
84// pointer before prolog-epilog rewriting occurs.
85// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86// sub / add which can clobber EFLAGS.
87let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
89 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000090 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000091 Requires<[In64BitMode]>;
92def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
93 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000094 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000095 Requires<[In64BitMode]>;
96}
97
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098//===----------------------------------------------------------------------===//
99// Call Instructions...
100//
Evan Cheng37e7c752007-07-21 00:34:19 +0000101let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000102 // All calls clobber the non-callee saved registers. RSP is marked as
103 // a use to prevent stack-pointer assignments that appear immediately
104 // before calls from potentially appearing dead. Uses for argument
105 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000107 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000110 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
111 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000112
113 // NOTE: this pattern doesn't match "X86call imm", because we do not know
114 // that the offset between an arbitrary immediate and the call will fit in
115 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000116 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Evan Cheng0af5a042009-03-12 18:15:39 +0000117 (outs), (ins i64i32imm:$dst, variable_ops),
Chris Lattner79552392009-03-18 00:43:52 +0000118 "call\t${dst:call}", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000119 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000120 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000121 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000122 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000123 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 }
125
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000126
127
128let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000129def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
130 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000131 "#TC_RETURN $dst $offset",
132 []>;
133
134let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000135def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
136 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000137 "#TC_RETURN $dst $offset",
138 []>;
139
140
141let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000142 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
143 "jmp{q}\t{*}$dst # TAILCALL",
144 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000145
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000147let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000148 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000149 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000150 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 [(brind (loadi64 addr:$dst))]>;
152}
153
154//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000155// EH Pseudo Instructions
156//
157let isTerminator = 1, isReturn = 1, isBarrier = 1,
158 hasCtrlDep = 1 in {
159def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
160 "ret\t#eh_return, addr: $addr",
161 [(X86ehret GR64:$addr)]>;
162
163}
164
165//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166// Miscellaneous Instructions...
167//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000168let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000170 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000171let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
172let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000174 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000175let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000177 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
178}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179
Bill Wendling4c2638c2009-06-15 19:39:04 +0000180let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
181def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000182 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000183def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000184 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000185def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000186 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000187}
188
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000189let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000190def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000191let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000192def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000193
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000195 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000196 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
198
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000199let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000200def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000201 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000202 [(set GR64:$dst, lea64addr:$src)]>;
203
204let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000205def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000206 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208
Evan Cheng48679f42007-12-14 02:13:44 +0000209// Bit scan instructions.
210let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000211def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000212 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000213 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000214def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000215 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000216 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
217 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000218
Evan Cheng4e33de92007-12-14 18:49:43 +0000219def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000220 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000221 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000222def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000223 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000224 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
225 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000226} // Defs = [EFLAGS]
227
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000229let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000230def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000231 [(X86rep_movs i64)]>, REP;
232let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000233def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000234 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235
236//===----------------------------------------------------------------------===//
237// Move Instructions...
238//
239
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000240let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000241def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000242 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243
Evan Chengd2b9d302008-06-25 01:16:38 +0000244let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000245def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000248def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000249 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000250 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000251}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252
Dan Gohman5574cc72008-12-03 18:15:48 +0000253let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000254def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000255 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256 [(set GR64:$dst, (load addr:$src))]>;
257
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(store i64immSExt32:$src, addr:$dst)]>;
264
265// Sign/Zero extenders
266
Dan Gohmanedde1992009-04-13 15:13:28 +0000267// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
268// operand, which makes it a rare instruction with an 8-bit register
269// operand that can never access an h register. If support for h registers
270// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000271def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000272 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000274def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000275 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000277def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000278 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000280def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000281 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000283def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000284 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000286def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000287 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
289
Dan Gohman9203ab42008-07-30 18:09:17 +0000290// Use movzbl instead of movzbq when the destination is a register; it's
291// equivalent due to implicit zero-extending, and it has a smaller encoding.
292def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
293 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
294 [(set GR64:$dst, (zext GR8:$src))]>, TB;
295def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
296 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
297 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
298// Use movzwl instead of movzwq when the destination is a register; it's
299// equivalent due to implicit zero-extending, and it has a smaller encoding.
300def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
301 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
302 [(set GR64:$dst, (zext GR16:$src))]>, TB;
303def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
304 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
305 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306
Dan Gohman47a419d2008-08-07 02:54:50 +0000307// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000308// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
309// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
310// zero-extension, however this isn't possible when the 32-bit value is
311// defined by a truncate or is copied from something where the high bits aren't
312// necessarily all zero. In such cases, we fall back to these explicit zext
313// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000314def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
315 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
316 [(set GR64:$dst, (zext GR32:$src))]>;
317def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
318 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
319 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
320
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000321// Any instruction that defines a 32-bit result leaves the high half of the
322// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
323// be copying from a truncate, but any other 32-bit operation will zero-extend
324// up to 64 bits.
325def def32 : PatLeaf<(i32 GR32:$src), [{
326 return N->getOpcode() != ISD::TRUNCATE &&
327 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
328 N->getOpcode() != ISD::CopyFromReg;
329}]>;
330
331// In the case of a 32-bit def that is known to implicitly zero-extend,
332// we can use a SUBREG_TO_REG.
333def : Pat<(i64 (zext def32:$src)),
334 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
335
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000336let neverHasSideEffects = 1 in {
337 let Defs = [RAX], Uses = [EAX] in
338 def CDQE : RI<0x98, RawFrm, (outs), (ins),
339 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000341 let Defs = [RAX,RDX], Uses = [RAX] in
342 def CQO : RI<0x99, RawFrm, (outs), (ins),
343 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
344}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345
346//===----------------------------------------------------------------------===//
347// Arithmetic Instructions...
348//
349
Evan Cheng55687072007-09-14 21:48:26 +0000350let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351let isTwoAddress = 1 in {
352let isConvertibleToThreeAddress = 1 in {
353let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000354// Register-Register Addition
355def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
356 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000357 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000358 (implicit EFLAGS)]>;
359
360// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000361def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
362 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000363 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
364 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000365def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
366 "add{q}\t{$src2, $dst|$dst, $src2}",
367 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
368 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369} // isConvertibleToThreeAddress
370
Bill Wendlingae034ed2008-12-12 00:56:36 +0000371// Register-Memory Addition
372def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
373 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000374 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000375 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376} // isTwoAddress
377
Bill Wendlingae034ed2008-12-12 00:56:36 +0000378// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000379def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000380 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000381 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
382 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000383def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000384 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000385 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
386 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000387def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
388 "add{q}\t{$src2, $dst|$dst, $src2}",
389 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
390 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391
Evan Cheng259471d2007-10-05 17:59:57 +0000392let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393let isTwoAddress = 1 in {
394let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000395def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000396 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000397 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398
Dale Johannesen747fe522009-06-02 03:12:52 +0000399def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000400 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000401 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402
Dale Johannesen747fe522009-06-02 03:12:52 +0000403def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000404 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000405 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
406def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000407 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000408 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409} // isTwoAddress
410
Evan Chengb783fa32007-07-19 01:14:50 +0000411def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000412 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000413 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000414def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000415 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000416 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000417def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
418 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000419 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000420} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421
422let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000423// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000424def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000425 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000426 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
427 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000428
429// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000430def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000431 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000432 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
433 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000434
435// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000436def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
437 (ins GR64:$src1, i64i8imm:$src2),
438 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000439 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
440 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000441def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
442 (ins GR64:$src1, i64i32imm:$src2),
443 "sub{q}\t{$src2, $dst|$dst, $src2}",
444 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
445 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446} // isTwoAddress
447
Bill Wendlingae034ed2008-12-12 00:56:36 +0000448// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000449def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000450 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000451 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
452 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000453
454// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000455def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000457 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000458 addr:$dst),
459 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000460def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
461 "sub{q}\t{$src2, $dst|$dst, $src2}",
462 [(store (sub (load addr:$dst), i64immSExt32:$src2),
463 addr:$dst),
464 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465
Evan Cheng259471d2007-10-05 17:59:57 +0000466let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000468def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000469 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000470 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471
Dale Johannesen747fe522009-06-02 03:12:52 +0000472def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000473 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000474 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475
Dale Johannesen747fe522009-06-02 03:12:52 +0000476def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000477 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000478 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
479def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000480 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000481 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482} // isTwoAddress
483
Evan Chengb783fa32007-07-19 01:14:50 +0000484def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000485 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000486 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000487def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000488 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000489 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000490def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
491 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000492 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000493} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000494} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495
496// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000497let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000498def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000499 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000500let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000501def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000502 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503
504// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000505def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000506 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000507let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000508def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000509 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
510}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511
Evan Cheng55687072007-09-14 21:48:26 +0000512let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513let isTwoAddress = 1 in {
514let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000515// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000516def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
517 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000518 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000519 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
520 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521
Bill Wendlingf5399032008-12-12 21:15:41 +0000522// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000523def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
524 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000525 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000526 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
527 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528} // isTwoAddress
529
530// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000531
Bill Wendlingf5399032008-12-12 21:15:41 +0000532// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000534 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000535 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000536 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
537 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000538def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
539 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
540 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
541 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
542 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000543
Bill Wendlingf5399032008-12-12 21:15:41 +0000544// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000546 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000547 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000548 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000549 i64immSExt8:$src2)),
550 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000551def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
552 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
553 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
554 [(set GR64:$dst, (mul (load addr:$src1),
555 i64immSExt32:$src2)),
556 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000557} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558
559// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000560let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000561def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000562 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000564def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000565 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000566let mayLoad = 1 in {
567def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
568 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000569def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000570 "idiv{q}\t$src", []>;
571}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000572}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573
574// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000575let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000577def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000578 [(set GR64:$dst, (ineg GR64:$src)),
579 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000580def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000581 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
582 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583
584let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000585def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000586 [(set GR64:$dst, (add GR64:$src, 1)),
587 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000588def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000589 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
590 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591
592let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000593def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000594 [(set GR64:$dst, (add GR64:$src, -1)),
595 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000596def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000597 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
598 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000599
600// In 64-bit mode, single byte INC and DEC cannot be encoded.
601let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
602// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000603def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000604 [(set GR16:$dst, (add GR16:$src, 1)),
605 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000607def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000608 [(set GR32:$dst, (add GR32:$src, 1)),
609 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000611def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000612 [(set GR16:$dst, (add GR16:$src, -1)),
613 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000615def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000616 [(set GR32:$dst, (add GR32:$src, -1)),
617 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 Requires<[In64BitMode]>;
619} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000620
621// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
622// how to unfold them.
623let isTwoAddress = 0, CodeSize = 2 in {
624 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000625 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
626 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000627 OpSize, Requires<[In64BitMode]>;
628 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000629 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
630 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000631 Requires<[In64BitMode]>;
632 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000633 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
634 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000635 OpSize, Requires<[In64BitMode]>;
636 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000637 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
638 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000639 Requires<[In64BitMode]>;
640}
Evan Cheng55687072007-09-14 21:48:26 +0000641} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642
643
Evan Cheng55687072007-09-14 21:48:26 +0000644let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645// Shift instructions
646let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000647let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000648def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000649 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000650 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000651let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000652def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000653 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000655// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
656// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000657} // isTwoAddress
658
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000659let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000660def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000661 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000662 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000663def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000664 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000666def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000667 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
669
670let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000671let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000674 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000675def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000676 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000678def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
681} // isTwoAddress
682
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000683let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000684def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000685 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000686 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000687def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000688 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000690def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
693
694let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000695let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000698 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000699def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000700 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000702def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000703 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
705} // isTwoAddress
706
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000708def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000710 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000714def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000715 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
717
718// Rotate instructions
719let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000720let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000721def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000722 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000724def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000725 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000727def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
730} // isTwoAddress
731
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000732let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000733def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000734 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000735 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000736def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000737 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000739def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
742
743let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000745def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000747 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000751def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
754} // isTwoAddress
755
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000757def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000759 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000763def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000764 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000765 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
766
767// Double shift instructions (generalizations of rotate)
768let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000769let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000770def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000771 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
772 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000773def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000774 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
775 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000776}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777
778let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
779def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000780 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000781 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
782 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
783 (i8 imm:$src3)))]>,
784 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000786 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000787 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
788 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
789 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 TB;
791} // isCommutable
792} // isTwoAddress
793
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000794let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000795def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000796 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
797 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
798 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000799def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000800 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
801 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
802 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000804def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000805 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000806 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
807 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
808 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 TB;
810def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000811 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000812 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
813 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
814 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000815 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000816} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817
818//===----------------------------------------------------------------------===//
819// Logical Instructions...
820//
821
Evan Cheng5b51c242009-01-21 19:45:31 +0000822let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000823def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000825def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
827
Evan Cheng55687072007-09-14 21:48:26 +0000828let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829let isTwoAddress = 1 in {
830let isCommutable = 1 in
831def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000832 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000833 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000834 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
835 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000837 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000838 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000839 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
840 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000842 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000843 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000844 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
845 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000846def AND64ri32 : RIi32<0x81, MRM4r,
847 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
848 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000849 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
850 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851} // isTwoAddress
852
853def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000854 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000855 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000856 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
857 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000858def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000859 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000860 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000861 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
862 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000863def AND64mi32 : RIi32<0x81, MRM4m,
864 (outs), (ins i64mem:$dst, i64i32imm:$src),
865 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000866 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
867 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868
869let isTwoAddress = 1 in {
870let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000871def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000872 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000873 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
874 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000875def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000876 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000877 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
878 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000879def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000880 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000881 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
882 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000883def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
884 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000885 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
886 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000887} // isTwoAddress
888
Evan Chengb783fa32007-07-19 01:14:50 +0000889def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000890 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000891 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
892 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000893def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000894 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000895 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
896 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000897def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
898 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000899 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
900 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000901
902let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000903let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000904def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000906 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
907 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000908def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000909 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000910 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
911 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000912def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
913 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000914 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
915 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000916def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000917 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000919 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
920 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921} // isTwoAddress
922
Evan Chengb783fa32007-07-19 01:14:50 +0000923def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000924 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000925 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
926 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000927def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000929 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
930 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000931def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
932 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000933 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
934 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000935} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000936
937//===----------------------------------------------------------------------===//
938// Comparison Instructions...
939//
940
941// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000942let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000944def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000945 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000946 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
947 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000948def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000950 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
951 (implicit EFLAGS)]>;
952def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
953 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000955 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
956 (implicit EFLAGS)]>;
957def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
958 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000960 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
961 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962
Evan Chengb783fa32007-07-19 01:14:50 +0000963def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000965 [(X86cmp GR64:$src1, GR64:$src2),
966 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000967def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000969 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
970 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000971def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000972 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000973 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
974 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000975def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
977 [(X86cmp GR64:$src1, i64immSExt8:$src2),
978 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000979def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000981 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000982 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000983def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000984 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000985 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000986 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000987def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
988 (ins i64mem:$src1, i64i32imm:$src2),
989 "cmp{q}\t{$src2, $src1|$src1, $src2}",
990 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
991 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000992} // Defs = [EFLAGS]
993
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000994// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000995// TODO: BTC, BTR, and BTS
996let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000997def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000998 "bt{q}\t{$src2, $src1|$src1, $src2}",
999 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001000 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001001
1002// Unlike with the register+register form, the memory+register form of the
1003// bt instruction does not ignore the high bits of the index. From ISel's
1004// perspective, this is pretty bizarre. Disable these instructions for now.
1005//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1006// "bt{q}\t{$src2, $src1|$src1, $src2}",
1007// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1008// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001009
1010def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1011 "bt{q}\t{$src2, $src1|$src1, $src2}",
1012 [(X86bt GR64:$src1, i64immSExt8:$src2),
1013 (implicit EFLAGS)]>, TB;
1014// Note that these instructions don't need FastBTMem because that
1015// only applies when the other operand is in a register. When it's
1016// an immediate, bt is still fast.
1017def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1018 "bt{q}\t{$src2, $src1|$src1, $src2}",
1019 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1020 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001021} // Defs = [EFLAGS]
1022
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001024let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001025let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001027 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001028 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001029 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001030 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001032 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001033 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001035 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001037 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001038 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001040 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001042 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001043 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001045 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001047 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001048 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001050 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001052 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001053 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001055 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001057 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001058 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001059 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001060 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001062 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001065 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001067 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001068 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001070 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001072 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001073 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001075 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001077 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001078 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001080 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001082 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001083 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001085 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001087 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001088 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001090 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001092 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001093 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001095 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001096def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1097 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1098 "cmovo\t{$src2, $dst|$dst, $src2}",
1099 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1100 X86_COND_O, EFLAGS))]>, TB;
1101def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1102 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1103 "cmovno\t{$src2, $dst|$dst, $src2}",
1104 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1105 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001106} // isCommutable = 1
1107
1108def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1109 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1110 "cmovb\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1112 X86_COND_B, EFLAGS))]>, TB;
1113def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1114 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115 "cmovae\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1117 X86_COND_AE, EFLAGS))]>, TB;
1118def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1119 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1120 "cmove\t{$src2, $dst|$dst, $src2}",
1121 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1122 X86_COND_E, EFLAGS))]>, TB;
1123def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "cmovne\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1127 X86_COND_NE, EFLAGS))]>, TB;
1128def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1129 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1130 "cmovbe\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1132 X86_COND_BE, EFLAGS))]>, TB;
1133def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1134 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1135 "cmova\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1137 X86_COND_A, EFLAGS))]>, TB;
1138def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1139 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1140 "cmovl\t{$src2, $dst|$dst, $src2}",
1141 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1142 X86_COND_L, EFLAGS))]>, TB;
1143def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1144 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1145 "cmovge\t{$src2, $dst|$dst, $src2}",
1146 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1147 X86_COND_GE, EFLAGS))]>, TB;
1148def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1149 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1150 "cmovle\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1152 X86_COND_LE, EFLAGS))]>, TB;
1153def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1154 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1155 "cmovg\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1157 X86_COND_G, EFLAGS))]>, TB;
1158def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1159 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1160 "cmovs\t{$src2, $dst|$dst, $src2}",
1161 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1162 X86_COND_S, EFLAGS))]>, TB;
1163def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1164 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1165 "cmovns\t{$src2, $dst|$dst, $src2}",
1166 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1167 X86_COND_NS, EFLAGS))]>, TB;
1168def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1169 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1170 "cmovp\t{$src2, $dst|$dst, $src2}",
1171 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1172 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001173def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001174 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001175 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001176 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001177 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001178def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1179 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1180 "cmovo\t{$src2, $dst|$dst, $src2}",
1181 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1182 X86_COND_O, EFLAGS))]>, TB;
1183def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1184 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1185 "cmovno\t{$src2, $dst|$dst, $src2}",
1186 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1187 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001188} // isTwoAddress
1189
1190//===----------------------------------------------------------------------===//
1191// Conversion Instructions...
1192//
1193
1194// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001195def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001196 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001197 [(set GR64:$dst,
1198 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001199def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001200 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001201 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1202 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001203def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001204 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001206def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001207 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001208 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001209def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001210 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001211 [(set GR64:$dst,
1212 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001213def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001214 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001215 [(set GR64:$dst,
1216 (int_x86_sse2_cvttsd2si64
1217 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218
1219// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001220def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001221 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001223def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001224 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001226
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227let isTwoAddress = 1 in {
1228def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001229 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001230 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001231 [(set VR128:$dst,
1232 (int_x86_sse2_cvtsi642sd VR128:$src1,
1233 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001235 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001236 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001237 [(set VR128:$dst,
1238 (int_x86_sse2_cvtsi642sd VR128:$src1,
1239 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240} // isTwoAddress
1241
1242// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001243def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001244 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001245 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001246def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001247 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001248 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001249
1250let isTwoAddress = 1 in {
1251 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1252 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1253 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1254 [(set VR128:$dst,
1255 (int_x86_sse_cvtsi642ss VR128:$src1,
1256 GR64:$src2))]>;
1257 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1258 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1259 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1260 [(set VR128:$dst,
1261 (int_x86_sse_cvtsi642ss VR128:$src1,
1262 (loadi64 addr:$src2)))]>;
1263}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001264
1265// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001266def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001267 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001268 [(set GR64:$dst,
1269 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001270def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001272 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1273 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001274def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001275 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001276 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001277def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001278 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001280def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001281 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001282 [(set GR64:$dst,
1283 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001284def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001285 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001286 [(set GR64:$dst,
1287 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1288
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289//===----------------------------------------------------------------------===//
1290// Alias Instructions
1291//===----------------------------------------------------------------------===//
1292
Dan Gohman027cd112007-09-17 14:55:08 +00001293// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1294// equivalent due to implicit zero-extending, and it sometimes has a smaller
1295// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001296// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1297// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1298// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001299let Defs = [EFLAGS], AddedComplexity = 1,
1300 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001301def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1302 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1303 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001304
1305// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001306let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001307def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001308 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309 [(set GR64:$dst, i64immZExt32:$src)]>;
1310
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001311//===----------------------------------------------------------------------===//
1312// Thread Local Storage Instructions
1313//===----------------------------------------------------------------------===//
1314
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001315// All calls clobber the non-callee saved registers. RSP is marked as
1316// a use to prevent stack-pointer assignments that appear immediately
1317// before calls from potentially appearing dead.
1318let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1319 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1320 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1321 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1322 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1323 Uses = [RSP] in
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001324def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001325 ".byte\t0x66; "
1326 "leaq\t${sym:mem}(%rip), %rdi; "
1327 ".word\t0x6666; "
1328 "rex64; "
1329 "call\t__tls_get_addr@PLT",
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001330 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1331 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001332
sampo9cc09a32009-01-26 01:24:32 +00001333let AddedComplexity = 5 in
1334def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1335 "movq\t%gs:$src, $dst",
1336 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1337
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001338let AddedComplexity = 5 in
1339def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1340 "movq\t%fs:$src, $dst",
1341 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1342
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001343//===----------------------------------------------------------------------===//
1344// Atomic Instructions
1345//===----------------------------------------------------------------------===//
1346
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001347let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001348def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001349 "lock\n\t"
1350 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001351 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1352}
1353
Dan Gohmana41a1c092008-08-06 15:52:50 +00001354let Constraints = "$val = $dst" in {
1355let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001356def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001357 "lock\n\t"
1358 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001359 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001360 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001361def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001362 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001363 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001364}
1365
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001366// Atomic exchange, and, or, xor
1367let Constraints = "$val = $dst", Defs = [EFLAGS],
1368 usesCustomDAGSchedInserter = 1 in {
1369def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001370 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001371 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001372def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001373 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001374 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001375def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001376 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001377 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001378def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001379 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001380 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001381def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001382 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001383 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001384def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001385 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001386 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001387def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001388 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001389 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001390def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001391 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001392 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001393}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001394
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001395//===----------------------------------------------------------------------===//
1396// Non-Instruction Patterns
1397//===----------------------------------------------------------------------===//
1398
Bill Wendlingfef06052008-09-16 21:48:12 +00001399// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001400def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1401 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1402def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1403 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1404def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1405 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1406def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1407 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1408
1409def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1410 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001411 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001412def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1413 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001414 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001415def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1416 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001417 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001418def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1419 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001420 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001421
1422// Calls
1423// Direct PC relative function call for small code model. 32-bit displacement
1424// sign extended to 64-bit.
1425def : Pat<(X86call (i64 tglobaladdr:$dst)),
1426 (CALL64pcrel32 tglobaladdr:$dst)>;
1427def : Pat<(X86call (i64 texternalsym:$dst)),
1428 (CALL64pcrel32 texternalsym:$dst)>;
1429
1430def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1431 (CALL64pcrel32 tglobaladdr:$dst)>;
1432def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1433 (CALL64pcrel32 texternalsym:$dst)>;
1434
1435def : Pat<(X86tailcall GR64:$dst),
1436 (CALL64r GR64:$dst)>;
1437
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001438
1439// tailcall stuff
1440def : Pat<(X86tailcall GR32:$dst),
1441 (TAILCALL)>;
1442def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1443 (TAILCALL)>;
1444def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1445 (TAILCALL)>;
1446
1447def : Pat<(X86tcret GR64:$dst, imm:$off),
1448 (TCRETURNri64 GR64:$dst, imm:$off)>;
1449
1450def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1451 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1452
1453def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1454 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1455
Dan Gohmanec596042007-09-17 14:35:24 +00001456// Comparisons.
1457
1458// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001459def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001460 (TEST64rr GR64:$src1, GR64:$src1)>;
1461
Dan Gohman0a3c5222009-01-07 01:00:24 +00001462// Conditional moves with folded loads with operands swapped and conditions
1463// inverted.
1464def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1465 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1466def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1467 (CMOVB64rm GR64:$src2, addr:$src1)>;
1468def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1469 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1470def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1471 (CMOVE64rm GR64:$src2, addr:$src1)>;
1472def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1473 (CMOVA64rm GR64:$src2, addr:$src1)>;
1474def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1475 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1476def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1477 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1478def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1479 (CMOVL64rm GR64:$src2, addr:$src1)>;
1480def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1481 (CMOVG64rm GR64:$src2, addr:$src1)>;
1482def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1483 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1484def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1485 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1486def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1487 (CMOVP64rm GR64:$src2, addr:$src1)>;
1488def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1489 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1490def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1491 (CMOVS64rm GR64:$src2, addr:$src1)>;
1492def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1493 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1494def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1495 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001496
Duncan Sands082524c2008-01-23 20:39:46 +00001497// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001498def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1499
1500// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001501// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1502// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1503// partial-register updates.
1504def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1505def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1506def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1507// For other extloads, use subregs, since the high contents of the register are
1508// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001509def : Pat<(extloadi64i32 addr:$src),
1510 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1511 x86_subreg_32bit)>;
1512def : Pat<(extloadi16i1 addr:$src),
1513 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1514 x86_subreg_8bit)>,
1515 Requires<[In64BitMode]>;
1516def : Pat<(extloadi16i8 addr:$src),
1517 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1518 x86_subreg_8bit)>,
1519 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520
Dan Gohmandd612bb2008-08-20 21:27:32 +00001521// anyext
1522def : Pat<(i64 (anyext GR8:$src)),
1523 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1524def : Pat<(i64 (anyext GR16:$src)),
1525 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001526def : Pat<(i64 (anyext GR32:$src)),
1527 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001528def : Pat<(i16 (anyext GR8:$src)),
1529 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1530 Requires<[In64BitMode]>;
1531def : Pat<(i32 (anyext GR8:$src)),
1532 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1533 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001534
1535//===----------------------------------------------------------------------===//
1536// Some peepholes
1537//===----------------------------------------------------------------------===//
1538
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001539// Odd encoding trick: -128 fits into an 8-bit immediate field while
1540// +128 doesn't, so in this special case use a sub instead of an add.
1541def : Pat<(add GR64:$src1, 128),
1542 (SUB64ri8 GR64:$src1, -128)>;
1543def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1544 (SUB64mi8 addr:$dst, -128)>;
1545
1546// The same trick applies for 32-bit immediate fields in 64-bit
1547// instructions.
1548def : Pat<(add GR64:$src1, 0x0000000080000000),
1549 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1550def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1551 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1552
Dan Gohman47a419d2008-08-07 02:54:50 +00001553// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001554def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001555 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001556// r & (2^16-1) ==> movz
1557def : Pat<(and GR64:$src, 0xffff),
1558 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1559// r & (2^8-1) ==> movz
1560def : Pat<(and GR64:$src, 0xff),
1561 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001562// r & (2^8-1) ==> movz
1563def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001564 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001565 Requires<[In64BitMode]>;
1566// r & (2^8-1) ==> movz
1567def : Pat<(and GR16:$src1, 0xff),
1568 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1569 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001570
Dan Gohmandd612bb2008-08-20 21:27:32 +00001571// sext_inreg patterns
1572def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001573 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001574def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001575 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001576def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001577 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001578def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001579 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001580 Requires<[In64BitMode]>;
1581def : Pat<(sext_inreg GR16:$src, i8),
1582 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1583 Requires<[In64BitMode]>;
1584
1585// trunc patterns
1586def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001587 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001588def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001589 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001590def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001591 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001592def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001593 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001594 Requires<[In64BitMode]>;
1595def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001596 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1597 Requires<[In64BitMode]>;
1598
1599// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001600// For now, be conservative on x86-64 and use an h-register extract only if the
1601// value is immediately zero-extended or stored, which are somewhat common
1602// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1603// from being allocated in the same instruction as the h register, as there's
1604// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001605
1606// h-register extract and zero-extend.
1607def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1608 (SUBREG_TO_REG
1609 (i64 0),
1610 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001611 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001612 x86_subreg_8bit_hi)),
1613 x86_subreg_32bit)>;
1614def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1615 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001616 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001617 x86_subreg_8bit_hi))>,
1618 Requires<[In64BitMode]>;
1619def : Pat<(srl_su GR16:$src, (i8 8)),
1620 (EXTRACT_SUBREG
1621 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001622 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001623 x86_subreg_8bit_hi)),
1624 x86_subreg_16bit)>,
1625 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001626def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1627 (MOVZX32_NOREXrr8
1628 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1629 x86_subreg_8bit_hi))>,
1630 Requires<[In64BitMode]>;
1631def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1632 (SUBREG_TO_REG
1633 (i64 0),
1634 (MOVZX32_NOREXrr8
1635 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1636 x86_subreg_8bit_hi)),
1637 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001638
1639// h-register extract and store.
1640def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1641 (MOV8mr_NOREX
1642 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001643 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001644 x86_subreg_8bit_hi))>;
1645def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1646 (MOV8mr_NOREX
1647 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001648 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001649 x86_subreg_8bit_hi))>,
1650 Requires<[In64BitMode]>;
1651def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1652 (MOV8mr_NOREX
1653 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001654 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001655 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001656 Requires<[In64BitMode]>;
1657
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001658// (shl x, 1) ==> (add x, x)
1659def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1660
Evan Cheng76a64c72008-08-30 02:03:58 +00001661// (shl x (and y, 63)) ==> (shl x, y)
1662def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1663 (SHL64rCL GR64:$src1)>;
1664def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1665 (SHL64mCL addr:$dst)>;
1666
1667def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1668 (SHR64rCL GR64:$src1)>;
1669def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1670 (SHR64mCL addr:$dst)>;
1671
1672def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1673 (SAR64rCL GR64:$src1)>;
1674def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1675 (SAR64mCL addr:$dst)>;
1676
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001677// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1678def : Pat<(or (srl GR64:$src1, CL:$amt),
1679 (shl GR64:$src2, (sub 64, CL:$amt))),
1680 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1681
1682def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1683 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1684 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1685
Dan Gohman921581d2008-10-17 01:23:35 +00001686def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1687 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1688 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1689
1690def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1691 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1692 addr:$dst),
1693 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1694
1695def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1696 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1697
1698def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1699 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1700 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1701
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001702// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1703def : Pat<(or (shl GR64:$src1, CL:$amt),
1704 (srl GR64:$src2, (sub 64, CL:$amt))),
1705 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1706
1707def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1708 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1709 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1710
Dan Gohman921581d2008-10-17 01:23:35 +00001711def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1712 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1713 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1714
1715def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1716 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1717 addr:$dst),
1718 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1719
1720def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1721 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1722
1723def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1724 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1725 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1726
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001727// X86 specific add which produces a flag.
1728def : Pat<(addc GR64:$src1, GR64:$src2),
1729 (ADD64rr GR64:$src1, GR64:$src2)>;
1730def : Pat<(addc GR64:$src1, (load addr:$src2)),
1731 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001732def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1733 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001734def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1735 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001736
1737def : Pat<(subc GR64:$src1, GR64:$src2),
1738 (SUB64rr GR64:$src1, GR64:$src2)>;
1739def : Pat<(subc GR64:$src1, (load addr:$src2)),
1740 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001741def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1742 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001743def : Pat<(subc GR64:$src1, imm:$src2),
1744 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001745
Bill Wendlingf5399032008-12-12 21:15:41 +00001746//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001747// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001748//===----------------------------------------------------------------------===//
1749
Dan Gohman99a12192009-03-04 19:44:21 +00001750// Register-Register Addition with EFLAGS result
1751def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001752 (implicit EFLAGS)),
1753 (ADD64rr GR64:$src1, GR64:$src2)>;
1754
Dan Gohman99a12192009-03-04 19:44:21 +00001755// Register-Integer Addition with EFLAGS result
1756def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001757 (implicit EFLAGS)),
1758 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001759def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001760 (implicit EFLAGS)),
1761 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001762
Dan Gohman99a12192009-03-04 19:44:21 +00001763// Register-Memory Addition with EFLAGS result
1764def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001765 (implicit EFLAGS)),
1766 (ADD64rm GR64:$src1, addr:$src2)>;
1767
Dan Gohman99a12192009-03-04 19:44:21 +00001768// Memory-Register Addition with EFLAGS result
1769def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001770 addr:$dst),
1771 (implicit EFLAGS)),
1772 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001773def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001774 addr:$dst),
1775 (implicit EFLAGS)),
1776 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001777def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001778 addr:$dst),
1779 (implicit EFLAGS)),
1780 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001781
Dan Gohman99a12192009-03-04 19:44:21 +00001782// Register-Register Subtraction with EFLAGS result
1783def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001784 (implicit EFLAGS)),
1785 (SUB64rr GR64:$src1, GR64:$src2)>;
1786
Dan Gohman99a12192009-03-04 19:44:21 +00001787// Register-Memory Subtraction with EFLAGS result
1788def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001789 (implicit EFLAGS)),
1790 (SUB64rm GR64:$src1, addr:$src2)>;
1791
Dan Gohman99a12192009-03-04 19:44:21 +00001792// Register-Integer Subtraction with EFLAGS result
1793def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001794 (implicit EFLAGS)),
1795 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001796def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001797 (implicit EFLAGS)),
1798 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001799
Dan Gohman99a12192009-03-04 19:44:21 +00001800// Memory-Register Subtraction with EFLAGS result
1801def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001802 addr:$dst),
1803 (implicit EFLAGS)),
1804 (SUB64mr addr:$dst, GR64:$src2)>;
1805
Dan Gohman99a12192009-03-04 19:44:21 +00001806// Memory-Integer Subtraction with EFLAGS result
1807def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001808 addr:$dst),
1809 (implicit EFLAGS)),
1810 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001811def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001812 addr:$dst),
1813 (implicit EFLAGS)),
1814 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001815
Dan Gohman99a12192009-03-04 19:44:21 +00001816// Register-Register Signed Integer Multiplication with EFLAGS result
1817def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001818 (implicit EFLAGS)),
1819 (IMUL64rr GR64:$src1, GR64:$src2)>;
1820
Dan Gohman99a12192009-03-04 19:44:21 +00001821// Register-Memory Signed Integer Multiplication with EFLAGS result
1822def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001823 (implicit EFLAGS)),
1824 (IMUL64rm GR64:$src1, addr:$src2)>;
1825
Dan Gohman99a12192009-03-04 19:44:21 +00001826// Register-Integer Signed Integer Multiplication with EFLAGS result
1827def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001828 (implicit EFLAGS)),
1829 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001830def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001831 (implicit EFLAGS)),
1832 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001833
Dan Gohman99a12192009-03-04 19:44:21 +00001834// Memory-Integer Signed Integer Multiplication with EFLAGS result
1835def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001836 (implicit EFLAGS)),
1837 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001838def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001839 (implicit EFLAGS)),
1840 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001841
Dan Gohman99a12192009-03-04 19:44:21 +00001842// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001843def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1844 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1845def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1846 (implicit EFLAGS)),
1847 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1848def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1849 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1850def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1851 (implicit EFLAGS)),
1852 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1853
1854def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1855 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1856def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1857 (implicit EFLAGS)),
1858 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1859def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1860 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1861def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1862 (implicit EFLAGS)),
1863 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1864
Dan Gohman99a12192009-03-04 19:44:21 +00001865def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1866 (INC64r GR64:$src)>;
1867def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1868 (implicit EFLAGS)),
1869 (INC64m addr:$dst)>;
1870def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1871 (DEC64r GR64:$src)>;
1872def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1873 (implicit EFLAGS)),
1874 (DEC64m addr:$dst)>;
1875
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001876//===----------------------------------------------------------------------===//
1877// X86-64 SSE Instructions
1878//===----------------------------------------------------------------------===//
1879
1880// Move instructions...
1881
Evan Chengb783fa32007-07-19 01:14:50 +00001882def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001883 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001884 [(set VR128:$dst,
1885 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001886def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001887 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001888 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1889 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001890
Evan Chengb783fa32007-07-19 01:14:50 +00001891def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001892 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001893 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001894def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001895 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001896 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1897
Evan Chengb783fa32007-07-19 01:14:50 +00001898def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001899 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001900 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001901def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001902 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001903 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001904
1905//===----------------------------------------------------------------------===//
1906// X86-64 SSE4.1 Instructions
1907//===----------------------------------------------------------------------===//
1908
Nate Begeman4294c1f2008-02-12 22:51:28 +00001909/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1910multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001911 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001912 (ins VR128:$src1, i32i8imm:$src2),
1913 !strconcat(OpcodeStr,
1914 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1915 [(set GR64:$dst,
1916 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001917 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001918 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1919 !strconcat(OpcodeStr,
1920 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1921 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1922 addr:$dst)]>, OpSize, REX_W;
1923}
1924
1925defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1926
1927let isTwoAddress = 1 in {
1928 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001929 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001930 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1931 !strconcat(OpcodeStr,
1932 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1933 [(set VR128:$dst,
1934 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1935 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001936 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001937 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1938 !strconcat(OpcodeStr,
1939 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1940 [(set VR128:$dst,
1941 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1942 imm:$src3)))]>, OpSize, REX_W;
1943 }
1944}
1945
1946defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;