blob: 49b3f3fd57756a78a750778ddd61d368da79e7bc [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
46def i64immSExt32 : PatLeaf<(i64 imm), [{
47 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
48 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000049 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050}]>;
51
52def i64immZExt32 : PatLeaf<(i64 imm), [{
53 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immSExt8 : PatLeaf<(i64 imm), [{
59 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (int64_t)N->getZExtValue() == (int8_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}",
318 [(set GR64:$dst, (add GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319
Bill Wendlingae034ed2008-12-12 00:56:36 +0000320// Register-Register Addition with Overflow
321def ADDOvf64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
322 "add{q}\t{$src2, $dst|$dst, $src2}",
323 [(set GR64:$dst, (X86add_ovf GR64:$src1, GR64:$src2)),
324 (implicit EFLAGS)]>;
325
326// Register-Integer Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000327def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000328 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000329 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2))]>;
330def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
331 "add{q}\t{$src2, $dst|$dst, $src2}",
332 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2))]>;
333
334// Register-Integer Addition with Overflow
335def ADDOvf64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
336 "add{q}\t{$src2, $dst|$dst, $src2}",
337 [(set GR64:$dst, (X86add_ovf GR64:$src1, i64immSExt32:$src2)),
338 (implicit EFLAGS)]>;
339def ADDOvf64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
340 "add{q}\t{$src2, $dst|$dst, $src2}",
341 [(set GR64:$dst, (X86add_ovf GR64:$src1, i64immSExt8:$src2)),
342 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343} // isConvertibleToThreeAddress
344
Bill Wendlingae034ed2008-12-12 00:56:36 +0000345// Register-Memory Addition
346def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
347 "add{q}\t{$src2, $dst|$dst, $src2}",
348 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2)))]>;
349
350// Register-Memory Addition with Overflow
351def ADDOvf64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
352 "add{q}\t{$src2, $dst|$dst, $src2}",
353 [(set GR64:$dst, (X86add_ovf GR64:$src1, (load addr:$src2))),
354 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355} // isTwoAddress
356
Bill Wendlingae034ed2008-12-12 00:56:36 +0000357// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000358def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000359 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000360 [(store (add (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000361def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000362 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000363 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000364def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000365 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000366 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
367
368// Memory-Register Addition with Overflow
369def ADDOvf64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
370 "add{q}\t{$src2, $dst|$dst, $src2}",
371 [(store (X86add_ovf (load addr:$dst), GR64:$src2),
372 addr:$dst),
373 (implicit EFLAGS)]>;
374def ADDOvf64mi32 : RIi32<0x81, MRM0m, (outs),(ins i64mem:$dst, i64i32imm:$src2),
375 "add{q}\t{$src2, $dst|$dst, $src2}",
376 [(store (X86add_ovf (load addr:$dst),
377 i64immSExt32:$src2),
378 addr:$dst),
379 (implicit EFLAGS)]>;
380def ADDOvf64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
381 "add{q}\t{$src2, $dst|$dst, $src2}",
382 [(store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
383 addr:$dst),
384 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
Evan Cheng259471d2007-10-05 17:59:57 +0000386let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387let isTwoAddress = 1 in {
388let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000389def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000390 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000391 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392
Evan Chengb783fa32007-07-19 01:14:50 +0000393def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000394 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000395 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396
Evan Chengb783fa32007-07-19 01:14:50 +0000397def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000398 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000399 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000400def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000401 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000402 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403} // isTwoAddress
404
Evan Chengb783fa32007-07-19 01:14:50 +0000405def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000406 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000407 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000408def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000410 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000411def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000412 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000413 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000414} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415
416let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000417// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000418def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000419 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000420 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421
Bill Wendlingae034ed2008-12-12 00:56:36 +0000422// Register-Register Subtraction with Overflow
423def SUBOvf64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
424 "sub{q}\t{$src2, $dst|$dst, $src2}",
425 [(set GR64:$dst, (X86sub_ovf GR64:$src1, GR64:$src2)),
426 (implicit EFLAGS)]>;
427
428// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000429def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000431 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432
Bill Wendlingae034ed2008-12-12 00:56:36 +0000433// Register-Memory Subtraction with Overflow
434def SUBOvf64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000435 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000436 [(set GR64:$dst, (X86sub_ovf GR64:$src1, (load addr:$src2))),
437 (implicit EFLAGS)]>;
438
439// Register-Integer Subtraction
440def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
441 (ins GR64:$src1, i64i32imm:$src2),
442 "sub{q}\t{$src2, $dst|$dst, $src2}",
443 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2))]>;
444def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
445 (ins GR64:$src1, i64i8imm:$src2),
446 "sub{q}\t{$src2, $dst|$dst, $src2}",
447 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2))]>;
448
449// Register-Integer Subtraction with Overflow
450def SUBOvf64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
451 (ins GR64:$src1, i64i32imm:$src2),
452 "sub{q}\t{$src2, $dst|$dst, $src2}",
453 [(set GR64:$dst, (X86sub_ovf GR64:$src1,
454 i64immSExt32:$src2)),
455 (implicit EFLAGS)]>;
456def SUBOvf64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
457 (ins GR64:$src1, i64i8imm:$src2),
458 "sub{q}\t{$src2, $dst|$dst, $src2}",
459 [(set GR64:$dst, (X86sub_ovf GR64:$src1,
460 i64immSExt8:$src2)),
461 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462} // isTwoAddress
463
Bill Wendlingae034ed2008-12-12 00:56:36 +0000464// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000465def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000466 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000467 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst)]>;
468
469// Memory-Register Subtraction with Overflow
470def SUBOvf64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
471 "sub{q}\t{$src2, $dst|$dst, $src2}",
472 [(store (X86sub_ovf (load addr:$dst), GR64:$src2),
473 addr:$dst),
474 (implicit EFLAGS)]>;
475
476// Memory-Integer Subtraction
477def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000479 [(store (sub (load addr:$dst), i64immSExt32:$src2),
480 addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000481def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000482 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000483 [(store (sub (load addr:$dst), i64immSExt8:$src2),
484 addr:$dst)]>;
485
486// Memory-Integer Subtraction with Overflow
487def SUBOvf64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst,i64i32imm:$src2),
488 "sub{q}\t{$src2, $dst|$dst, $src2}",
489 [(store (X86sub_ovf (load addr:$dst),
490 i64immSExt32:$src2), addr:$dst),
491 (implicit EFLAGS)]>;
492def SUBOvf64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
493 "sub{q}\t{$src2, $dst|$dst, $src2}",
494 [(store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
495 addr:$dst),
496 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497
Evan Cheng259471d2007-10-05 17:59:57 +0000498let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000500def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
503
Evan Chengb783fa32007-07-19 01:14:50 +0000504def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
507
Evan Chengb783fa32007-07-19 01:14:50 +0000508def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000509 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000510 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000511def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000512 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
514} // isTwoAddress
515
Evan Chengb783fa32007-07-19 01:14:50 +0000516def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000517 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000519def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000520 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000522def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000523 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000525} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000526} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527
528// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000529let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000530def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000531 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000532let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000533def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000534 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535
536// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000537def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000538 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000539let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000540def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000541 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
542}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543
Evan Cheng55687072007-09-14 21:48:26 +0000544let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545let isTwoAddress = 1 in {
546let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000547// Register-Register Integer Multiplication
548def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
549 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000550 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000551 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552
Bill Wendlingae034ed2008-12-12 00:56:36 +0000553// Register-Register Multiplication with Overflow
554def IMULOvf64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
555 (ins GR64:$src1, GR64:$src2),
556 "imul{q}\t{$src2, $dst|$dst, $src2}",
557 [(set GR64:$dst, (X86mul_ovf GR64:$src1, GR64:$src2)),
558 (implicit EFLAGS)]>, TB;
559
560// Register-Memory Integer Multiplication
561def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
562 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000563 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000564 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2)))]>, TB;
565
566// Register-Memory Integer Multiplication with Overflow
567def IMULOvf64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
568 (ins GR64:$src1, i64mem:$src2),
569 "imul{q}\t{$src2, $dst|$dst, $src2}",
570 [(set GR64:$dst, (X86mul_ovf GR64:$src1,
571 (load addr:$src2))),
572 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573} // isTwoAddress
574
575// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000576
577// Register-Integer Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000579 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000580 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000581 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000583 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000584 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000585 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2))]>;
586
587// Register-Integer Integer Multiplication with Overflow
588def IMULOvf64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
589 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
590 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
591 [(set GR64:$dst, (X86mul_ovf GR64:$src1,
592 i64immSExt32:$src2)),
593 (implicit EFLAGS)]>;
594def IMULOvf64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
595 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
596 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
597 [(set GR64:$dst, (X86mul_ovf GR64:$src1,
598 i64immSExt8:$src2)),
599 (implicit EFLAGS)]>;
600
601// Memory-Integer Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000603 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000604 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000605 [(set GR64:$dst, (mul (load addr:$src1),
606 i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000608 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000609 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000610 [(set GR64:$dst, (mul (load addr:$src1),
611 i64immSExt8:$src2))]>;
612
613// Memory-Integer Integer Multiplication with Overflow
614def IMULOvf64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
615 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
616 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
617 [(set GR64:$dst, (X86mul_ovf (load addr:$src1),
618 i64immSExt32:$src2)),
619 (implicit EFLAGS)]>;
620def IMULOvf64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
621 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
622 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
623 [(set GR64:$dst, (X86mul_ovf (load addr:$src1),
624 i64immSExt8:$src2)),
625 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000626} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627
628// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000629let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000630def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000631 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000633def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000634 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000635let mayLoad = 1 in {
636def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
637 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000638def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000639 "idiv{q}\t$src", []>;
640}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000641}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642
643// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000644let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000646def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 [(set GR64:$dst, (ineg GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000648def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
650
651let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000652def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 [(set GR64:$dst, (add GR64:$src, 1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000654def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
656
657let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000658def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659 [(set GR64:$dst, (add GR64:$src, -1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000660def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
662
663// In 64-bit mode, single byte INC and DEC cannot be encoded.
664let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
665// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000666def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 [(set GR16:$dst, (add GR16:$src, 1))]>,
668 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000669def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670 [(set GR32:$dst, (add GR32:$src, 1))]>,
671 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000672def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 [(set GR16:$dst, (add GR16:$src, -1))]>,
674 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000675def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 [(set GR32:$dst, (add GR32:$src, -1))]>,
677 Requires<[In64BitMode]>;
678} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000679
680// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
681// how to unfold them.
682let isTwoAddress = 0, CodeSize = 2 in {
683 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
684 [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
685 OpSize, Requires<[In64BitMode]>;
686 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
687 [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
688 Requires<[In64BitMode]>;
689 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
690 [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
691 OpSize, Requires<[In64BitMode]>;
692 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
693 [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
694 Requires<[In64BitMode]>;
695}
Evan Cheng55687072007-09-14 21:48:26 +0000696} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697
698
Evan Cheng55687072007-09-14 21:48:26 +0000699let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700// Shift instructions
701let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000702let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000703def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000704 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000705 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000706let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000707def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000710// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
711// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712} // isTwoAddress
713
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000714let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000715def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000717 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000718def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000719 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000721def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000722 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000723 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
724
725let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000726let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000727def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000729 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000730def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000731 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000732 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000733def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000734 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000735 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
736} // isTwoAddress
737
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000738let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000739def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000743 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000745def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
748
749let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000750let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000751def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000753 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000754def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000757def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
760} // isTwoAddress
761
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000762let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000763def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000764 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000765 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000766def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000769def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
772
773// Rotate instructions
774let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000775let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000776def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000777 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000778 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000779def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000782def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000783 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
785} // isTwoAddress
786
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000787let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000788def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000789 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000790 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000791def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000792 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000794def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000795 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
797
798let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000799let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000800def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000801 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000802 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000803def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000804 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000805 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000806def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000807 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
809} // isTwoAddress
810
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000811let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000812def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000813 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000814 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000815def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000816 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000818def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000819 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000820 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
821
822// Double shift instructions (generalizations of rotate)
823let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000824let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000825def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000826 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
827 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000828def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000829 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
830 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000831}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832
833let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
834def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000835 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000836 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
837 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
838 (i8 imm:$src3)))]>,
839 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000841 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000842 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
843 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
844 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 TB;
846} // isCommutable
847} // isTwoAddress
848
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000849let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000850def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000851 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
852 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
853 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000854def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000855 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
856 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
857 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000858}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000860 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000861 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
862 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
863 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864 TB;
865def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000866 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000867 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
868 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
869 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000871} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000872
873//===----------------------------------------------------------------------===//
874// Logical Instructions...
875//
876
877let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000878def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000880def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
882
Evan Cheng55687072007-09-14 21:48:26 +0000883let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884let isTwoAddress = 1 in {
885let isCommutable = 1 in
886def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000887 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
890def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000891 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000892 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000893 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
894def AND64ri32 : RIi32<0x81, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000895 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000896 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
898def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000899 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000900 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000901 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
902} // isTwoAddress
903
904def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000905 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000906 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000907 [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
908def AND64mi32 : RIi32<0x81, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000909 (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000910 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000911 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
912def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000913 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000914 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
916
917let isTwoAddress = 1 in {
918let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000919def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000920 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000922def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000923 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000925def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000926 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000927 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000928def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
931} // isTwoAddress
932
Evan Chengb783fa32007-07-19 01:14:50 +0000933def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000934 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000935 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000936def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000939def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
942
943let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000944let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000945def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000947 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000948def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000950 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
951def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000952 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000953 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000955def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000956 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
958} // isTwoAddress
959
Evan Chengb783fa32007-07-19 01:14:50 +0000960def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962 [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000963def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000966def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000967 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000969} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000970
971//===----------------------------------------------------------------------===//
972// Comparison Instructions...
973//
974
975// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000976let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000978def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000979 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000980 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
981 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000982def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000983 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000984 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
985 (implicit EFLAGS)]>;
986def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
987 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000988 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000989 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
990 (implicit EFLAGS)]>;
991def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
992 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000993 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000994 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
995 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000996
Evan Chengb783fa32007-07-19 01:14:50 +0000997def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000998 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000999 [(X86cmp GR64:$src1, GR64:$src2),
1000 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001001def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001002 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001003 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1004 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001005def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001006 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001007 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1008 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001009def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001010 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001011 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001012 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001013def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +00001014 (ins i64mem:$src1, i64i32imm:$src2),
1015 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001016 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001017 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001018def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001019 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001020 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001021 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001022def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001023 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001024 [(X86cmp GR64:$src1, i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001025 (implicit EFLAGS)]>;
1026} // Defs = [EFLAGS]
1027
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001029let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001030let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001032 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001033 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001035 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001037 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001038 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001040 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001042 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001043 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001045 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001047 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001048 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001050 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001052 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001053 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001055 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001057 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001058 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001059 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001060 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001062 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001065 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001067 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001068 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001070 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001072 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001073 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001075 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001077 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001078 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001080 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001082 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001083 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001085 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001087 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001088 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001090 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001092 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001093 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001095 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001097 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001100 X86_COND_NP, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001101} // isCommutable = 1
1102
1103def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1104 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1105 "cmovb\t{$src2, $dst|$dst, $src2}",
1106 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1107 X86_COND_B, EFLAGS))]>, TB;
1108def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1109 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1110 "cmovae\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1112 X86_COND_AE, EFLAGS))]>, TB;
1113def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1114 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1115 "cmove\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1117 X86_COND_E, EFLAGS))]>, TB;
1118def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1119 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1120 "cmovne\t{$src2, $dst|$dst, $src2}",
1121 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1122 X86_COND_NE, EFLAGS))]>, TB;
1123def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1124 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1125 "cmovbe\t{$src2, $dst|$dst, $src2}",
1126 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1127 X86_COND_BE, EFLAGS))]>, TB;
1128def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1129 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1130 "cmova\t{$src2, $dst|$dst, $src2}",
1131 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1132 X86_COND_A, EFLAGS))]>, TB;
1133def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1134 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1135 "cmovl\t{$src2, $dst|$dst, $src2}",
1136 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1137 X86_COND_L, EFLAGS))]>, TB;
1138def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1139 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1140 "cmovge\t{$src2, $dst|$dst, $src2}",
1141 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1142 X86_COND_GE, EFLAGS))]>, TB;
1143def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1144 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1145 "cmovle\t{$src2, $dst|$dst, $src2}",
1146 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1147 X86_COND_LE, EFLAGS))]>, TB;
1148def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1149 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1150 "cmovg\t{$src2, $dst|$dst, $src2}",
1151 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1152 X86_COND_G, EFLAGS))]>, TB;
1153def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1154 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1155 "cmovs\t{$src2, $dst|$dst, $src2}",
1156 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1157 X86_COND_S, EFLAGS))]>, TB;
1158def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1159 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1160 "cmovns\t{$src2, $dst|$dst, $src2}",
1161 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1162 X86_COND_NS, EFLAGS))]>, TB;
1163def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1164 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1165 "cmovp\t{$src2, $dst|$dst, $src2}",
1166 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1167 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001168def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001169 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001170 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001172 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001173} // isTwoAddress
1174
1175//===----------------------------------------------------------------------===//
1176// Conversion Instructions...
1177//
1178
1179// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001180def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001181 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001182 [(set GR64:$dst,
1183 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001184def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001185 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001186 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1187 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001188def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001189 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001191def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001192 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001193 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001194def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001195 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001196 [(set GR64:$dst,
1197 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001198def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001199 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001200 [(set GR64:$dst,
1201 (int_x86_sse2_cvttsd2si64
1202 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001203
1204// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001205def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001206 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001207 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001208def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001209 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001211
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212let isTwoAddress = 1 in {
1213def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001214 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001215 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001216 [(set VR128:$dst,
1217 (int_x86_sse2_cvtsi642sd VR128:$src1,
1218 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001219def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001220 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001221 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001222 [(set VR128:$dst,
1223 (int_x86_sse2_cvtsi642sd VR128:$src1,
1224 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225} // isTwoAddress
1226
1227// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001228def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001229 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001231def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001232 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001233 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001234
1235let isTwoAddress = 1 in {
1236 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1237 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1238 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1239 [(set VR128:$dst,
1240 (int_x86_sse_cvtsi642ss VR128:$src1,
1241 GR64:$src2))]>;
1242 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1243 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1244 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1245 [(set VR128:$dst,
1246 (int_x86_sse_cvtsi642ss VR128:$src1,
1247 (loadi64 addr:$src2)))]>;
1248}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249
1250// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001251def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001252 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001253 [(set GR64:$dst,
1254 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001255def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001256 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001257 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1258 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001259def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001261 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001262def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001263 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001264 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001265def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001266 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001267 [(set GR64:$dst,
1268 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001269def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001270 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001271 [(set GR64:$dst,
1272 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1273
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001274//===----------------------------------------------------------------------===//
1275// Alias Instructions
1276//===----------------------------------------------------------------------===//
1277
Dan Gohman027cd112007-09-17 14:55:08 +00001278// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1279// equivalent due to implicit zero-extending, and it sometimes has a smaller
1280// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1282// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1283// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001284let Defs = [EFLAGS], AddedComplexity = 1,
1285 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001286def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1287 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1288 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289
1290// Materialize i64 constant where top 32-bits are zero.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001291let AddedComplexity = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001292def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001293 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001294 [(set GR64:$dst, i64immZExt32:$src)]>;
1295
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001296//===----------------------------------------------------------------------===//
1297// Thread Local Storage Instructions
1298//===----------------------------------------------------------------------===//
1299
1300def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001301 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001302 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001303
1304//===----------------------------------------------------------------------===//
1305// Atomic Instructions
1306//===----------------------------------------------------------------------===//
1307
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001308let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001309def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001310 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001311 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1312}
1313
Dan Gohmana41a1c092008-08-06 15:52:50 +00001314let Constraints = "$val = $dst" in {
1315let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001316def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001317 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001318 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001319 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001320def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001321 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001322 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001323}
1324
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001325// Atomic exchange, and, or, xor
1326let Constraints = "$val = $dst", Defs = [EFLAGS],
1327 usesCustomDAGSchedInserter = 1 in {
1328def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001329 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001330 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001331def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001332 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001333 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001334def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001335 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001336 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001337def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001338 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001339 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001340def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001341 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001342 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001343def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001344 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001345 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001346def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001347 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001348 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001349def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001350 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001351 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001352}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001353
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001354//===----------------------------------------------------------------------===//
1355// Non-Instruction Patterns
1356//===----------------------------------------------------------------------===//
1357
Bill Wendlingfef06052008-09-16 21:48:12 +00001358// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1360 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1361def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1362 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1363def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1364 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1365def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1366 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1367
1368def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1369 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001370 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001371def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1372 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001373 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001374def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1375 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001376 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001377def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1378 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001379 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001380
1381// Calls
1382// Direct PC relative function call for small code model. 32-bit displacement
1383// sign extended to 64-bit.
1384def : Pat<(X86call (i64 tglobaladdr:$dst)),
1385 (CALL64pcrel32 tglobaladdr:$dst)>;
1386def : Pat<(X86call (i64 texternalsym:$dst)),
1387 (CALL64pcrel32 texternalsym:$dst)>;
1388
1389def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1390 (CALL64pcrel32 tglobaladdr:$dst)>;
1391def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1392 (CALL64pcrel32 texternalsym:$dst)>;
1393
1394def : Pat<(X86tailcall GR64:$dst),
1395 (CALL64r GR64:$dst)>;
1396
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001397
1398// tailcall stuff
1399def : Pat<(X86tailcall GR32:$dst),
1400 (TAILCALL)>;
1401def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1402 (TAILCALL)>;
1403def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1404 (TAILCALL)>;
1405
1406def : Pat<(X86tcret GR64:$dst, imm:$off),
1407 (TCRETURNri64 GR64:$dst, imm:$off)>;
1408
1409def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1410 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1411
1412def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1413 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1414
Dan Gohmanec596042007-09-17 14:35:24 +00001415// Comparisons.
1416
1417// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001418def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001419 (TEST64rr GR64:$src1, GR64:$src1)>;
1420
Christopher Lambb371e032008-03-13 05:47:01 +00001421
1422
1423// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001424def : Pat<(i64 (zext GR32:$src)),
1425 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001426
Duncan Sands082524c2008-01-23 20:39:46 +00001427// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001428def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1429
1430// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001431// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1432// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1433// partial-register updates.
1434def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1435def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1436def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1437// For other extloads, use subregs, since the high contents of the register are
1438// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001439def : Pat<(extloadi64i32 addr:$src),
1440 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1441 x86_subreg_32bit)>;
1442def : Pat<(extloadi16i1 addr:$src),
1443 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1444 x86_subreg_8bit)>,
1445 Requires<[In64BitMode]>;
1446def : Pat<(extloadi16i8 addr:$src),
1447 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1448 x86_subreg_8bit)>,
1449 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001450
Dan Gohmandd612bb2008-08-20 21:27:32 +00001451// anyext
1452def : Pat<(i64 (anyext GR8:$src)),
1453 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1454def : Pat<(i64 (anyext GR16:$src)),
1455 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001456def : Pat<(i64 (anyext GR32:$src)),
1457 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001458def : Pat<(i16 (anyext GR8:$src)),
1459 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1460 Requires<[In64BitMode]>;
1461def : Pat<(i32 (anyext GR8:$src)),
1462 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1463 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001464
1465//===----------------------------------------------------------------------===//
1466// Some peepholes
1467//===----------------------------------------------------------------------===//
1468
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001469// Odd encoding trick: -128 fits into an 8-bit immediate field while
1470// +128 doesn't, so in this special case use a sub instead of an add.
1471def : Pat<(add GR64:$src1, 128),
1472 (SUB64ri8 GR64:$src1, -128)>;
1473def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1474 (SUB64mi8 addr:$dst, -128)>;
1475
1476// The same trick applies for 32-bit immediate fields in 64-bit
1477// instructions.
1478def : Pat<(add GR64:$src1, 0x0000000080000000),
1479 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1480def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1481 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1482
Dan Gohman47a419d2008-08-07 02:54:50 +00001483// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001484def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001485 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001486// r & (2^16-1) ==> movz
1487def : Pat<(and GR64:$src, 0xffff),
1488 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1489// r & (2^8-1) ==> movz
1490def : Pat<(and GR64:$src, 0xff),
1491 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001492// r & (2^8-1) ==> movz
1493def : Pat<(and GR32:$src1, 0xff),
1494 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1495 Requires<[In64BitMode]>;
1496// r & (2^8-1) ==> movz
1497def : Pat<(and GR16:$src1, 0xff),
1498 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1499 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001500
Dan Gohmandd612bb2008-08-20 21:27:32 +00001501// sext_inreg patterns
1502def : Pat<(sext_inreg GR64:$src, i32),
1503 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1504def : Pat<(sext_inreg GR64:$src, i16),
1505 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1506def : Pat<(sext_inreg GR64:$src, i8),
1507 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1508def : Pat<(sext_inreg GR32:$src, i8),
1509 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1510 Requires<[In64BitMode]>;
1511def : Pat<(sext_inreg GR16:$src, i8),
1512 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1513 Requires<[In64BitMode]>;
1514
1515// trunc patterns
1516def : Pat<(i32 (trunc GR64:$src)),
1517 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1518def : Pat<(i16 (trunc GR64:$src)),
1519 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1520def : Pat<(i8 (trunc GR64:$src)),
1521 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1522def : Pat<(i8 (trunc GR32:$src)),
1523 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1524 Requires<[In64BitMode]>;
1525def : Pat<(i8 (trunc GR16:$src)),
1526 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1527 Requires<[In64BitMode]>;
1528
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529// (shl x, 1) ==> (add x, x)
1530def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1531
Evan Cheng76a64c72008-08-30 02:03:58 +00001532// (shl x (and y, 63)) ==> (shl x, y)
1533def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1534 (SHL64rCL GR64:$src1)>;
1535def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1536 (SHL64mCL addr:$dst)>;
1537
1538def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1539 (SHR64rCL GR64:$src1)>;
1540def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1541 (SHR64mCL addr:$dst)>;
1542
1543def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1544 (SAR64rCL GR64:$src1)>;
1545def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1546 (SAR64mCL addr:$dst)>;
1547
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001548// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1549def : Pat<(or (srl GR64:$src1, CL:$amt),
1550 (shl GR64:$src2, (sub 64, CL:$amt))),
1551 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1552
1553def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1554 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1555 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1556
Dan Gohman921581d2008-10-17 01:23:35 +00001557def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1558 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1559 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1560
1561def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1562 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1563 addr:$dst),
1564 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1565
1566def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1567 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1568
1569def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1570 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1571 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1572
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001573// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1574def : Pat<(or (shl GR64:$src1, CL:$amt),
1575 (srl GR64:$src2, (sub 64, CL:$amt))),
1576 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1577
1578def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1579 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1580 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1581
Dan Gohman921581d2008-10-17 01:23:35 +00001582def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1583 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1584 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1585
1586def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1587 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1588 addr:$dst),
1589 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1590
1591def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1592 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1593
1594def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1595 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1596 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1597
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001598// X86 specific add which produces a flag.
1599def : Pat<(addc GR64:$src1, GR64:$src2),
1600 (ADD64rr GR64:$src1, GR64:$src2)>;
1601def : Pat<(addc GR64:$src1, (load addr:$src2)),
1602 (ADD64rm GR64:$src1, addr:$src2)>;
1603def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1604 (ADD64ri32 GR64:$src1, imm:$src2)>;
1605def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1606 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1607
1608def : Pat<(subc GR64:$src1, GR64:$src2),
1609 (SUB64rr GR64:$src1, GR64:$src2)>;
1610def : Pat<(subc GR64:$src1, (load addr:$src2)),
1611 (SUB64rm GR64:$src1, addr:$src2)>;
1612def : Pat<(subc GR64:$src1, imm:$src2),
1613 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1614def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1615 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1616
1617
1618//===----------------------------------------------------------------------===//
1619// X86-64 SSE Instructions
1620//===----------------------------------------------------------------------===//
1621
1622// Move instructions...
1623
Evan Chengb783fa32007-07-19 01:14:50 +00001624def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001625 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001626 [(set VR128:$dst,
1627 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001628def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001629 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001630 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1631 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632
Evan Chengb783fa32007-07-19 01:14:50 +00001633def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001634 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001635 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001636def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001637 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001638 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1639
Evan Chengb783fa32007-07-19 01:14:50 +00001640def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001641 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001642 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001643def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001644 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001645 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001646
1647//===----------------------------------------------------------------------===//
1648// X86-64 SSE4.1 Instructions
1649//===----------------------------------------------------------------------===//
1650
Nate Begeman4294c1f2008-02-12 22:51:28 +00001651/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1652multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001653 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001654 (ins VR128:$src1, i32i8imm:$src2),
1655 !strconcat(OpcodeStr,
1656 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1657 [(set GR64:$dst,
1658 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001659 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001660 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1661 !strconcat(OpcodeStr,
1662 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1663 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1664 addr:$dst)]>, OpSize, REX_W;
1665}
1666
1667defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1668
1669let isTwoAddress = 1 in {
1670 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001671 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001672 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1673 !strconcat(OpcodeStr,
1674 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1675 [(set VR128:$dst,
1676 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1677 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001678 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001679 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1680 !strconcat(OpcodeStr,
1681 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1682 [(set VR128:$dst,
1683 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1684 imm:$src3)))]>, OpSize, REX_W;
1685 }
1686}
1687
1688defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;