blob: 2fe26c0b700fb97aa3898b7965d1d2d76b16efc0 [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>;
Chris Lattner357a0ca2009-06-20 19:34:09 +000022
23// 64-bits but only 32 bits are significant, and those bits are treated as being
24// pc relative.
25def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27}
28
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// 64-bits but only 8 bits are significant.
31def i64i8imm : Operand<i64>;
32
33def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000034 let PrintMethod = "printlea64mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
36}
37
38def lea64_32mem : Operand<i32> {
39 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000040 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
42}
43
44//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000045// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046//
47def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Chris Lattnerdc6fc472009-06-27 04:16:01 +000048 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper,
49 X86WrapperRIP],
Evan Chengc3495762009-03-30 21:36:47 +000050 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051
Chris Lattnerf1940742009-06-20 20:38:48 +000052def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
53 [tglobaltlsaddr], []>;
54
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000056// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057//
58
Dan Gohmand16fdc02008-12-19 18:25:21 +000059def i64immSExt8 : PatLeaf<(i64 imm), [{
60 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
61 // sign extended field.
62 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
63}]>;
64
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065def i64immSExt32 : PatLeaf<(i64 imm), [{
66 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
67 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000068 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069}]>;
70
71def i64immZExt32 : PatLeaf<(i64 imm), [{
72 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
73 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000074 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075}]>;
76
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
78def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
79def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
80
81def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
82def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
83def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
84def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
85
86def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
87def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
88def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
89def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
90
91//===----------------------------------------------------------------------===//
92// Instruction list...
93//
94
Dan Gohman01c9f772008-10-01 18:28:06 +000095// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
96// a stack adjustment and the codegen must know that they may modify the stack
97// pointer before prolog-epilog rewriting occurs.
98// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
99// sub / add which can clobber EFLAGS.
100let Defs = [RSP, EFLAGS], Uses = [RSP] in {
101def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
102 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000103 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000104 Requires<[In64BitMode]>;
105def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
106 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000107 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000108 Requires<[In64BitMode]>;
109}
110
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111//===----------------------------------------------------------------------===//
112// Call Instructions...
113//
Evan Cheng37e7c752007-07-21 00:34:19 +0000114let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000115 // All calls clobber the non-callee saved registers. RSP is marked as
116 // a use to prevent stack-pointer assignments that appear immediately
117 // before calls from potentially appearing dead. Uses for argument
118 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000120 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000121 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
122 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000123 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
124 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000125
126 // NOTE: this pattern doesn't match "X86call imm", because we do not know
127 // that the offset between an arbitrary immediate and the call will fit in
128 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000129 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000130 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
131 "call\t$dst", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000132 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000133 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000134 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000135 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000136 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137 }
138
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000139
140
141let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000142def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
143 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000144 "#TC_RETURN $dst $offset",
145 []>;
146
147let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000148def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
149 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000150 "#TC_RETURN $dst $offset",
151 []>;
152
153
154let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000155 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
156 "jmp{q}\t{*}$dst # TAILCALL",
157 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000158
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000160let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000161 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000163 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164 [(brind (loadi64 addr:$dst))]>;
165}
166
167//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000168// EH Pseudo Instructions
169//
170let isTerminator = 1, isReturn = 1, isBarrier = 1,
171 hasCtrlDep = 1 in {
172def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
173 "ret\t#eh_return, addr: $addr",
174 [(X86ehret GR64:$addr)]>;
175
176}
177
178//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179// Miscellaneous Instructions...
180//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000181let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000183 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000184let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
185let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000187 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000188let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000190 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
191}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192
Bill Wendling4c2638c2009-06-15 19:39:04 +0000193let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
194def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000195 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000196def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000197 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000198def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000199 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000200}
201
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000202let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000203def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000204let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000205def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000206
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000208 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000209 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
211
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000212let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000213def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000214 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215 [(set GR64:$dst, lea64addr:$src)]>;
216
217let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000218def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000219 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
Evan Cheng48679f42007-12-14 02:13:44 +0000222// Bit scan instructions.
223let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000224def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000225 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000226 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000227def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000228 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000229 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
230 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000231
Evan Cheng4e33de92007-12-14 18:49:43 +0000232def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000233 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000234 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000235def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000236 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000237 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
238 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000239} // Defs = [EFLAGS]
240
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000242let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000243def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000244 [(X86rep_movs i64)]>, REP;
245let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000246def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000247 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248
249//===----------------------------------------------------------------------===//
250// Move Instructions...
251//
252
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000253let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000254def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000255 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256
Evan Chengd2b9d302008-06-25 01:16:38 +0000257let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000264}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265
Dan Gohman5574cc72008-12-03 18:15:48 +0000266let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000267def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000268 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 [(set GR64:$dst, (load addr:$src))]>;
270
Evan Chengb783fa32007-07-19 01:14:50 +0000271def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000272 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000274def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000275 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 [(store i64immSExt32:$src, addr:$dst)]>;
277
278// Sign/Zero extenders
279
Dan Gohmanedde1992009-04-13 15:13:28 +0000280// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
281// operand, which makes it a rare instruction with an 8-bit register
282// operand that can never access an h register. If support for h registers
283// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000284def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000285 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000287def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000288 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000290def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000291 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000293def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000294 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000296def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000297 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000299def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000300 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
302
Dan Gohman9203ab42008-07-30 18:09:17 +0000303// Use movzbl instead of movzbq when the destination is a register; it's
304// equivalent due to implicit zero-extending, and it has a smaller encoding.
305def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
306 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
307 [(set GR64:$dst, (zext GR8:$src))]>, TB;
308def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
309 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
310 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
311// Use movzwl instead of movzwq when the destination is a register; it's
312// equivalent due to implicit zero-extending, and it has a smaller encoding.
313def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
314 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
315 [(set GR64:$dst, (zext GR16:$src))]>, TB;
316def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
317 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
318 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319
Dan Gohman47a419d2008-08-07 02:54:50 +0000320// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000321// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
322// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
323// zero-extension, however this isn't possible when the 32-bit value is
324// defined by a truncate or is copied from something where the high bits aren't
325// necessarily all zero. In such cases, we fall back to these explicit zext
326// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000327def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
328 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
329 [(set GR64:$dst, (zext GR32:$src))]>;
330def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
331 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
332 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
333
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000334// Any instruction that defines a 32-bit result leaves the high half of the
335// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
336// be copying from a truncate, but any other 32-bit operation will zero-extend
337// up to 64 bits.
338def def32 : PatLeaf<(i32 GR32:$src), [{
339 return N->getOpcode() != ISD::TRUNCATE &&
340 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
341 N->getOpcode() != ISD::CopyFromReg;
342}]>;
343
344// In the case of a 32-bit def that is known to implicitly zero-extend,
345// we can use a SUBREG_TO_REG.
346def : Pat<(i64 (zext def32:$src)),
347 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
348
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000349let neverHasSideEffects = 1 in {
350 let Defs = [RAX], Uses = [EAX] in
351 def CDQE : RI<0x98, RawFrm, (outs), (ins),
352 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000354 let Defs = [RAX,RDX], Uses = [RAX] in
355 def CQO : RI<0x99, RawFrm, (outs), (ins),
356 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
357}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000358
359//===----------------------------------------------------------------------===//
360// Arithmetic Instructions...
361//
362
Evan Cheng55687072007-09-14 21:48:26 +0000363let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364let isTwoAddress = 1 in {
365let isConvertibleToThreeAddress = 1 in {
366let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000367// Register-Register Addition
368def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
369 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000370 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000371 (implicit EFLAGS)]>;
372
373// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000374def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
375 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000376 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
377 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000378def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
379 "add{q}\t{$src2, $dst|$dst, $src2}",
380 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
381 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382} // isConvertibleToThreeAddress
383
Bill Wendlingae034ed2008-12-12 00:56:36 +0000384// Register-Memory Addition
385def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
386 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000387 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000388 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389} // isTwoAddress
390
Bill Wendlingae034ed2008-12-12 00:56:36 +0000391// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000392def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000394 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
395 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000396def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000397 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000398 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
399 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000400def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
401 "add{q}\t{$src2, $dst|$dst, $src2}",
402 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
403 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404
Evan Cheng259471d2007-10-05 17:59:57 +0000405let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406let isTwoAddress = 1 in {
407let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000408def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000410 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411
Dale Johannesen747fe522009-06-02 03:12:52 +0000412def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000413 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000414 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415
Dale Johannesen747fe522009-06-02 03:12:52 +0000416def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000417 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000418 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
419def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000420 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000421 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422} // isTwoAddress
423
Evan Chengb783fa32007-07-19 01:14:50 +0000424def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000425 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000426 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000427def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000428 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000429 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000430def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
431 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000432 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000433} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434
435let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000436// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000437def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000438 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000439 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
440 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000441
442// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000443def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000444 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000445 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
446 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000447
448// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000449def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
450 (ins GR64:$src1, i64i8imm:$src2),
451 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000452 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
453 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000454def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
455 (ins GR64:$src1, i64i32imm:$src2),
456 "sub{q}\t{$src2, $dst|$dst, $src2}",
457 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
458 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459} // isTwoAddress
460
Bill Wendlingae034ed2008-12-12 00:56:36 +0000461// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000462def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000463 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000464 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
465 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000466
467// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000468def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000469 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000470 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000471 addr:$dst),
472 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000473def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
474 "sub{q}\t{$src2, $dst|$dst, $src2}",
475 [(store (sub (load addr:$dst), i64immSExt32:$src2),
476 addr:$dst),
477 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478
Evan Cheng259471d2007-10-05 17:59:57 +0000479let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000481def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000482 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000483 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484
Dale Johannesen747fe522009-06-02 03:12:52 +0000485def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000487 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488
Dale Johannesen747fe522009-06-02 03:12:52 +0000489def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000490 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000491 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
492def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000493 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000494 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495} // isTwoAddress
496
Evan Chengb783fa32007-07-19 01:14:50 +0000497def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000498 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000499 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000500def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000502 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000503def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
504 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000505 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000506} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000507} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508
509// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000510let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000511def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000512 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000513let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000514def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000515 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516
517// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000518def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000519 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000520let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000521def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000522 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
523}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524
Evan Cheng55687072007-09-14 21:48:26 +0000525let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526let isTwoAddress = 1 in {
527let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000528// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000529def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
530 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000531 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000532 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
533 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
Bill Wendlingf5399032008-12-12 21:15:41 +0000535// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000536def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
537 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000538 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000539 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
540 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541} // isTwoAddress
542
543// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000544
Bill Wendlingf5399032008-12-12 21:15:41 +0000545// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000547 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000548 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000549 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
550 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000551def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
552 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
553 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
554 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
555 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000556
Bill Wendlingf5399032008-12-12 21:15:41 +0000557// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000559 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000560 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000561 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000562 i64immSExt8:$src2)),
563 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000564def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
565 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
566 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
567 [(set GR64:$dst, (mul (load addr:$src1),
568 i64immSExt32:$src2)),
569 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000570} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571
572// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000573let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000574def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000575 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000577def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000578 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000579let mayLoad = 1 in {
580def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
581 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000582def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000583 "idiv{q}\t$src", []>;
584}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000585}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586
587// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000588let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000590def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000591 [(set GR64:$dst, (ineg GR64:$src)),
592 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000593def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000594 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
595 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000596
597let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000598def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000599 [(set GR64:$dst, (add GR64:$src, 1)),
600 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000601def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000602 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
603 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604
605let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000606def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000607 [(set GR64:$dst, (add GR64:$src, -1)),
608 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000609def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000610 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
611 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612
613// In 64-bit mode, single byte INC and DEC cannot be encoded.
614let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
615// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000616def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000617 [(set GR16:$dst, (add GR16:$src, 1)),
618 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000620def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000621 [(set GR32:$dst, (add GR32:$src, 1)),
622 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000624def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000625 [(set GR16:$dst, (add GR16:$src, -1)),
626 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000628def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000629 [(set GR32:$dst, (add GR32:$src, -1)),
630 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631 Requires<[In64BitMode]>;
632} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000633
634// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
635// how to unfold them.
636let isTwoAddress = 0, CodeSize = 2 in {
637 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000638 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
639 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000640 OpSize, Requires<[In64BitMode]>;
641 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000642 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
643 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000644 Requires<[In64BitMode]>;
645 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000646 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
647 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000648 OpSize, Requires<[In64BitMode]>;
649 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000650 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
651 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000652 Requires<[In64BitMode]>;
653}
Evan Cheng55687072007-09-14 21:48:26 +0000654} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655
656
Evan Cheng55687072007-09-14 21:48:26 +0000657let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658// Shift instructions
659let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000660let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000661def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000662 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000663 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000664let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000665def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000666 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000668// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
669// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670} // isTwoAddress
671
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000672let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000673def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000674 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000675 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000676def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000677 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000679def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000680 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
682
683let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000684let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000685def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000687 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000688def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000689 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000691def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000692 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
694} // isTwoAddress
695
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000696let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000697def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000699 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000700def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000703def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000704 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000705 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
706
707let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000708let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000709def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000710 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000711 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000712def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000713 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000715def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000717 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
718} // isTwoAddress
719
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000720let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000721def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000722 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000724def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000725 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000727def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
730
731// Rotate instructions
732let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000733let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000734def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000736 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000737def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000738 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000740def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000742 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
743} // isTwoAddress
744
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000745let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000746def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000748 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000749def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000750 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000752def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
755
756let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000757let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000758def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000760 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000761def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000763 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000764def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000765 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000766 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
767} // isTwoAddress
768
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000769let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000770def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000771 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000772 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000773def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000774 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000775 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000776def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000777 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
779
780// Double shift instructions (generalizations of rotate)
781let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000782let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000783def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000784 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
785 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000786def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000787 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
788 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000789}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790
791let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
792def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000793 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000794 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
795 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
796 (i8 imm:$src3)))]>,
797 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000799 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000800 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
801 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
802 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 TB;
804} // isCommutable
805} // isTwoAddress
806
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000807let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000808def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000809 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
810 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
811 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000812def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000813 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
814 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
815 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000816}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000818 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000819 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
820 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
821 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000822 TB;
823def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000824 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000825 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
826 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
827 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000829} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830
831//===----------------------------------------------------------------------===//
832// Logical Instructions...
833//
834
Evan Cheng5b51c242009-01-21 19:45:31 +0000835let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000836def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000838def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
840
Evan Cheng55687072007-09-14 21:48:26 +0000841let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842let isTwoAddress = 1 in {
843let isCommutable = 1 in
844def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000845 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000846 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000847 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
848 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000850 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000851 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000852 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
853 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000856 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000857 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
858 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000859def AND64ri32 : RIi32<0x81, MRM4r,
860 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
861 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000862 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
863 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864} // isTwoAddress
865
866def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000867 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000868 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000869 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
870 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000871def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000872 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000873 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000874 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
875 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000876def AND64mi32 : RIi32<0x81, MRM4m,
877 (outs), (ins i64mem:$dst, i64i32imm:$src),
878 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000879 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
880 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881
882let isTwoAddress = 1 in {
883let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000884def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000886 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
887 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000888def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000889 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000890 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
891 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000892def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000893 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000894 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
895 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000896def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
897 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000898 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
899 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000900} // isTwoAddress
901
Evan Chengb783fa32007-07-19 01:14:50 +0000902def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000903 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000904 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
905 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000906def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000907 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000908 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
909 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000910def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
911 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000912 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
913 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914
915let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000916let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000917def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000919 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
920 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000921def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000922 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000923 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
924 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000925def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
926 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000927 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
928 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000929def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000930 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000931 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000932 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
933 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934} // isTwoAddress
935
Evan Chengb783fa32007-07-19 01:14:50 +0000936def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000938 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
939 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000940def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000941 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000942 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
943 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000944def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
945 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000946 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
947 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000948} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949
950//===----------------------------------------------------------------------===//
951// Comparison Instructions...
952//
953
954// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000955let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000956let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000957def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000958 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000959 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
960 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000961def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000963 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
964 (implicit EFLAGS)]>;
965def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
966 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000967 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000968 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
969 (implicit EFLAGS)]>;
970def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
971 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000972 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000973 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
974 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975
Evan Chengb783fa32007-07-19 01:14:50 +0000976def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000977 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000978 [(X86cmp GR64:$src1, GR64:$src2),
979 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000980def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000981 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000982 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
983 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000984def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000985 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000986 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
987 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000988def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
989 "cmp{q}\t{$src2, $src1|$src1, $src2}",
990 [(X86cmp GR64:$src1, i64immSExt8:$src2),
991 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000992def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000993 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000994 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000995 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000996def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000997 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000998 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000999 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001000def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1001 (ins i64mem:$src1, i64i32imm:$src2),
1002 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1003 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1004 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001005} // Defs = [EFLAGS]
1006
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001007// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001008// TODO: BTC, BTR, and BTS
1009let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001010def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001011 "bt{q}\t{$src2, $src1|$src1, $src2}",
1012 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001013 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001014
1015// Unlike with the register+register form, the memory+register form of the
1016// bt instruction does not ignore the high bits of the index. From ISel's
1017// perspective, this is pretty bizarre. Disable these instructions for now.
1018//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1019// "bt{q}\t{$src2, $src1|$src1, $src2}",
1020// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1021// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001022
1023def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1024 "bt{q}\t{$src2, $src1|$src1, $src2}",
1025 [(X86bt GR64:$src1, i64immSExt8:$src2),
1026 (implicit EFLAGS)]>, TB;
1027// Note that these instructions don't need FastBTMem because that
1028// only applies when the other operand is in a register. When it's
1029// an immediate, bt is still fast.
1030def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1031 "bt{q}\t{$src2, $src1|$src1, $src2}",
1032 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1033 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001034} // Defs = [EFLAGS]
1035
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001037let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001038let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001040 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001041 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001042 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001043 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001045 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001046 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001048 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001050 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001051 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001053 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001055 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001056 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001057 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001058 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001059def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001060 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001061 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001062 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001063 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001065 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001066 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001068 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001070 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001071 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001073 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001075 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001076 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001077 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001078 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001080 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001081 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001083 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001085 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001086 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001088 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001090 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001093 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001095 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001096 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001097 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001098 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001100 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001103 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001105 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001106 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001107 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001108 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001109def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1110 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1111 "cmovo\t{$src2, $dst|$dst, $src2}",
1112 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1113 X86_COND_O, EFLAGS))]>, TB;
1114def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1115 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1116 "cmovno\t{$src2, $dst|$dst, $src2}",
1117 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1118 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001119} // isCommutable = 1
1120
1121def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1122 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1123 "cmovb\t{$src2, $dst|$dst, $src2}",
1124 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1125 X86_COND_B, EFLAGS))]>, TB;
1126def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1127 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1128 "cmovae\t{$src2, $dst|$dst, $src2}",
1129 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1130 X86_COND_AE, EFLAGS))]>, TB;
1131def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1132 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1133 "cmove\t{$src2, $dst|$dst, $src2}",
1134 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1135 X86_COND_E, EFLAGS))]>, TB;
1136def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1137 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1138 "cmovne\t{$src2, $dst|$dst, $src2}",
1139 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1140 X86_COND_NE, EFLAGS))]>, TB;
1141def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1142 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1143 "cmovbe\t{$src2, $dst|$dst, $src2}",
1144 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1145 X86_COND_BE, EFLAGS))]>, TB;
1146def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1147 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1148 "cmova\t{$src2, $dst|$dst, $src2}",
1149 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1150 X86_COND_A, EFLAGS))]>, TB;
1151def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1152 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1153 "cmovl\t{$src2, $dst|$dst, $src2}",
1154 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1155 X86_COND_L, EFLAGS))]>, TB;
1156def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1157 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1158 "cmovge\t{$src2, $dst|$dst, $src2}",
1159 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1160 X86_COND_GE, EFLAGS))]>, TB;
1161def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1162 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1163 "cmovle\t{$src2, $dst|$dst, $src2}",
1164 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1165 X86_COND_LE, EFLAGS))]>, TB;
1166def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1167 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1168 "cmovg\t{$src2, $dst|$dst, $src2}",
1169 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1170 X86_COND_G, EFLAGS))]>, TB;
1171def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1172 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1173 "cmovs\t{$src2, $dst|$dst, $src2}",
1174 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1175 X86_COND_S, EFLAGS))]>, TB;
1176def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1177 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1178 "cmovns\t{$src2, $dst|$dst, $src2}",
1179 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1180 X86_COND_NS, EFLAGS))]>, TB;
1181def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1182 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1183 "cmovp\t{$src2, $dst|$dst, $src2}",
1184 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1185 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001187 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001188 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001189 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001190 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001191def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1192 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1193 "cmovo\t{$src2, $dst|$dst, $src2}",
1194 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1195 X86_COND_O, EFLAGS))]>, TB;
1196def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1197 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1198 "cmovno\t{$src2, $dst|$dst, $src2}",
1199 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1200 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001201} // isTwoAddress
1202
1203//===----------------------------------------------------------------------===//
1204// Conversion Instructions...
1205//
1206
1207// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001208def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001209 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001210 [(set GR64:$dst,
1211 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001212def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001213 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001214 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1215 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001216def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001217 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001219def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001220 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001221 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001222def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001223 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001224 [(set GR64:$dst,
1225 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001226def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001227 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001228 [(set GR64:$dst,
1229 (int_x86_sse2_cvttsd2si64
1230 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231
1232// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001233def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001236def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001237 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001239
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240let isTwoAddress = 1 in {
1241def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001242 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001243 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001244 [(set VR128:$dst,
1245 (int_x86_sse2_cvtsi642sd VR128:$src1,
1246 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001247def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001248 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001249 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001250 [(set VR128:$dst,
1251 (int_x86_sse2_cvtsi642sd VR128:$src1,
1252 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253} // isTwoAddress
1254
1255// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001256def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001259def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001261 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001262
1263let isTwoAddress = 1 in {
1264 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1265 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1266 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1267 [(set VR128:$dst,
1268 (int_x86_sse_cvtsi642ss VR128:$src1,
1269 GR64:$src2))]>;
1270 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1271 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1272 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1273 [(set VR128:$dst,
1274 (int_x86_sse_cvtsi642ss VR128:$src1,
1275 (loadi64 addr:$src2)))]>;
1276}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277
1278// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001279def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001281 [(set GR64:$dst,
1282 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001283def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001284 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001285 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1286 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001287def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001288 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001290def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001291 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001292 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001293def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001294 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001295 [(set GR64:$dst,
1296 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001297def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001298 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001299 [(set GR64:$dst,
1300 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1301
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001302//===----------------------------------------------------------------------===//
1303// Alias Instructions
1304//===----------------------------------------------------------------------===//
1305
Dan Gohman027cd112007-09-17 14:55:08 +00001306// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1307// equivalent due to implicit zero-extending, and it sometimes has a smaller
1308// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1310// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1311// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001312let Defs = [EFLAGS], AddedComplexity = 1,
1313 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001314def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1315 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1316 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317
1318// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001319let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001320def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322 [(set GR64:$dst, i64immZExt32:$src)]>;
1323
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001324//===----------------------------------------------------------------------===//
1325// Thread Local Storage Instructions
1326//===----------------------------------------------------------------------===//
1327
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001328// All calls clobber the non-callee saved registers. RSP is marked as
1329// a use to prevent stack-pointer assignments that appear immediately
1330// before calls from potentially appearing dead.
1331let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1332 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1333 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1334 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1335 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1336 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001337def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001338 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001339 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001340 ".word\t0x6666; "
1341 "rex64; "
1342 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001343 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001344 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001345
sampo9cc09a32009-01-26 01:24:32 +00001346let AddedComplexity = 5 in
1347def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1348 "movq\t%gs:$src, $dst",
1349 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1350
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001351let AddedComplexity = 5 in
1352def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1353 "movq\t%fs:$src, $dst",
1354 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1355
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001356//===----------------------------------------------------------------------===//
1357// Atomic Instructions
1358//===----------------------------------------------------------------------===//
1359
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001360let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001361def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001362 "lock\n\t"
1363 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001364 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1365}
1366
Dan Gohmana41a1c092008-08-06 15:52:50 +00001367let Constraints = "$val = $dst" in {
1368let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001369def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001370 "lock\n\t"
1371 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001372 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001373 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001374def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001375 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001376 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001377}
1378
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001379// Atomic exchange, and, or, xor
1380let Constraints = "$val = $dst", Defs = [EFLAGS],
1381 usesCustomDAGSchedInserter = 1 in {
1382def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001383 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001384 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001385def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001386 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001387 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001388def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001389 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001390 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001391def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001392 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001393 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001394def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001395 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001396 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001397def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001398 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001399 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001400def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001401 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001402 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001403def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001404 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001405 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001406}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001407
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001408//===----------------------------------------------------------------------===//
1409// Non-Instruction Patterns
1410//===----------------------------------------------------------------------===//
1411
Chris Lattner0d2dad62009-07-11 22:50:33 +00001412// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1413// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1414// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001415def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1416 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1417def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1418 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1419def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1420 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1421def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1422 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1423
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001424// If we have small model and -static mode, it is safe to store global addresses
1425// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001426// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001427def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1428 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001429 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001430def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1431 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001432 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001433def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1434 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001435 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001436def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1437 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001438 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001439
1440// Calls
1441// Direct PC relative function call for small code model. 32-bit displacement
1442// sign extended to 64-bit.
1443def : Pat<(X86call (i64 tglobaladdr:$dst)),
1444 (CALL64pcrel32 tglobaladdr:$dst)>;
1445def : Pat<(X86call (i64 texternalsym:$dst)),
1446 (CALL64pcrel32 texternalsym:$dst)>;
1447
1448def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1449 (CALL64pcrel32 tglobaladdr:$dst)>;
1450def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1451 (CALL64pcrel32 texternalsym:$dst)>;
1452
1453def : Pat<(X86tailcall GR64:$dst),
1454 (CALL64r GR64:$dst)>;
1455
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001456
1457// tailcall stuff
1458def : Pat<(X86tailcall GR32:$dst),
1459 (TAILCALL)>;
1460def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1461 (TAILCALL)>;
1462def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1463 (TAILCALL)>;
1464
1465def : Pat<(X86tcret GR64:$dst, imm:$off),
1466 (TCRETURNri64 GR64:$dst, imm:$off)>;
1467
1468def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1469 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1470
1471def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1472 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1473
Dan Gohmanec596042007-09-17 14:35:24 +00001474// Comparisons.
1475
1476// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001477def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001478 (TEST64rr GR64:$src1, GR64:$src1)>;
1479
Dan Gohman0a3c5222009-01-07 01:00:24 +00001480// Conditional moves with folded loads with operands swapped and conditions
1481// inverted.
1482def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1483 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1484def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1485 (CMOVB64rm GR64:$src2, addr:$src1)>;
1486def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1487 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1488def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1489 (CMOVE64rm GR64:$src2, addr:$src1)>;
1490def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1491 (CMOVA64rm GR64:$src2, addr:$src1)>;
1492def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1493 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1494def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1495 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1496def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1497 (CMOVL64rm GR64:$src2, addr:$src1)>;
1498def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1499 (CMOVG64rm GR64:$src2, addr:$src1)>;
1500def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1501 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1502def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1503 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1504def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1505 (CMOVP64rm GR64:$src2, addr:$src1)>;
1506def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1507 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1508def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1509 (CMOVS64rm GR64:$src2, addr:$src1)>;
1510def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1511 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1512def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1513 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001514
Duncan Sands082524c2008-01-23 20:39:46 +00001515// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001516def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1517
1518// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001519// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1520// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1521// partial-register updates.
1522def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1523def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1524def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1525// For other extloads, use subregs, since the high contents of the register are
1526// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001527def : Pat<(extloadi64i32 addr:$src),
1528 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1529 x86_subreg_32bit)>;
1530def : Pat<(extloadi16i1 addr:$src),
1531 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1532 x86_subreg_8bit)>,
1533 Requires<[In64BitMode]>;
1534def : Pat<(extloadi16i8 addr:$src),
1535 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1536 x86_subreg_8bit)>,
1537 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538
Dan Gohmandd612bb2008-08-20 21:27:32 +00001539// anyext
1540def : Pat<(i64 (anyext GR8:$src)),
1541 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1542def : Pat<(i64 (anyext GR16:$src)),
1543 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001544def : Pat<(i64 (anyext GR32:$src)),
1545 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001546def : Pat<(i16 (anyext GR8:$src)),
1547 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1548 Requires<[In64BitMode]>;
1549def : Pat<(i32 (anyext GR8:$src)),
1550 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1551 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001552
1553//===----------------------------------------------------------------------===//
1554// Some peepholes
1555//===----------------------------------------------------------------------===//
1556
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001557// Odd encoding trick: -128 fits into an 8-bit immediate field while
1558// +128 doesn't, so in this special case use a sub instead of an add.
1559def : Pat<(add GR64:$src1, 128),
1560 (SUB64ri8 GR64:$src1, -128)>;
1561def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1562 (SUB64mi8 addr:$dst, -128)>;
1563
1564// The same trick applies for 32-bit immediate fields in 64-bit
1565// instructions.
1566def : Pat<(add GR64:$src1, 0x0000000080000000),
1567 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1568def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1569 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1570
Dan Gohman47a419d2008-08-07 02:54:50 +00001571// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001572def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001573 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001574// r & (2^16-1) ==> movz
1575def : Pat<(and GR64:$src, 0xffff),
1576 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1577// r & (2^8-1) ==> movz
1578def : Pat<(and GR64:$src, 0xff),
1579 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001580// r & (2^8-1) ==> movz
1581def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001582 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001583 Requires<[In64BitMode]>;
1584// r & (2^8-1) ==> movz
1585def : Pat<(and GR16:$src1, 0xff),
1586 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1587 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001588
Dan Gohmandd612bb2008-08-20 21:27:32 +00001589// sext_inreg patterns
1590def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001591 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001592def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001593 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001594def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001595 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001596def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001597 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001598 Requires<[In64BitMode]>;
1599def : Pat<(sext_inreg GR16:$src, i8),
1600 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1601 Requires<[In64BitMode]>;
1602
1603// trunc patterns
1604def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001605 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001606def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001607 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001608def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001609 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001610def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001611 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001612 Requires<[In64BitMode]>;
1613def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001614 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1615 Requires<[In64BitMode]>;
1616
1617// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001618// For now, be conservative on x86-64 and use an h-register extract only if the
1619// value is immediately zero-extended or stored, which are somewhat common
1620// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1621// from being allocated in the same instruction as the h register, as there's
1622// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001623
1624// h-register extract and zero-extend.
1625def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1626 (SUBREG_TO_REG
1627 (i64 0),
1628 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001629 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001630 x86_subreg_8bit_hi)),
1631 x86_subreg_32bit)>;
1632def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1633 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001634 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001635 x86_subreg_8bit_hi))>,
1636 Requires<[In64BitMode]>;
1637def : Pat<(srl_su GR16:$src, (i8 8)),
1638 (EXTRACT_SUBREG
1639 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001640 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001641 x86_subreg_8bit_hi)),
1642 x86_subreg_16bit)>,
1643 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001644def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1645 (MOVZX32_NOREXrr8
1646 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1647 x86_subreg_8bit_hi))>,
1648 Requires<[In64BitMode]>;
1649def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1650 (SUBREG_TO_REG
1651 (i64 0),
1652 (MOVZX32_NOREXrr8
1653 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1654 x86_subreg_8bit_hi)),
1655 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001656
1657// h-register extract and store.
1658def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1659 (MOV8mr_NOREX
1660 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001661 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001662 x86_subreg_8bit_hi))>;
1663def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1664 (MOV8mr_NOREX
1665 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001666 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001667 x86_subreg_8bit_hi))>,
1668 Requires<[In64BitMode]>;
1669def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1670 (MOV8mr_NOREX
1671 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001672 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001673 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001674 Requires<[In64BitMode]>;
1675
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001676// (shl x, 1) ==> (add x, x)
1677def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1678
Evan Cheng76a64c72008-08-30 02:03:58 +00001679// (shl x (and y, 63)) ==> (shl x, y)
1680def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1681 (SHL64rCL GR64:$src1)>;
1682def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1683 (SHL64mCL addr:$dst)>;
1684
1685def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1686 (SHR64rCL GR64:$src1)>;
1687def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1688 (SHR64mCL addr:$dst)>;
1689
1690def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1691 (SAR64rCL GR64:$src1)>;
1692def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1693 (SAR64mCL addr:$dst)>;
1694
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001695// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1696def : Pat<(or (srl GR64:$src1, CL:$amt),
1697 (shl GR64:$src2, (sub 64, CL:$amt))),
1698 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1699
1700def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1701 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1702 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1703
Dan Gohman921581d2008-10-17 01:23:35 +00001704def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1705 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1706 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1707
1708def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1709 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1710 addr:$dst),
1711 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1712
1713def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1714 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1715
1716def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1717 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1718 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1719
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001720// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1721def : Pat<(or (shl GR64:$src1, CL:$amt),
1722 (srl GR64:$src2, (sub 64, CL:$amt))),
1723 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1724
1725def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1726 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1727 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1728
Dan Gohman921581d2008-10-17 01:23:35 +00001729def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1730 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1731 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1732
1733def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1734 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1735 addr:$dst),
1736 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1737
1738def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1739 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1740
1741def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1742 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1743 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1744
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001745// X86 specific add which produces a flag.
1746def : Pat<(addc GR64:$src1, GR64:$src2),
1747 (ADD64rr GR64:$src1, GR64:$src2)>;
1748def : Pat<(addc GR64:$src1, (load addr:$src2)),
1749 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1751 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001752def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1753 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754
1755def : Pat<(subc GR64:$src1, GR64:$src2),
1756 (SUB64rr GR64:$src1, GR64:$src2)>;
1757def : Pat<(subc GR64:$src1, (load addr:$src2)),
1758 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001759def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1760 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001761def : Pat<(subc GR64:$src1, imm:$src2),
1762 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001763
Bill Wendlingf5399032008-12-12 21:15:41 +00001764//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001765// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001766//===----------------------------------------------------------------------===//
1767
Dan Gohman99a12192009-03-04 19:44:21 +00001768// Register-Register Addition with EFLAGS result
1769def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001770 (implicit EFLAGS)),
1771 (ADD64rr GR64:$src1, GR64:$src2)>;
1772
Dan Gohman99a12192009-03-04 19:44:21 +00001773// Register-Integer Addition with EFLAGS result
1774def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001775 (implicit EFLAGS)),
1776 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001777def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001778 (implicit EFLAGS)),
1779 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001780
Dan Gohman99a12192009-03-04 19:44:21 +00001781// Register-Memory Addition with EFLAGS result
1782def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001783 (implicit EFLAGS)),
1784 (ADD64rm GR64:$src1, addr:$src2)>;
1785
Dan Gohman99a12192009-03-04 19:44:21 +00001786// Memory-Register Addition with EFLAGS result
1787def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001788 addr:$dst),
1789 (implicit EFLAGS)),
1790 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001791def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001792 addr:$dst),
1793 (implicit EFLAGS)),
1794 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001795def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001796 addr:$dst),
1797 (implicit EFLAGS)),
1798 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001799
Dan Gohman99a12192009-03-04 19:44:21 +00001800// Register-Register Subtraction with EFLAGS result
1801def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001802 (implicit EFLAGS)),
1803 (SUB64rr GR64:$src1, GR64:$src2)>;
1804
Dan Gohman99a12192009-03-04 19:44:21 +00001805// Register-Memory Subtraction with EFLAGS result
1806def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001807 (implicit EFLAGS)),
1808 (SUB64rm GR64:$src1, addr:$src2)>;
1809
Dan Gohman99a12192009-03-04 19:44:21 +00001810// Register-Integer Subtraction with EFLAGS result
1811def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001812 (implicit EFLAGS)),
1813 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001814def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001815 (implicit EFLAGS)),
1816 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001817
Dan Gohman99a12192009-03-04 19:44:21 +00001818// Memory-Register Subtraction with EFLAGS result
1819def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001820 addr:$dst),
1821 (implicit EFLAGS)),
1822 (SUB64mr addr:$dst, GR64:$src2)>;
1823
Dan Gohman99a12192009-03-04 19:44:21 +00001824// Memory-Integer Subtraction with EFLAGS result
1825def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001826 addr:$dst),
1827 (implicit EFLAGS)),
1828 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001829def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001830 addr:$dst),
1831 (implicit EFLAGS)),
1832 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001833
Dan Gohman99a12192009-03-04 19:44:21 +00001834// Register-Register Signed Integer Multiplication with EFLAGS result
1835def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001836 (implicit EFLAGS)),
1837 (IMUL64rr GR64:$src1, GR64:$src2)>;
1838
Dan Gohman99a12192009-03-04 19:44:21 +00001839// Register-Memory Signed Integer Multiplication with EFLAGS result
1840def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001841 (implicit EFLAGS)),
1842 (IMUL64rm GR64:$src1, addr:$src2)>;
1843
Dan Gohman99a12192009-03-04 19:44:21 +00001844// Register-Integer Signed Integer Multiplication with EFLAGS result
1845def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001846 (implicit EFLAGS)),
1847 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001848def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001849 (implicit EFLAGS)),
1850 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001851
Dan Gohman99a12192009-03-04 19:44:21 +00001852// Memory-Integer Signed Integer Multiplication with EFLAGS result
1853def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001854 (implicit EFLAGS)),
1855 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001856def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001857 (implicit EFLAGS)),
1858 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001859
Dan Gohman99a12192009-03-04 19:44:21 +00001860// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001861def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1862 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1863def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1864 (implicit EFLAGS)),
1865 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1866def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1867 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1868def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1869 (implicit EFLAGS)),
1870 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1871
1872def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1873 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1874def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1875 (implicit EFLAGS)),
1876 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1877def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1878 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1879def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1880 (implicit EFLAGS)),
1881 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1882
Dan Gohman99a12192009-03-04 19:44:21 +00001883def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1884 (INC64r GR64:$src)>;
1885def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1886 (implicit EFLAGS)),
1887 (INC64m addr:$dst)>;
1888def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1889 (DEC64r GR64:$src)>;
1890def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1891 (implicit EFLAGS)),
1892 (DEC64m addr:$dst)>;
1893
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001894//===----------------------------------------------------------------------===//
1895// X86-64 SSE Instructions
1896//===----------------------------------------------------------------------===//
1897
1898// Move instructions...
1899
Evan Chengb783fa32007-07-19 01:14:50 +00001900def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001901 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001902 [(set VR128:$dst,
1903 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001904def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001905 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001906 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1907 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001908
Evan Chengb783fa32007-07-19 01:14:50 +00001909def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001910 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001911 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001912def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001913 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1915
Evan Chengb783fa32007-07-19 01:14:50 +00001916def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001917 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001918 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001919def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001920 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001922
1923//===----------------------------------------------------------------------===//
1924// X86-64 SSE4.1 Instructions
1925//===----------------------------------------------------------------------===//
1926
Nate Begeman4294c1f2008-02-12 22:51:28 +00001927/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1928multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001929 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001930 (ins VR128:$src1, i32i8imm:$src2),
1931 !strconcat(OpcodeStr,
1932 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1933 [(set GR64:$dst,
1934 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001935 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001936 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1937 !strconcat(OpcodeStr,
1938 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1939 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1940 addr:$dst)]>, OpSize, REX_W;
1941}
1942
1943defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1944
1945let isTwoAddress = 1 in {
1946 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001947 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001948 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1949 !strconcat(OpcodeStr,
1950 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1951 [(set VR128:$dst,
1952 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1953 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001954 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001955 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1956 !strconcat(OpcodeStr,
1957 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1958 [(set VR128:$dst,
1959 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1960 imm:$src3)))]>, OpSize, REX_W;
1961 }
1962}
1963
1964defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;