blob: ce5a8a37032fac2a8d230c5c9a33e06c88e421a1 [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> {
26 let PrintMethod = "printi64mem";
27 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 Cheng0af5a042009-03-12 18:15:39 +0000116 def CALL64pcrel32 : I<0xE8, RawFrm,
117 (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
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000180let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000181def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000182let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000183def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000184
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000186 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000187 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
189
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000190let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000191def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000192 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 [(set GR64:$dst, lea64addr:$src)]>;
194
195let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000196def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000197 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199
Evan Cheng48679f42007-12-14 02:13:44 +0000200// Bit scan instructions.
201let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000202def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000203 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000204 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000205def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000206 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000207 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
208 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000209
Evan Cheng4e33de92007-12-14 18:49:43 +0000210def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000211 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000212 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000213def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000214 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000215 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
216 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000217} // Defs = [EFLAGS]
218
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000220let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000221def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000222 [(X86rep_movs i64)]>, REP;
223let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000224def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000225 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226
227//===----------------------------------------------------------------------===//
228// Move Instructions...
229//
230
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000231let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000232def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000233 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Evan Chengd2b9d302008-06-25 01:16:38 +0000235let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000236def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000237 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000239def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000240 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000242}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243
Dan Gohman5574cc72008-12-03 18:15:48 +0000244let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, (load addr:$src))]>;
248
Evan Chengb783fa32007-07-19 01:14:50 +0000249def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000250 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000252def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000253 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 [(store i64immSExt32:$src, addr:$dst)]>;
255
256// Sign/Zero extenders
257
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000264def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000265 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000267def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000268 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000270def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000271 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000273def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000274 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
276
Dan Gohman9203ab42008-07-30 18:09:17 +0000277// Use movzbl instead of movzbq when the destination is a register; it's
278// equivalent due to implicit zero-extending, and it has a smaller encoding.
279def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
280 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
281 [(set GR64:$dst, (zext GR8:$src))]>, TB;
282def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
283 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
284 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
285// Use movzwl instead of movzwq when the destination is a register; it's
286// equivalent due to implicit zero-extending, and it has a smaller encoding.
287def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
288 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
289 [(set GR64:$dst, (zext GR16:$src))]>, TB;
290def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
291 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293
Dan Gohman47a419d2008-08-07 02:54:50 +0000294// There's no movzlq instruction, but movl can be used for this purpose, using
295// implicit zero-extension. We need this because the seeming alternative for
296// implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
297// safe because both instructions could be optimized away in the
298// register-to-register case, leaving nothing behind to do the zero extension.
299def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
300 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
301 [(set GR64:$dst, (zext GR32:$src))]>;
302def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
303 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
304 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
305
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000306let neverHasSideEffects = 1 in {
307 let Defs = [RAX], Uses = [EAX] in
308 def CDQE : RI<0x98, RawFrm, (outs), (ins),
309 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000311 let Defs = [RAX,RDX], Uses = [RAX] in
312 def CQO : RI<0x99, RawFrm, (outs), (ins),
313 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
314}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315
316//===----------------------------------------------------------------------===//
317// Arithmetic Instructions...
318//
319
Evan Cheng55687072007-09-14 21:48:26 +0000320let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321let isTwoAddress = 1 in {
322let isConvertibleToThreeAddress = 1 in {
323let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000324// Register-Register Addition
325def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
326 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000327 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000328 (implicit EFLAGS)]>;
329
330// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000331def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
332 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000333 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
334 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000335def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
336 "add{q}\t{$src2, $dst|$dst, $src2}",
337 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
338 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339} // isConvertibleToThreeAddress
340
Bill Wendlingae034ed2008-12-12 00:56:36 +0000341// Register-Memory Addition
342def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
343 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000344 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000345 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346} // isTwoAddress
347
Bill Wendlingae034ed2008-12-12 00:56:36 +0000348// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000349def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000350 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000351 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
352 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000353def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000354 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000355 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
356 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000357def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
358 "add{q}\t{$src2, $dst|$dst, $src2}",
359 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
360 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361
Evan Cheng259471d2007-10-05 17:59:57 +0000362let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363let isTwoAddress = 1 in {
364let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000365def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000366 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000367 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368
Evan Chengb783fa32007-07-19 01:14:50 +0000369def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000370 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000371 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372
Evan Chengb783fa32007-07-19 01:14:50 +0000373def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000374 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000375 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000376def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
377 "adc{q}\t{$src2, $dst|$dst, $src2}",
378 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379} // isTwoAddress
380
Evan Chengb783fa32007-07-19 01:14:50 +0000381def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000382 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000383 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000384def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000385 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000386 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000387def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
388 "adc{q}\t{$src2, $dst|$dst, $src2}",
389 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000390} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391
392let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000393// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000394def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000395 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000396 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
397 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000398
399// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000400def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000401 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000402 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
403 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000404
405// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000406def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
407 (ins GR64:$src1, i64i8imm:$src2),
408 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000409 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
410 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000411def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
412 (ins GR64:$src1, i64i32imm:$src2),
413 "sub{q}\t{$src2, $dst|$dst, $src2}",
414 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
415 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416} // isTwoAddress
417
Bill Wendlingae034ed2008-12-12 00:56:36 +0000418// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000419def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000420 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000421 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
422 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000423
424// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000425def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000426 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000427 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000428 addr:$dst),
429 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000430def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
431 "sub{q}\t{$src2, $dst|$dst, $src2}",
432 [(store (sub (load addr:$dst), i64immSExt32:$src2),
433 addr:$dst),
434 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435
Evan Cheng259471d2007-10-05 17:59:57 +0000436let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000438def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000439 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000440 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
441
Evan Chengb783fa32007-07-19 01:14:50 +0000442def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
445
Evan Chengb783fa32007-07-19 01:14:50 +0000446def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000447 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000449def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
450 "sbb{q}\t{$src2, $dst|$dst, $src2}",
451 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452} // isTwoAddress
453
Evan Chengb783fa32007-07-19 01:14:50 +0000454def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000455 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000457def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000458 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000460def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
461 "sbb{q}\t{$src2, $dst|$dst, $src2}",
462 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000463} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000464} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465
466// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000467let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000468def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000469 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000470let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000471def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000472 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
474// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000475def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000476 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000477let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000478def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000479 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
480}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481
Evan Cheng55687072007-09-14 21:48:26 +0000482let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483let isTwoAddress = 1 in {
484let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000485// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000486def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
487 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000488 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000489 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
490 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491
Bill Wendlingf5399032008-12-12 21:15:41 +0000492// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000493def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
494 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000495 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000496 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
497 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498} // isTwoAddress
499
500// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000501
Bill Wendlingf5399032008-12-12 21:15:41 +0000502// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000504 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000506 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
507 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000508def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
509 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
510 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
511 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
512 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000513
Bill Wendlingf5399032008-12-12 21:15:41 +0000514// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000516 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000517 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000518 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000519 i64immSExt8:$src2)),
520 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000521def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
522 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
523 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
524 [(set GR64:$dst, (mul (load addr:$src1),
525 i64immSExt32:$src2)),
526 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000527} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
529// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000530let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000531def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000532 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000534def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000535 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000536let mayLoad = 1 in {
537def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
538 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000539def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000540 "idiv{q}\t$src", []>;
541}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000542}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543
544// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000545let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000547def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000548 [(set GR64:$dst, (ineg GR64:$src)),
549 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000550def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000551 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
552 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553
554let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000555def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000556 [(set GR64:$dst, (add GR64:$src, 1)),
557 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000558def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000559 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
560 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561
562let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000563def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000564 [(set GR64:$dst, (add GR64:$src, -1)),
565 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000566def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000567 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
568 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569
570// In 64-bit mode, single byte INC and DEC cannot be encoded.
571let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
572// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000573def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000574 [(set GR16:$dst, (add GR16:$src, 1)),
575 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000577def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000578 [(set GR32:$dst, (add GR32:$src, 1)),
579 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000581def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000582 [(set GR16:$dst, (add GR16:$src, -1)),
583 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000585def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000586 [(set GR32:$dst, (add GR32:$src, -1)),
587 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 Requires<[In64BitMode]>;
589} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000590
591// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
592// how to unfold them.
593let isTwoAddress = 0, CodeSize = 2 in {
594 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000595 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
596 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000597 OpSize, Requires<[In64BitMode]>;
598 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000599 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
600 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000601 Requires<[In64BitMode]>;
602 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000603 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
604 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000605 OpSize, Requires<[In64BitMode]>;
606 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000607 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
608 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000609 Requires<[In64BitMode]>;
610}
Evan Cheng55687072007-09-14 21:48:26 +0000611} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612
613
Evan Cheng55687072007-09-14 21:48:26 +0000614let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615// Shift instructions
616let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000617let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000618def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000619 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000620 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000621let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000622def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000623 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000625// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
626// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627} // isTwoAddress
628
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000629let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000630def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000631 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000632 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000633def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000634 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000636def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000637 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
639
640let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000641let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000642def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000643 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000644 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000645def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000646 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000648def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000649 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000650 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
651} // isTwoAddress
652
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000653let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000654def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000655 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000656 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000657def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000658 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000660def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000661 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
663
664let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000665let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000666def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000667 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000668 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000669def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000670 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000671 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
675} // isTwoAddress
676
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000677let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000678def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000680 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000681def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000682 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000683 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000684def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000685 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
687
688// Rotate instructions
689let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000690let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000691def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000692 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000693 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000694def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000695 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000696 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000697def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
700} // isTwoAddress
701
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000702let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000703def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000704 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000705 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000706def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000707 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000709def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000710 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000711 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
712
713let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000714let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000715def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000717 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000718def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000719 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000721def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000722 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000723 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
724} // isTwoAddress
725
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000726let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000727def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000729 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000730def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000731 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000732 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000733def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000734 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000735 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
736
737// Double shift instructions (generalizations of rotate)
738let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000739let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000741 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
742 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000743def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000744 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
745 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000746}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747
748let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
749def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000750 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000751 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
752 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
753 (i8 imm:$src3)))]>,
754 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000756 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000757 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
758 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
759 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 TB;
761} // isCommutable
762} // isTwoAddress
763
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000764let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000765def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000766 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
767 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
768 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000769def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000770 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
771 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
772 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000773}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000775 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000776 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
777 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
778 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 TB;
780def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000781 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000782 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
783 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
784 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000786} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000787
788//===----------------------------------------------------------------------===//
789// Logical Instructions...
790//
791
Evan Cheng5b51c242009-01-21 19:45:31 +0000792let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000793def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000795def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
797
Evan Cheng55687072007-09-14 21:48:26 +0000798let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799let isTwoAddress = 1 in {
800let isCommutable = 1 in
801def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000802 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000803 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000804 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
805 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000807 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000809 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
810 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000812 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000813 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000814 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
815 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000816def AND64ri32 : RIi32<0x81, MRM4r,
817 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
818 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000819 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
820 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821} // isTwoAddress
822
823def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000824 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000825 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000826 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
827 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000829 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000830 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000831 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
832 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000833def AND64mi32 : RIi32<0x81, MRM4m,
834 (outs), (ins i64mem:$dst, i64i32imm:$src),
835 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000836 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
837 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838
839let isTwoAddress = 1 in {
840let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000841def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000842 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000843 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
844 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000845def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000846 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000847 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
848 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000849def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000850 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000851 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
852 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000853def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
854 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000855 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
856 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857} // isTwoAddress
858
Evan Chengb783fa32007-07-19 01:14:50 +0000859def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000860 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000861 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
862 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000863def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000864 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000865 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
866 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000867def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
868 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000869 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
870 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000871
872let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000873let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000874def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000875 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000876 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
877 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000878def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000879 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000880 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
881 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000882def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
883 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000884 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
885 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000887 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000889 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
890 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891} // isTwoAddress
892
Evan Chengb783fa32007-07-19 01:14:50 +0000893def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000894 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000895 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
896 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000897def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000898 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000899 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
900 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000901def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
902 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000903 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
904 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000905} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906
907//===----------------------------------------------------------------------===//
908// Comparison Instructions...
909//
910
911// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000912let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000914def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000915 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000916 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
917 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000918def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000919 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000920 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
921 (implicit EFLAGS)]>;
922def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
923 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000924 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000925 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
926 (implicit EFLAGS)]>;
927def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
928 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000930 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
931 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000932
Evan Chengb783fa32007-07-19 01:14:50 +0000933def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000935 [(X86cmp GR64:$src1, GR64:$src2),
936 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000937def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000939 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
940 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000941def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000943 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
944 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000945def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
946 "cmp{q}\t{$src2, $src1|$src1, $src2}",
947 [(X86cmp GR64:$src1, i64immSExt8:$src2),
948 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000949def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000950 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000951 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000952 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000953def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000954 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000955 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000956 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000957def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
958 (ins i64mem:$src1, i64i32imm:$src2),
959 "cmp{q}\t{$src2, $src1|$src1, $src2}",
960 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
961 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000962} // Defs = [EFLAGS]
963
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000964// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000965// TODO: BTC, BTR, and BTS
966let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000967def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000968 "bt{q}\t{$src2, $src1|$src1, $src2}",
969 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +0000970 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +0000971
972// Unlike with the register+register form, the memory+register form of the
973// bt instruction does not ignore the high bits of the index. From ISel's
974// perspective, this is pretty bizarre. Disable these instructions for now.
975//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
976// "bt{q}\t{$src2, $src1|$src1, $src2}",
977// [(X86bt (loadi64 addr:$src1), GR64:$src2),
978// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +0000979
980def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
981 "bt{q}\t{$src2, $src1|$src1, $src2}",
982 [(X86bt GR64:$src1, i64immSExt8:$src2),
983 (implicit EFLAGS)]>, TB;
984// Note that these instructions don't need FastBTMem because that
985// only applies when the other operand is in a register. When it's
986// an immediate, bt is still fast.
987def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
988 "bt{q}\t{$src2, $src1|$src1, $src2}",
989 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
990 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000991} // Defs = [EFLAGS]
992
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000993// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +0000994let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +0000995let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000996def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000997 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000998 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000999 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001000 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001001def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001002 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001003 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001004 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001005 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001007 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001008 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001009 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001010 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001011def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001012 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001013 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001014 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001015 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001016def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001017 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001018 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001019 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001020 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001021def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001022 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001023 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001024 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001025 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, 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 "cmovl\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_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, 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 "cmovge\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_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, 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 "cmovle\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_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, 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 "cmovg\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_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, 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 "cmovs\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_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, 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 "cmovns\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_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, 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 "cmovp\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_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, 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 "cmovnp\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_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001066def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1067 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1068 "cmovo\t{$src2, $dst|$dst, $src2}",
1069 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1070 X86_COND_O, EFLAGS))]>, TB;
1071def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1072 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1073 "cmovno\t{$src2, $dst|$dst, $src2}",
1074 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1075 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001076} // isCommutable = 1
1077
1078def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1079 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1080 "cmovb\t{$src2, $dst|$dst, $src2}",
1081 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1082 X86_COND_B, EFLAGS))]>, TB;
1083def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1084 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1085 "cmovae\t{$src2, $dst|$dst, $src2}",
1086 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1087 X86_COND_AE, EFLAGS))]>, TB;
1088def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1089 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1090 "cmove\t{$src2, $dst|$dst, $src2}",
1091 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1092 X86_COND_E, EFLAGS))]>, TB;
1093def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1094 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1095 "cmovne\t{$src2, $dst|$dst, $src2}",
1096 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1097 X86_COND_NE, EFLAGS))]>, TB;
1098def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1099 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1100 "cmovbe\t{$src2, $dst|$dst, $src2}",
1101 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1102 X86_COND_BE, EFLAGS))]>, TB;
1103def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1104 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1105 "cmova\t{$src2, $dst|$dst, $src2}",
1106 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1107 X86_COND_A, EFLAGS))]>, TB;
1108def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1109 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1110 "cmovl\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1112 X86_COND_L, EFLAGS))]>, TB;
1113def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1114 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115 "cmovge\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1117 X86_COND_GE, EFLAGS))]>, TB;
1118def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1119 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1120 "cmovle\t{$src2, $dst|$dst, $src2}",
1121 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1122 X86_COND_LE, EFLAGS))]>, TB;
1123def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "cmovg\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1127 X86_COND_G, EFLAGS))]>, TB;
1128def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1129 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1130 "cmovs\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1132 X86_COND_S, EFLAGS))]>, TB;
1133def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1134 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1135 "cmovns\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1137 X86_COND_NS, EFLAGS))]>, TB;
1138def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1139 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1140 "cmovp\t{$src2, $dst|$dst, $src2}",
1141 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1142 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001144 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001145 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001147 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001148def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1149 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1150 "cmovo\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1152 X86_COND_O, EFLAGS))]>, TB;
1153def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1154 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1155 "cmovno\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1157 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001158} // isTwoAddress
1159
1160//===----------------------------------------------------------------------===//
1161// Conversion Instructions...
1162//
1163
1164// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001165def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001166 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001167 [(set GR64:$dst,
1168 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001169def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001170 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001171 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1172 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001173def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001174 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001175 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001176def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001177 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001178 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001179def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001180 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001181 [(set GR64:$dst,
1182 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001183def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001184 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001185 [(set GR64:$dst,
1186 (int_x86_sse2_cvttsd2si64
1187 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001188
1189// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001190def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001191 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001193def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001194 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001196
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197let isTwoAddress = 1 in {
1198def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001199 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001200 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001201 [(set VR128:$dst,
1202 (int_x86_sse2_cvtsi642sd VR128:$src1,
1203 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001204def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001205 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001206 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001207 [(set VR128:$dst,
1208 (int_x86_sse2_cvtsi642sd VR128:$src1,
1209 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210} // isTwoAddress
1211
1212// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001213def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001214 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001215 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001216def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001217 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001219
1220let isTwoAddress = 1 in {
1221 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1222 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1223 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1224 [(set VR128:$dst,
1225 (int_x86_sse_cvtsi642ss VR128:$src1,
1226 GR64:$src2))]>;
1227 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1228 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1229 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1230 [(set VR128:$dst,
1231 (int_x86_sse_cvtsi642ss VR128:$src1,
1232 (loadi64 addr:$src2)))]>;
1233}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234
1235// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001236def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001237 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001238 [(set GR64:$dst,
1239 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001240def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001241 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001242 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1243 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001244def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001245 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001246 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001247def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001250def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001251 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001252 [(set GR64:$dst,
1253 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001254def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001255 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001256 [(set GR64:$dst,
1257 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1258
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001259//===----------------------------------------------------------------------===//
1260// Alias Instructions
1261//===----------------------------------------------------------------------===//
1262
Dan Gohman027cd112007-09-17 14:55:08 +00001263// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1264// equivalent due to implicit zero-extending, and it sometimes has a smaller
1265// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1267// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1268// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001269let Defs = [EFLAGS], AddedComplexity = 1,
1270 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001271def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1272 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1273 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001274
1275// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001276let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001277def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001278 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279 [(set GR64:$dst, i64immZExt32:$src)]>;
1280
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001281//===----------------------------------------------------------------------===//
1282// Thread Local Storage Instructions
1283//===----------------------------------------------------------------------===//
1284
1285def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001286 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001287 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001288
sampo9cc09a32009-01-26 01:24:32 +00001289let AddedComplexity = 5 in
1290def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1291 "movq\t%gs:$src, $dst",
1292 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1293
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001294//===----------------------------------------------------------------------===//
1295// Atomic Instructions
1296//===----------------------------------------------------------------------===//
1297
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001298let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001299def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001300 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001301 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1302}
1303
Dan Gohmana41a1c092008-08-06 15:52:50 +00001304let Constraints = "$val = $dst" in {
1305let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001306def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001307 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001308 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001309 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001310def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001311 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001312 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001313}
1314
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001315// Atomic exchange, and, or, xor
1316let Constraints = "$val = $dst", Defs = [EFLAGS],
1317 usesCustomDAGSchedInserter = 1 in {
1318def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001319 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001320 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001321def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001322 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001323 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001324def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001325 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001326 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001327def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001328 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001329 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001330def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001331 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001332 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001333def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001334 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001335 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001336def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001337 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001338 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001339def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001340 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001341 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001342}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001343
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001344//===----------------------------------------------------------------------===//
1345// Non-Instruction Patterns
1346//===----------------------------------------------------------------------===//
1347
Bill Wendlingfef06052008-09-16 21:48:12 +00001348// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1350 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1351def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1352 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1353def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1354 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1355def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1356 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1357
1358def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1359 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001360 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001361def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1362 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001363 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1365 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001366 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1368 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001369 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001370
1371// Calls
1372// Direct PC relative function call for small code model. 32-bit displacement
1373// sign extended to 64-bit.
1374def : Pat<(X86call (i64 tglobaladdr:$dst)),
1375 (CALL64pcrel32 tglobaladdr:$dst)>;
1376def : Pat<(X86call (i64 texternalsym:$dst)),
1377 (CALL64pcrel32 texternalsym:$dst)>;
1378
1379def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1380 (CALL64pcrel32 tglobaladdr:$dst)>;
1381def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1382 (CALL64pcrel32 texternalsym:$dst)>;
1383
1384def : Pat<(X86tailcall GR64:$dst),
1385 (CALL64r GR64:$dst)>;
1386
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001387
1388// tailcall stuff
1389def : Pat<(X86tailcall GR32:$dst),
1390 (TAILCALL)>;
1391def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1392 (TAILCALL)>;
1393def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1394 (TAILCALL)>;
1395
1396def : Pat<(X86tcret GR64:$dst, imm:$off),
1397 (TCRETURNri64 GR64:$dst, imm:$off)>;
1398
1399def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1400 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1401
1402def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1403 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1404
Dan Gohmanec596042007-09-17 14:35:24 +00001405// Comparisons.
1406
1407// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001408def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001409 (TEST64rr GR64:$src1, GR64:$src1)>;
1410
Dan Gohman0a3c5222009-01-07 01:00:24 +00001411// Conditional moves with folded loads with operands swapped and conditions
1412// inverted.
1413def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1414 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1415def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1416 (CMOVB64rm GR64:$src2, addr:$src1)>;
1417def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1418 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1419def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1420 (CMOVE64rm GR64:$src2, addr:$src1)>;
1421def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1422 (CMOVA64rm GR64:$src2, addr:$src1)>;
1423def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1424 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1425def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1426 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1427def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1428 (CMOVL64rm GR64:$src2, addr:$src1)>;
1429def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1430 (CMOVG64rm GR64:$src2, addr:$src1)>;
1431def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1432 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1433def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1434 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1435def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1436 (CMOVP64rm GR64:$src2, addr:$src1)>;
1437def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1438 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1439def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1440 (CMOVS64rm GR64:$src2, addr:$src1)>;
1441def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1442 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1443def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1444 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001445
1446// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001447def : Pat<(i64 (zext GR32:$src)),
1448 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001449
Duncan Sands082524c2008-01-23 20:39:46 +00001450// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1452
1453// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001454// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1455// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1456// partial-register updates.
1457def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1458def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1459def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1460// For other extloads, use subregs, since the high contents of the register are
1461// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001462def : Pat<(extloadi64i32 addr:$src),
1463 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1464 x86_subreg_32bit)>;
1465def : Pat<(extloadi16i1 addr:$src),
1466 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1467 x86_subreg_8bit)>,
1468 Requires<[In64BitMode]>;
1469def : Pat<(extloadi16i8 addr:$src),
1470 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1471 x86_subreg_8bit)>,
1472 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001473
Dan Gohmandd612bb2008-08-20 21:27:32 +00001474// anyext
1475def : Pat<(i64 (anyext GR8:$src)),
1476 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1477def : Pat<(i64 (anyext GR16:$src)),
1478 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001479def : Pat<(i64 (anyext GR32:$src)),
1480 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001481def : Pat<(i16 (anyext GR8:$src)),
1482 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1483 Requires<[In64BitMode]>;
1484def : Pat<(i32 (anyext GR8:$src)),
1485 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1486 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001487
1488//===----------------------------------------------------------------------===//
1489// Some peepholes
1490//===----------------------------------------------------------------------===//
1491
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001492// Odd encoding trick: -128 fits into an 8-bit immediate field while
1493// +128 doesn't, so in this special case use a sub instead of an add.
1494def : Pat<(add GR64:$src1, 128),
1495 (SUB64ri8 GR64:$src1, -128)>;
1496def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1497 (SUB64mi8 addr:$dst, -128)>;
1498
1499// The same trick applies for 32-bit immediate fields in 64-bit
1500// instructions.
1501def : Pat<(add GR64:$src1, 0x0000000080000000),
1502 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1503def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1504 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1505
Dan Gohman47a419d2008-08-07 02:54:50 +00001506// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001507def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001508 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001509// r & (2^16-1) ==> movz
1510def : Pat<(and GR64:$src, 0xffff),
1511 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1512// r & (2^8-1) ==> movz
1513def : Pat<(and GR64:$src, 0xff),
1514 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001515// r & (2^8-1) ==> movz
1516def : Pat<(and GR32:$src1, 0xff),
1517 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1518 Requires<[In64BitMode]>;
1519// r & (2^8-1) ==> movz
1520def : Pat<(and GR16:$src1, 0xff),
1521 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1522 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001523
Dan Gohmandd612bb2008-08-20 21:27:32 +00001524// sext_inreg patterns
1525def : Pat<(sext_inreg GR64:$src, i32),
1526 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1527def : Pat<(sext_inreg GR64:$src, i16),
1528 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1529def : Pat<(sext_inreg GR64:$src, i8),
1530 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1531def : Pat<(sext_inreg GR32:$src, i8),
1532 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1533 Requires<[In64BitMode]>;
1534def : Pat<(sext_inreg GR16:$src, i8),
1535 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1536 Requires<[In64BitMode]>;
1537
1538// trunc patterns
1539def : Pat<(i32 (trunc GR64:$src)),
1540 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1541def : Pat<(i16 (trunc GR64:$src)),
1542 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1543def : Pat<(i8 (trunc GR64:$src)),
1544 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1545def : Pat<(i8 (trunc GR32:$src)),
1546 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1547 Requires<[In64BitMode]>;
1548def : Pat<(i8 (trunc GR16:$src)),
1549 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1550 Requires<[In64BitMode]>;
1551
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001552// (shl x, 1) ==> (add x, x)
1553def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1554
Evan Cheng76a64c72008-08-30 02:03:58 +00001555// (shl x (and y, 63)) ==> (shl x, y)
1556def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1557 (SHL64rCL GR64:$src1)>;
1558def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1559 (SHL64mCL addr:$dst)>;
1560
1561def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1562 (SHR64rCL GR64:$src1)>;
1563def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1564 (SHR64mCL addr:$dst)>;
1565
1566def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1567 (SAR64rCL GR64:$src1)>;
1568def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1569 (SAR64mCL addr:$dst)>;
1570
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001571// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1572def : Pat<(or (srl GR64:$src1, CL:$amt),
1573 (shl GR64:$src2, (sub 64, CL:$amt))),
1574 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1575
1576def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1577 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1578 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1579
Dan Gohman921581d2008-10-17 01:23:35 +00001580def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1581 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1582 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1583
1584def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1585 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1586 addr:$dst),
1587 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1588
1589def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1590 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1591
1592def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1593 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1594 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1595
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001596// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1597def : Pat<(or (shl GR64:$src1, CL:$amt),
1598 (srl GR64:$src2, (sub 64, CL:$amt))),
1599 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1600
1601def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1602 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1603 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1604
Dan Gohman921581d2008-10-17 01:23:35 +00001605def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1606 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1607 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1608
1609def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1610 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1611 addr:$dst),
1612 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1613
1614def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1615 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1616
1617def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1618 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1619 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1620
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001621// X86 specific add which produces a flag.
1622def : Pat<(addc GR64:$src1, GR64:$src2),
1623 (ADD64rr GR64:$src1, GR64:$src2)>;
1624def : Pat<(addc GR64:$src1, (load addr:$src2)),
1625 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001626def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1627 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001628def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1629 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001630
1631def : Pat<(subc GR64:$src1, GR64:$src2),
1632 (SUB64rr GR64:$src1, GR64:$src2)>;
1633def : Pat<(subc GR64:$src1, (load addr:$src2)),
1634 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001635def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1636 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001637def : Pat<(subc GR64:$src1, imm:$src2),
1638 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001639
Bill Wendlingf5399032008-12-12 21:15:41 +00001640//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001641// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001642//===----------------------------------------------------------------------===//
1643
Dan Gohman99a12192009-03-04 19:44:21 +00001644// Register-Register Addition with EFLAGS result
1645def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001646 (implicit EFLAGS)),
1647 (ADD64rr GR64:$src1, GR64:$src2)>;
1648
Dan Gohman99a12192009-03-04 19:44:21 +00001649// Register-Integer Addition with EFLAGS result
1650def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001651 (implicit EFLAGS)),
1652 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001653def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001654 (implicit EFLAGS)),
1655 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001656
Dan Gohman99a12192009-03-04 19:44:21 +00001657// Register-Memory Addition with EFLAGS result
1658def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001659 (implicit EFLAGS)),
1660 (ADD64rm GR64:$src1, addr:$src2)>;
1661
Dan Gohman99a12192009-03-04 19:44:21 +00001662// Memory-Register Addition with EFLAGS result
1663def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001664 addr:$dst),
1665 (implicit EFLAGS)),
1666 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001667def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001668 addr:$dst),
1669 (implicit EFLAGS)),
1670 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001671def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001672 addr:$dst),
1673 (implicit EFLAGS)),
1674 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001675
Dan Gohman99a12192009-03-04 19:44:21 +00001676// Register-Register Subtraction with EFLAGS result
1677def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001678 (implicit EFLAGS)),
1679 (SUB64rr GR64:$src1, GR64:$src2)>;
1680
Dan Gohman99a12192009-03-04 19:44:21 +00001681// Register-Memory Subtraction with EFLAGS result
1682def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001683 (implicit EFLAGS)),
1684 (SUB64rm GR64:$src1, addr:$src2)>;
1685
Dan Gohman99a12192009-03-04 19:44:21 +00001686// Register-Integer Subtraction with EFLAGS result
1687def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001688 (implicit EFLAGS)),
1689 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001690def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001691 (implicit EFLAGS)),
1692 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001693
Dan Gohman99a12192009-03-04 19:44:21 +00001694// Memory-Register Subtraction with EFLAGS result
1695def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001696 addr:$dst),
1697 (implicit EFLAGS)),
1698 (SUB64mr addr:$dst, GR64:$src2)>;
1699
Dan Gohman99a12192009-03-04 19:44:21 +00001700// Memory-Integer Subtraction with EFLAGS result
1701def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001702 addr:$dst),
1703 (implicit EFLAGS)),
1704 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001705def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001706 addr:$dst),
1707 (implicit EFLAGS)),
1708 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001709
Dan Gohman99a12192009-03-04 19:44:21 +00001710// Register-Register Signed Integer Multiplication with EFLAGS result
1711def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001712 (implicit EFLAGS)),
1713 (IMUL64rr GR64:$src1, GR64:$src2)>;
1714
Dan Gohman99a12192009-03-04 19:44:21 +00001715// Register-Memory Signed Integer Multiplication with EFLAGS result
1716def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001717 (implicit EFLAGS)),
1718 (IMUL64rm GR64:$src1, addr:$src2)>;
1719
Dan Gohman99a12192009-03-04 19:44:21 +00001720// Register-Integer Signed Integer Multiplication with EFLAGS result
1721def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001722 (implicit EFLAGS)),
1723 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001724def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001725 (implicit EFLAGS)),
1726 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001727
Dan Gohman99a12192009-03-04 19:44:21 +00001728// Memory-Integer Signed Integer Multiplication with EFLAGS result
1729def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001730 (implicit EFLAGS)),
1731 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001732def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001733 (implicit EFLAGS)),
1734 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001735
Dan Gohman99a12192009-03-04 19:44:21 +00001736// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001737def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1738 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1739def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1740 (implicit EFLAGS)),
1741 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1742def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1743 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1744def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1745 (implicit EFLAGS)),
1746 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1747
1748def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1749 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1750def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1751 (implicit EFLAGS)),
1752 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1753def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1754 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1755def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1756 (implicit EFLAGS)),
1757 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1758
Dan Gohman99a12192009-03-04 19:44:21 +00001759def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1760 (INC64r GR64:$src)>;
1761def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1762 (implicit EFLAGS)),
1763 (INC64m addr:$dst)>;
1764def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1765 (DEC64r GR64:$src)>;
1766def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1767 (implicit EFLAGS)),
1768 (DEC64m addr:$dst)>;
1769
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001770//===----------------------------------------------------------------------===//
1771// X86-64 SSE Instructions
1772//===----------------------------------------------------------------------===//
1773
1774// Move instructions...
1775
Evan Chengb783fa32007-07-19 01:14:50 +00001776def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001777 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778 [(set VR128:$dst,
1779 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001780def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001781 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001782 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1783 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001784
Evan Chengb783fa32007-07-19 01:14:50 +00001785def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001786 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001787 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001788def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001789 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001790 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1791
Evan Chengb783fa32007-07-19 01:14:50 +00001792def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001793 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001794 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001795def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001796 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001797 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001798
1799//===----------------------------------------------------------------------===//
1800// X86-64 SSE4.1 Instructions
1801//===----------------------------------------------------------------------===//
1802
Nate Begeman4294c1f2008-02-12 22:51:28 +00001803/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1804multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001805 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001806 (ins VR128:$src1, i32i8imm:$src2),
1807 !strconcat(OpcodeStr,
1808 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1809 [(set GR64:$dst,
1810 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001811 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001812 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1813 !strconcat(OpcodeStr,
1814 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1815 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1816 addr:$dst)]>, OpSize, REX_W;
1817}
1818
1819defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1820
1821let isTwoAddress = 1 in {
1822 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001823 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001824 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1825 !strconcat(OpcodeStr,
1826 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1827 [(set VR128:$dst,
1828 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1829 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001830 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001831 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1832 !strconcat(OpcodeStr,
1833 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1834 [(set VR128:$dst,
1835 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1836 imm:$src3)))]>, OpSize, REX_W;
1837 }
1838}
1839
1840defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;