blob: 123062c6d05904b9acb66e8a8c352e0fc11dae35 [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",
39 [add, mul, shl, or, frameindex, X86Wrapper],
40 []>;
41
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 {
Evan Chengb783fa32007-07-19 01:14:50 +0000112 def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000113 "call\t${dst:call}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000114 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000115 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000116 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000117 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 }
119
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000120
121
122let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Arnold Schwaighofer6fd37ac2008-03-19 16:39:45 +0000123def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset, variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000124 "#TC_RETURN $dst $offset",
125 []>;
126
127let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Arnold Schwaighofer6fd37ac2008-03-19 16:39:45 +0000128def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset, variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000129 "#TC_RETURN $dst $offset",
130 []>;
131
132
133let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
134 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst # TAILCALL",
135 []>;
136
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000138let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000139 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000141 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142 [(brind (loadi64 addr:$dst))]>;
143}
144
145//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000146// EH Pseudo Instructions
147//
148let isTerminator = 1, isReturn = 1, isBarrier = 1,
149 hasCtrlDep = 1 in {
150def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
151 "ret\t#eh_return, addr: $addr",
152 [(X86ehret GR64:$addr)]>;
153
154}
155
156//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157// Miscellaneous Instructions...
158//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000159let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000161 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000162let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
163let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000165 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000166let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000168 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
169}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000171let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000172def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000173let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000174def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000175
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000177 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000178 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
180
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000181let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000182def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000183 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 [(set GR64:$dst, lea64addr:$src)]>;
185
186let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000187def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000188 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190
Evan Cheng48679f42007-12-14 02:13:44 +0000191// Bit scan instructions.
192let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000193def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000194 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000195 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000196def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000197 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000198 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
199 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000200
Evan Cheng4e33de92007-12-14 18:49:43 +0000201def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000202 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000203 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000204def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000205 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000206 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
207 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000208} // Defs = [EFLAGS]
209
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000211let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000212def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000213 [(X86rep_movs i64)]>, REP;
214let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000215def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000216 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
218//===----------------------------------------------------------------------===//
219// Move Instructions...
220//
221
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000222let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000223def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000224 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225
Evan Chengd2b9d302008-06-25 01:16:38 +0000226let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000227def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000228 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000230def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000231 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000233}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Dan Gohman5574cc72008-12-03 18:15:48 +0000235let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000236def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000237 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 [(set GR64:$dst, (load addr:$src))]>;
239
Evan Chengb783fa32007-07-19 01:14:50 +0000240def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000241 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000243def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000244 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 [(store i64immSExt32:$src, addr:$dst)]>;
246
247// Sign/Zero extenders
248
Evan Chengb783fa32007-07-19 01:14:50 +0000249def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000250 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000252def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000253 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000255def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000256 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000264def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000265 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
267
Dan Gohman9203ab42008-07-30 18:09:17 +0000268// Use movzbl instead of movzbq when the destination is a register; it's
269// equivalent due to implicit zero-extending, and it has a smaller encoding.
270def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
271 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
272 [(set GR64:$dst, (zext GR8:$src))]>, TB;
273def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
274 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
275 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
276// Use movzwl instead of movzwq when the destination is a register; it's
277// equivalent due to implicit zero-extending, and it has a smaller encoding.
278def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
279 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
280 [(set GR64:$dst, (zext GR16:$src))]>, TB;
281def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
282 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
283 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284
Dan Gohman47a419d2008-08-07 02:54:50 +0000285// There's no movzlq instruction, but movl can be used for this purpose, using
286// implicit zero-extension. We need this because the seeming alternative for
287// implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
288// safe because both instructions could be optimized away in the
289// register-to-register case, leaving nothing behind to do the zero extension.
290def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
291 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zext GR32:$src))]>;
293def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
294 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
296
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000297let neverHasSideEffects = 1 in {
298 let Defs = [RAX], Uses = [EAX] in
299 def CDQE : RI<0x98, RawFrm, (outs), (ins),
300 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000302 let Defs = [RAX,RDX], Uses = [RAX] in
303 def CQO : RI<0x99, RawFrm, (outs), (ins),
304 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
305}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306
307//===----------------------------------------------------------------------===//
308// Arithmetic Instructions...
309//
310
Evan Cheng55687072007-09-14 21:48:26 +0000311let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312let isTwoAddress = 1 in {
313let isConvertibleToThreeAddress = 1 in {
314let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000315// Register-Register Addition
316def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
317 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000318 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000319 (implicit EFLAGS)]>;
320
321// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000322def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
323 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000324 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
325 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000326def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
327 "add{q}\t{$src2, $dst|$dst, $src2}",
328 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
329 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330} // isConvertibleToThreeAddress
331
Bill Wendlingae034ed2008-12-12 00:56:36 +0000332// Register-Memory Addition
333def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
334 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000335 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000336 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337} // isTwoAddress
338
Bill Wendlingae034ed2008-12-12 00:56:36 +0000339// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000340def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000342 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
343 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000344def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000345 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000346 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
347 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000348def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
349 "add{q}\t{$src2, $dst|$dst, $src2}",
350 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
351 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
Evan Cheng259471d2007-10-05 17:59:57 +0000353let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354let isTwoAddress = 1 in {
355let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000356def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000357 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000358 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359
Evan Chengb783fa32007-07-19 01:14:50 +0000360def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000361 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000362 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363
Evan Chengb783fa32007-07-19 01:14:50 +0000364def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000365 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000366 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000367def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
368 "adc{q}\t{$src2, $dst|$dst, $src2}",
369 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370} // isTwoAddress
371
Evan Chengb783fa32007-07-19 01:14:50 +0000372def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000373 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000374 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000375def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000376 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000377 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000378def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
379 "adc{q}\t{$src2, $dst|$dst, $src2}",
380 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000381} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382
383let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000384// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000385def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000386 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000387 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
388 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000389
390// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000391def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000392 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000393 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
394 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000395
396// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000397def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
398 (ins GR64:$src1, i64i8imm:$src2),
399 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000400 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
401 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000402def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
403 (ins GR64:$src1, i64i32imm:$src2),
404 "sub{q}\t{$src2, $dst|$dst, $src2}",
405 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
406 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407} // isTwoAddress
408
Bill Wendlingae034ed2008-12-12 00:56:36 +0000409// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000410def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000411 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000412 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
413 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000414
415// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000416def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000417 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000418 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000419 addr:$dst),
420 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000421def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
422 "sub{q}\t{$src2, $dst|$dst, $src2}",
423 [(store (sub (load addr:$dst), i64immSExt32:$src2),
424 addr:$dst),
425 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426
Evan Cheng259471d2007-10-05 17:59:57 +0000427let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000429def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
432
Evan Chengb783fa32007-07-19 01:14:50 +0000433def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000434 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
436
Evan Chengb783fa32007-07-19 01:14:50 +0000437def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000438 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000440def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
441 "sbb{q}\t{$src2, $dst|$dst, $src2}",
442 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000443} // isTwoAddress
444
Evan Chengb783fa32007-07-19 01:14:50 +0000445def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000448def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000451def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
452 "sbb{q}\t{$src2, $dst|$dst, $src2}",
453 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000454} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000455} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456
457// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000458let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000459def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000460 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000461let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000462def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000463 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464
465// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000466def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000467 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000468let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000469def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000470 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
471}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
Evan Cheng55687072007-09-14 21:48:26 +0000473let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474let isTwoAddress = 1 in {
475let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000476// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000477def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
478 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000479 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000480 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
481 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482
Bill Wendlingf5399032008-12-12 21:15:41 +0000483// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000484def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
485 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000487 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
488 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489} // isTwoAddress
490
491// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000492
Bill Wendlingf5399032008-12-12 21:15:41 +0000493// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000495 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000496 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000497 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
498 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000499def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
500 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
501 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
502 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
503 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000504
Bill Wendlingf5399032008-12-12 21:15:41 +0000505// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000507 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000508 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000509 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000510 i64immSExt8:$src2)),
511 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000512def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
513 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
514 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
515 [(set GR64:$dst, (mul (load addr:$src1),
516 i64immSExt32:$src2)),
517 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000518} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
520// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000521let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000522def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000523 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000525def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000526 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000527let mayLoad = 1 in {
528def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
529 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000530def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000531 "idiv{q}\t$src", []>;
532}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000533}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
535// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000536let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000538def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539 [(set GR64:$dst, (ineg GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000540def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
542
543let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000544def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 [(set GR64:$dst, (add GR64:$src, 1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000546def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
548
549let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000550def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 [(set GR64:$dst, (add GR64:$src, -1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000552def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
554
555// In 64-bit mode, single byte INC and DEC cannot be encoded.
556let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
557// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000558def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 [(set GR16:$dst, (add GR16:$src, 1))]>,
560 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000561def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 [(set GR32:$dst, (add GR32:$src, 1))]>,
563 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000564def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565 [(set GR16:$dst, (add GR16:$src, -1))]>,
566 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000567def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 [(set GR32:$dst, (add GR32:$src, -1))]>,
569 Requires<[In64BitMode]>;
570} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000571
572// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
573// how to unfold them.
574let isTwoAddress = 0, CodeSize = 2 in {
575 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
576 [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
577 OpSize, Requires<[In64BitMode]>;
578 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
579 [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
580 Requires<[In64BitMode]>;
581 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
582 [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
583 OpSize, Requires<[In64BitMode]>;
584 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
585 [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
586 Requires<[In64BitMode]>;
587}
Evan Cheng55687072007-09-14 21:48:26 +0000588} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589
590
Evan Cheng55687072007-09-14 21:48:26 +0000591let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592// Shift instructions
593let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000594let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000595def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000596 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000597 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000598let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000599def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000602// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
603// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604} // isTwoAddress
605
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000606let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000607def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000608 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000609 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000610def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000611 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000613def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000614 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
616
617let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000618let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000619def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000620 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000621 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000622def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000623 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000625def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000626 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
628} // isTwoAddress
629
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000630let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000631def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000632 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000633 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000634def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000635 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000637def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000638 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
640
641let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000642let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000643def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000644 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000645 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000646def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000647 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000648 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000649def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000650 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
652} // isTwoAddress
653
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000654let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000655def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000656 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000657 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000658def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000659 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000661def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000662 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
664
665// Rotate instructions
666let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000667let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000668def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000669 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000670 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000671def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000672 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000674def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000675 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
677} // isTwoAddress
678
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000679let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000680def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000681 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000682 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000683def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000686def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000687 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
689
690let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000691let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000692def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000693 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000694 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000695def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000698def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000699 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
701} // isTwoAddress
702
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000703let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000704def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000705 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000706 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000707def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000710def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
713
714// Double shift instructions (generalizations of rotate)
715let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000716let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000717def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000718 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
719 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000721 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
722 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724
725let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
726def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000727 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000728 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
729 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
730 (i8 imm:$src3)))]>,
731 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000732def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000733 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000734 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
735 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
736 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 TB;
738} // isCommutable
739} // isTwoAddress
740
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000743 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
744 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
745 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000747 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
748 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
749 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000750}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000752 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000753 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
754 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
755 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 TB;
757def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000758 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000759 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
760 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
761 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000763} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764
765//===----------------------------------------------------------------------===//
766// Logical Instructions...
767//
768
Evan Cheng5b51c242009-01-21 19:45:31 +0000769let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000770def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000772def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
774
Evan Cheng55687072007-09-14 21:48:26 +0000775let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776let isTwoAddress = 1 in {
777let isCommutable = 1 in
778def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000779 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
782def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000783 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000787 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000788 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000789 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000790def AND64ri32 : RIi32<0x81, MRM4r,
791 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
792 "and{q}\t{$src2, $dst|$dst, $src2}",
793 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794} // isTwoAddress
795
796def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000797 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000798 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000801 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000804def AND64mi32 : RIi32<0x81, MRM4m,
805 (outs), (ins i64mem:$dst, i64i32imm:$src),
806 "and{q}\t{$src, $dst|$dst, $src}",
807 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808
809let isTwoAddress = 1 in {
810let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000811def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000812 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000814def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000815 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000817def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000818 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000820def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
821 "or{q}\t{$src2, $dst|$dst, $src2}",
822 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823} // isTwoAddress
824
Evan Chengb783fa32007-07-19 01:14:50 +0000825def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000826 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000828def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000829 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000831def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
832 "or{q}\t{$src, $dst|$dst, $src}",
833 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834
835let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000836let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000837def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000838 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000840def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000841 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000843def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
844 "xor{q}\t{$src2, $dst|$dst, $src2}",
845 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000847 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000848 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850} // isTwoAddress
851
Evan Chengb783fa32007-07-19 01:14:50 +0000852def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000853 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854 [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000855def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000856 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000858def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
859 "xor{q}\t{$src, $dst|$dst, $src}",
860 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000861} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862
863//===----------------------------------------------------------------------===//
864// Comparison Instructions...
865//
866
867// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000868let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000870def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000871 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000872 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
873 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000874def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000875 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000876 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
877 (implicit EFLAGS)]>;
878def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
879 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000880 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000881 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
882 (implicit EFLAGS)]>;
883def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
884 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000886 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
887 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888
Evan Chengb783fa32007-07-19 01:14:50 +0000889def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000890 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000891 [(X86cmp GR64:$src1, GR64:$src2),
892 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000893def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000894 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000895 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
896 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000897def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000898 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000899 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
900 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000901def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
902 "cmp{q}\t{$src2, $src1|$src1, $src2}",
903 [(X86cmp GR64:$src1, i64immSExt8:$src2),
904 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000905def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000906 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000907 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000908 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000909def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000910 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000911 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000912 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000913def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
914 (ins i64mem:$src1, i64i32imm:$src2),
915 "cmp{q}\t{$src2, $src1|$src1, $src2}",
916 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
917 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000918} // Defs = [EFLAGS]
919
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000920// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000921// TODO: BTC, BTR, and BTS
922let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000923def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000924 "bt{q}\t{$src2, $src1|$src1, $src2}",
925 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +0000926 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +0000927
928// Unlike with the register+register form, the memory+register form of the
929// bt instruction does not ignore the high bits of the index. From ISel's
930// perspective, this is pretty bizarre. Disable these instructions for now.
931//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
932// "bt{q}\t{$src2, $src1|$src1, $src2}",
933// [(X86bt (loadi64 addr:$src1), GR64:$src2),
934// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +0000935
936def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
937 "bt{q}\t{$src2, $src1|$src1, $src2}",
938 [(X86bt GR64:$src1, i64immSExt8:$src2),
939 (implicit EFLAGS)]>, TB;
940// Note that these instructions don't need FastBTMem because that
941// only applies when the other operand is in a register. When it's
942// an immediate, bt is still fast.
943def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
944 "bt{q}\t{$src2, $src1|$src1, $src2}",
945 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
946 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000947} // Defs = [EFLAGS]
948
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +0000950let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +0000951let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000953 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000956 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000958 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000961 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000963 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000966 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000968 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000969 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000970 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000971 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000973 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000976 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000978 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000979 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000981 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000982def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000983 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000984 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000986 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000987def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000988 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000991 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000992def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000993 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000994 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000996 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000997def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000998 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000999 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001001 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001002def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001003 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001005 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001006 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001008 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001009 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001010 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001011 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001012def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001013 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001014 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001015 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001016 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001017def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001018 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001019 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001021 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001022def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1023 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1024 "cmovo\t{$src2, $dst|$dst, $src2}",
1025 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1026 X86_COND_O, EFLAGS))]>, TB;
1027def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1028 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1029 "cmovno\t{$src2, $dst|$dst, $src2}",
1030 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1031 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001032} // isCommutable = 1
1033
1034def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1035 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1036 "cmovb\t{$src2, $dst|$dst, $src2}",
1037 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1038 X86_COND_B, EFLAGS))]>, TB;
1039def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1040 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1041 "cmovae\t{$src2, $dst|$dst, $src2}",
1042 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1043 X86_COND_AE, EFLAGS))]>, TB;
1044def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1045 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1046 "cmove\t{$src2, $dst|$dst, $src2}",
1047 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1048 X86_COND_E, EFLAGS))]>, TB;
1049def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1050 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1051 "cmovne\t{$src2, $dst|$dst, $src2}",
1052 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1053 X86_COND_NE, EFLAGS))]>, TB;
1054def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1055 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1056 "cmovbe\t{$src2, $dst|$dst, $src2}",
1057 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1058 X86_COND_BE, EFLAGS))]>, TB;
1059def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1060 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1061 "cmova\t{$src2, $dst|$dst, $src2}",
1062 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1063 X86_COND_A, EFLAGS))]>, TB;
1064def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1065 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1066 "cmovl\t{$src2, $dst|$dst, $src2}",
1067 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1068 X86_COND_L, EFLAGS))]>, TB;
1069def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1070 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1071 "cmovge\t{$src2, $dst|$dst, $src2}",
1072 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1073 X86_COND_GE, EFLAGS))]>, TB;
1074def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1075 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1076 "cmovle\t{$src2, $dst|$dst, $src2}",
1077 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1078 X86_COND_LE, EFLAGS))]>, TB;
1079def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1080 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1081 "cmovg\t{$src2, $dst|$dst, $src2}",
1082 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1083 X86_COND_G, EFLAGS))]>, TB;
1084def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1085 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1086 "cmovs\t{$src2, $dst|$dst, $src2}",
1087 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1088 X86_COND_S, EFLAGS))]>, TB;
1089def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1090 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1091 "cmovns\t{$src2, $dst|$dst, $src2}",
1092 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1093 X86_COND_NS, EFLAGS))]>, TB;
1094def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1095 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1096 "cmovp\t{$src2, $dst|$dst, $src2}",
1097 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1098 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001100 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001103 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001104def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1105 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1106 "cmovo\t{$src2, $dst|$dst, $src2}",
1107 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1108 X86_COND_O, EFLAGS))]>, TB;
1109def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1110 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1111 "cmovno\t{$src2, $dst|$dst, $src2}",
1112 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1113 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114} // isTwoAddress
1115
1116//===----------------------------------------------------------------------===//
1117// Conversion Instructions...
1118//
1119
1120// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001121def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001122 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001123 [(set GR64:$dst,
1124 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001125def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001127 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1128 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001129def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001130 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001132def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001133 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001135def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001136 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001137 [(set GR64:$dst,
1138 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001139def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001140 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001141 [(set GR64:$dst,
1142 (int_x86_sse2_cvttsd2si64
1143 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001144
1145// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001146def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001147 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001148 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001149def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001150 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001152
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153let isTwoAddress = 1 in {
1154def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001155 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001156 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001157 [(set VR128:$dst,
1158 (int_x86_sse2_cvtsi642sd VR128:$src1,
1159 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001160def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001161 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001163 [(set VR128:$dst,
1164 (int_x86_sse2_cvtsi642sd VR128:$src1,
1165 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166} // isTwoAddress
1167
1168// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001169def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001170 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001172def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001173 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001174 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001175
1176let isTwoAddress = 1 in {
1177 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1178 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1179 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1180 [(set VR128:$dst,
1181 (int_x86_sse_cvtsi642ss VR128:$src1,
1182 GR64:$src2))]>;
1183 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1184 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1185 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1186 [(set VR128:$dst,
1187 (int_x86_sse_cvtsi642ss VR128:$src1,
1188 (loadi64 addr:$src2)))]>;
1189}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190
1191// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001192def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001194 [(set GR64:$dst,
1195 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001196def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001197 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001198 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1199 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001200def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001202 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001203def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001204 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001206def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001207 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001208 [(set GR64:$dst,
1209 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001210def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001212 [(set GR64:$dst,
1213 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1214
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001215//===----------------------------------------------------------------------===//
1216// Alias Instructions
1217//===----------------------------------------------------------------------===//
1218
Dan Gohman027cd112007-09-17 14:55:08 +00001219// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1220// equivalent due to implicit zero-extending, and it sometimes has a smaller
1221// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1223// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1224// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001225let Defs = [EFLAGS], AddedComplexity = 1,
1226 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001227def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1228 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1229 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230
1231// Materialize i64 constant where top 32-bits are zero.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001232let AddedComplexity = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001233def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235 [(set GR64:$dst, i64immZExt32:$src)]>;
1236
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001237//===----------------------------------------------------------------------===//
1238// Thread Local Storage Instructions
1239//===----------------------------------------------------------------------===//
1240
1241def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001242 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001243 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001244
1245//===----------------------------------------------------------------------===//
1246// Atomic Instructions
1247//===----------------------------------------------------------------------===//
1248
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001249let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001250def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001251 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001252 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1253}
1254
Dan Gohmana41a1c092008-08-06 15:52:50 +00001255let Constraints = "$val = $dst" in {
1256let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001257def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001258 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001259 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001260 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001261def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001262 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001263 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001264}
1265
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001266// Atomic exchange, and, or, xor
1267let Constraints = "$val = $dst", Defs = [EFLAGS],
1268 usesCustomDAGSchedInserter = 1 in {
1269def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001270 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001271 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001272def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001273 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001274 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001275def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001276 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001277 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001278def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001279 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001280 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001281def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001282 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001283 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001284def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001285 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001286 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001287def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001288 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001289 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001290def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001291 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001292 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001293}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001294
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001295//===----------------------------------------------------------------------===//
1296// Non-Instruction Patterns
1297//===----------------------------------------------------------------------===//
1298
Bill Wendlingfef06052008-09-16 21:48:12 +00001299// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1301 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1302def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1303 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1304def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1305 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1306def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1307 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1308
1309def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1310 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001311 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1313 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001314 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001315def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1316 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001317 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001318def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1319 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001320 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001321
1322// Calls
1323// Direct PC relative function call for small code model. 32-bit displacement
1324// sign extended to 64-bit.
1325def : Pat<(X86call (i64 tglobaladdr:$dst)),
1326 (CALL64pcrel32 tglobaladdr:$dst)>;
1327def : Pat<(X86call (i64 texternalsym:$dst)),
1328 (CALL64pcrel32 texternalsym:$dst)>;
1329
1330def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1331 (CALL64pcrel32 tglobaladdr:$dst)>;
1332def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1333 (CALL64pcrel32 texternalsym:$dst)>;
1334
1335def : Pat<(X86tailcall GR64:$dst),
1336 (CALL64r GR64:$dst)>;
1337
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001338
1339// tailcall stuff
1340def : Pat<(X86tailcall GR32:$dst),
1341 (TAILCALL)>;
1342def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1343 (TAILCALL)>;
1344def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1345 (TAILCALL)>;
1346
1347def : Pat<(X86tcret GR64:$dst, imm:$off),
1348 (TCRETURNri64 GR64:$dst, imm:$off)>;
1349
1350def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1351 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1352
1353def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1354 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1355
Dan Gohmanec596042007-09-17 14:35:24 +00001356// Comparisons.
1357
1358// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001359def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001360 (TEST64rr GR64:$src1, GR64:$src1)>;
1361
Dan Gohman0a3c5222009-01-07 01:00:24 +00001362// Conditional moves with folded loads with operands swapped and conditions
1363// inverted.
1364def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1365 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1366def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1367 (CMOVB64rm GR64:$src2, addr:$src1)>;
1368def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1369 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1370def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1371 (CMOVE64rm GR64:$src2, addr:$src1)>;
1372def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1373 (CMOVA64rm GR64:$src2, addr:$src1)>;
1374def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1375 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1376def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1377 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1378def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1379 (CMOVL64rm GR64:$src2, addr:$src1)>;
1380def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1381 (CMOVG64rm GR64:$src2, addr:$src1)>;
1382def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1383 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1384def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1385 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1386def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1387 (CMOVP64rm GR64:$src2, addr:$src1)>;
1388def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1389 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1390def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1391 (CMOVS64rm GR64:$src2, addr:$src1)>;
1392def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1393 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1394def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1395 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001396
1397// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001398def : Pat<(i64 (zext GR32:$src)),
1399 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001400
Duncan Sands082524c2008-01-23 20:39:46 +00001401// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001402def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1403
1404// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001405// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1406// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1407// partial-register updates.
1408def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1409def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1410def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1411// For other extloads, use subregs, since the high contents of the register are
1412// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001413def : Pat<(extloadi64i32 addr:$src),
1414 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1415 x86_subreg_32bit)>;
1416def : Pat<(extloadi16i1 addr:$src),
1417 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1418 x86_subreg_8bit)>,
1419 Requires<[In64BitMode]>;
1420def : Pat<(extloadi16i8 addr:$src),
1421 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1422 x86_subreg_8bit)>,
1423 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001424
Dan Gohmandd612bb2008-08-20 21:27:32 +00001425// anyext
1426def : Pat<(i64 (anyext GR8:$src)),
1427 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1428def : Pat<(i64 (anyext GR16:$src)),
1429 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001430def : Pat<(i64 (anyext GR32:$src)),
1431 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001432def : Pat<(i16 (anyext GR8:$src)),
1433 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1434 Requires<[In64BitMode]>;
1435def : Pat<(i32 (anyext GR8:$src)),
1436 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1437 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001438
1439//===----------------------------------------------------------------------===//
1440// Some peepholes
1441//===----------------------------------------------------------------------===//
1442
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001443// Odd encoding trick: -128 fits into an 8-bit immediate field while
1444// +128 doesn't, so in this special case use a sub instead of an add.
1445def : Pat<(add GR64:$src1, 128),
1446 (SUB64ri8 GR64:$src1, -128)>;
1447def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1448 (SUB64mi8 addr:$dst, -128)>;
1449
1450// The same trick applies for 32-bit immediate fields in 64-bit
1451// instructions.
1452def : Pat<(add GR64:$src1, 0x0000000080000000),
1453 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1454def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1455 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1456
Dan Gohman47a419d2008-08-07 02:54:50 +00001457// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001458def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001459 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001460// r & (2^16-1) ==> movz
1461def : Pat<(and GR64:$src, 0xffff),
1462 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1463// r & (2^8-1) ==> movz
1464def : Pat<(and GR64:$src, 0xff),
1465 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001466// r & (2^8-1) ==> movz
1467def : Pat<(and GR32:$src1, 0xff),
1468 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1469 Requires<[In64BitMode]>;
1470// r & (2^8-1) ==> movz
1471def : Pat<(and GR16:$src1, 0xff),
1472 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1473 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001474
Dan Gohmandd612bb2008-08-20 21:27:32 +00001475// sext_inreg patterns
1476def : Pat<(sext_inreg GR64:$src, i32),
1477 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1478def : Pat<(sext_inreg GR64:$src, i16),
1479 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1480def : Pat<(sext_inreg GR64:$src, i8),
1481 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1482def : Pat<(sext_inreg GR32:$src, i8),
1483 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1484 Requires<[In64BitMode]>;
1485def : Pat<(sext_inreg GR16:$src, i8),
1486 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1487 Requires<[In64BitMode]>;
1488
1489// trunc patterns
1490def : Pat<(i32 (trunc GR64:$src)),
1491 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1492def : Pat<(i16 (trunc GR64:$src)),
1493 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1494def : Pat<(i8 (trunc GR64:$src)),
1495 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1496def : Pat<(i8 (trunc GR32:$src)),
1497 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1498 Requires<[In64BitMode]>;
1499def : Pat<(i8 (trunc GR16:$src)),
1500 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1501 Requires<[In64BitMode]>;
1502
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001503// (shl x, 1) ==> (add x, x)
1504def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1505
Evan Cheng76a64c72008-08-30 02:03:58 +00001506// (shl x (and y, 63)) ==> (shl x, y)
1507def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1508 (SHL64rCL GR64:$src1)>;
1509def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1510 (SHL64mCL addr:$dst)>;
1511
1512def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1513 (SHR64rCL GR64:$src1)>;
1514def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1515 (SHR64mCL addr:$dst)>;
1516
1517def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1518 (SAR64rCL GR64:$src1)>;
1519def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1520 (SAR64mCL addr:$dst)>;
1521
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1523def : Pat<(or (srl GR64:$src1, CL:$amt),
1524 (shl GR64:$src2, (sub 64, CL:$amt))),
1525 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1526
1527def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1528 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1529 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1530
Dan Gohman921581d2008-10-17 01:23:35 +00001531def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1532 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1533 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1534
1535def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1536 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1537 addr:$dst),
1538 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1539
1540def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1541 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1542
1543def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1544 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1545 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1546
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001547// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1548def : Pat<(or (shl GR64:$src1, CL:$amt),
1549 (srl GR64:$src2, (sub 64, CL:$amt))),
1550 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1551
1552def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1553 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1554 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1555
Dan Gohman921581d2008-10-17 01:23:35 +00001556def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1557 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1558 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1559
1560def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1561 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1562 addr:$dst),
1563 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1564
1565def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1566 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1567
1568def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1569 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1570 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1571
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001572// X86 specific add which produces a flag.
1573def : Pat<(addc GR64:$src1, GR64:$src2),
1574 (ADD64rr GR64:$src1, GR64:$src2)>;
1575def : Pat<(addc GR64:$src1, (load addr:$src2)),
1576 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001577def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1578 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001579def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1580 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001581
1582def : Pat<(subc GR64:$src1, GR64:$src2),
1583 (SUB64rr GR64:$src1, GR64:$src2)>;
1584def : Pat<(subc GR64:$src1, (load addr:$src2)),
1585 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001586def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1587 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001588def : Pat<(subc GR64:$src1, imm:$src2),
1589 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590
Bill Wendlingf5399032008-12-12 21:15:41 +00001591//===----------------------------------------------------------------------===//
1592// Overflow Patterns
1593//===----------------------------------------------------------------------===//
1594
1595// Register-Register Addition with Overflow
1596def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1597 (implicit EFLAGS)),
1598 (ADD64rr GR64:$src1, GR64:$src2)>;
1599
1600// Register-Integer Addition with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001601def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1602 (implicit EFLAGS)),
1603 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001604def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1605 (implicit EFLAGS)),
1606 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001607
1608// Register-Memory Addition with Overflow
1609def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1610 (implicit EFLAGS)),
1611 (ADD64rm GR64:$src1, addr:$src2)>;
1612
1613// Memory-Register Addition with Overflow
1614def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1615 addr:$dst),
1616 (implicit EFLAGS)),
1617 (ADD64mr addr:$dst, GR64:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001618def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1619 addr:$dst),
1620 (implicit EFLAGS)),
1621 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001622def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1623 addr:$dst),
1624 (implicit EFLAGS)),
1625 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001626
1627// Register-Register Subtraction with Overflow
1628def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1629 (implicit EFLAGS)),
1630 (SUB64rr GR64:$src1, GR64:$src2)>;
1631
1632// Register-Memory Subtraction with Overflow
1633def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1634 (implicit EFLAGS)),
1635 (SUB64rm GR64:$src1, addr:$src2)>;
1636
1637// Register-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001638def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1639 (implicit EFLAGS)),
1640 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001641def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1642 (implicit EFLAGS)),
1643 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001644
1645// Memory-Register Subtraction with Overflow
1646def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1647 addr:$dst),
1648 (implicit EFLAGS)),
1649 (SUB64mr addr:$dst, GR64:$src2)>;
1650
1651// Memory-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001652def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1653 addr:$dst),
1654 (implicit EFLAGS)),
1655 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001656def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1657 addr:$dst),
1658 (implicit EFLAGS)),
1659 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001660
1661// Register-Register Signed Integer Multiplication with Overflow
1662def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1663 (implicit EFLAGS)),
1664 (IMUL64rr GR64:$src1, GR64:$src2)>;
1665
1666// Register-Memory Signed Integer Multiplication with Overflow
1667def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1668 (implicit EFLAGS)),
1669 (IMUL64rm GR64:$src1, addr:$src2)>;
1670
1671// Register-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001672def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1673 (implicit EFLAGS)),
1674 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001675def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1676 (implicit EFLAGS)),
1677 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001678
1679// Memory-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001680def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1681 (implicit EFLAGS)),
1682 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001683def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1684 (implicit EFLAGS)),
1685 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686
1687//===----------------------------------------------------------------------===//
1688// X86-64 SSE Instructions
1689//===----------------------------------------------------------------------===//
1690
1691// Move instructions...
1692
Evan Chengb783fa32007-07-19 01:14:50 +00001693def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001694 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001695 [(set VR128:$dst,
1696 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001697def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001698 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001699 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1700 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001701
Evan Chengb783fa32007-07-19 01:14:50 +00001702def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001703 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001704 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001705def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001706 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001707 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1708
Evan Chengb783fa32007-07-19 01:14:50 +00001709def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001710 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001711 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001712def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001713 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001714 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001715
1716//===----------------------------------------------------------------------===//
1717// X86-64 SSE4.1 Instructions
1718//===----------------------------------------------------------------------===//
1719
Nate Begeman4294c1f2008-02-12 22:51:28 +00001720/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1721multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001722 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001723 (ins VR128:$src1, i32i8imm:$src2),
1724 !strconcat(OpcodeStr,
1725 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1726 [(set GR64:$dst,
1727 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001728 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001729 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1730 !strconcat(OpcodeStr,
1731 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1732 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1733 addr:$dst)]>, OpSize, REX_W;
1734}
1735
1736defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1737
1738let isTwoAddress = 1 in {
1739 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001740 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001741 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1742 !strconcat(OpcodeStr,
1743 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1744 [(set VR128:$dst,
1745 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1746 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001747 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001748 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1749 !strconcat(OpcodeStr,
1750 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1751 [(set VR128:$dst,
1752 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1753 imm:$src3)))]>, OpSize, REX_W;
1754 }
1755}
1756
1757defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;