blob: ba886e45acae3d6f6122c679073240971bed59a8 [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 Lattnerc04cd042009-07-11 23:17:29 +000048 [add, mul, X86mul_imm, shl, or, frameindex,
49 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
Chris Lattnerf1940742009-06-20 20:38:48 +000051def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
52 [tglobaltlsaddr], []>;
53
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000055// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056//
57
Dan Gohmand16fdc02008-12-19 18:25:21 +000058def i64immSExt8 : PatLeaf<(i64 imm), [{
59 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60 // sign extended field.
61 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
62}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def i64immSExt32 : PatLeaf<(i64 imm), [{
65 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
66 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000067 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068}]>;
69
70def i64immZExt32 : PatLeaf<(i64 imm), [{
71 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
72 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000073 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074}]>;
75
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
77def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
78def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
79
80def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
81def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
82def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
83def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
84
85def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
86def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
87def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
88def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
89
90//===----------------------------------------------------------------------===//
91// Instruction list...
92//
93
Dan Gohman01c9f772008-10-01 18:28:06 +000094// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
95// a stack adjustment and the codegen must know that they may modify the stack
96// pointer before prolog-epilog rewriting occurs.
97// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
98// sub / add which can clobber EFLAGS.
99let Defs = [RSP, EFLAGS], Uses = [RSP] in {
100def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
101 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000102 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000103 Requires<[In64BitMode]>;
104def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
105 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000106 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000107 Requires<[In64BitMode]>;
108}
109
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110//===----------------------------------------------------------------------===//
111// Call Instructions...
112//
Evan Cheng37e7c752007-07-21 00:34:19 +0000113let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000114 // All calls clobber the non-callee saved registers. RSP is marked as
115 // a use to prevent stack-pointer assignments that appear immediately
116 // before calls from potentially appearing dead. Uses for argument
117 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000119 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000120 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
121 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000122 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
123 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000124
125 // NOTE: this pattern doesn't match "X86call imm", because we do not know
126 // that the offset between an arbitrary immediate and the call will fit in
127 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000128 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000129 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
130 "call\t$dst", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000131 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000132 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000133 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000134 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000135 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136 }
137
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000138
139
140let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000141def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
142 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000143 "#TC_RETURN $dst $offset",
144 []>;
145
146let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000147def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
148 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000149 "#TC_RETURN $dst $offset",
150 []>;
151
152
153let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000154 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
155 "jmp{q}\t{*}$dst # TAILCALL",
156 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000157
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000159let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000160 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000162 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 [(brind (loadi64 addr:$dst))]>;
164}
165
166//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000167// EH Pseudo Instructions
168//
169let isTerminator = 1, isReturn = 1, isBarrier = 1,
170 hasCtrlDep = 1 in {
171def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
172 "ret\t#eh_return, addr: $addr",
173 [(X86ehret GR64:$addr)]>;
174
175}
176
177//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178// Miscellaneous Instructions...
179//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000180let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000182 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000183let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
184let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000186 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000187let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000189 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
190}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191
Bill Wendling4c2638c2009-06-15 19:39:04 +0000192let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
193def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000194 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000195def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000196 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000197def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000198 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000199}
200
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000201let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000202def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000203let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000204def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000205
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000207 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000208 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
210
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000211let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000212def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000213 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214 [(set GR64:$dst, lea64addr:$src)]>;
215
216let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000217def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000218 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220
Evan Cheng48679f42007-12-14 02:13:44 +0000221// Bit scan instructions.
222let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000223def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000224 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000225 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000226def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000227 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000228 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
229 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000230
Evan Cheng4e33de92007-12-14 18:49:43 +0000231def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000232 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000233 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000234def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000235 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000236 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
237 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000238} // Defs = [EFLAGS]
239
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000241let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000242def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000243 [(X86rep_movs i64)]>, REP;
244let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000246 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247
248//===----------------------------------------------------------------------===//
249// Move Instructions...
250//
251
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000252let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000253def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000254 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255
Evan Chengd2b9d302008-06-25 01:16:38 +0000256let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000257def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000258 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000260def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000261 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000263}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264
Dan Gohman5574cc72008-12-03 18:15:48 +0000265let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000266def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000267 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268 [(set GR64:$dst, (load addr:$src))]>;
269
Evan Chengb783fa32007-07-19 01:14:50 +0000270def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000271 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000273def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000274 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 [(store i64immSExt32:$src, addr:$dst)]>;
276
277// Sign/Zero extenders
278
Dan Gohmanedde1992009-04-13 15:13:28 +0000279// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
280// operand, which makes it a rare instruction with an 8-bit register
281// operand that can never access an h register. If support for h registers
282// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000283def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000284 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000286def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000287 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000289def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000290 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000292def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000293 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000295def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000296 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
301
Dan Gohman9203ab42008-07-30 18:09:17 +0000302// Use movzbl instead of movzbq when the destination is a register; it's
303// equivalent due to implicit zero-extending, and it has a smaller encoding.
304def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
305 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zext GR8:$src))]>, TB;
307def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
308 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
309 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
310// Use movzwl instead of movzwq when the destination is a register; it's
311// equivalent due to implicit zero-extending, and it has a smaller encoding.
312def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
313 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
314 [(set GR64:$dst, (zext GR16:$src))]>, TB;
315def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
316 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
317 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318
Dan Gohman47a419d2008-08-07 02:54:50 +0000319// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000320// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
321// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
322// zero-extension, however this isn't possible when the 32-bit value is
323// defined by a truncate or is copied from something where the high bits aren't
324// necessarily all zero. In such cases, we fall back to these explicit zext
325// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000326def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
327 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
328 [(set GR64:$dst, (zext GR32:$src))]>;
329def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
330 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
331 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
332
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000333// Any instruction that defines a 32-bit result leaves the high half of the
334// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
335// be copying from a truncate, but any other 32-bit operation will zero-extend
336// up to 64 bits.
337def def32 : PatLeaf<(i32 GR32:$src), [{
338 return N->getOpcode() != ISD::TRUNCATE &&
339 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
340 N->getOpcode() != ISD::CopyFromReg;
341}]>;
342
343// In the case of a 32-bit def that is known to implicitly zero-extend,
344// we can use a SUBREG_TO_REG.
345def : Pat<(i64 (zext def32:$src)),
346 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
347
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000348let neverHasSideEffects = 1 in {
349 let Defs = [RAX], Uses = [EAX] in
350 def CDQE : RI<0x98, RawFrm, (outs), (ins),
351 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000353 let Defs = [RAX,RDX], Uses = [RAX] in
354 def CQO : RI<0x99, RawFrm, (outs), (ins),
355 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
356}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357
358//===----------------------------------------------------------------------===//
359// Arithmetic Instructions...
360//
361
Evan Cheng55687072007-09-14 21:48:26 +0000362let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363let isTwoAddress = 1 in {
364let isConvertibleToThreeAddress = 1 in {
365let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000366// Register-Register Addition
367def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
368 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000369 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000370 (implicit EFLAGS)]>;
371
372// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000373def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
374 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000375 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
376 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000377def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
378 "add{q}\t{$src2, $dst|$dst, $src2}",
379 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
380 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381} // isConvertibleToThreeAddress
382
Bill Wendlingae034ed2008-12-12 00:56:36 +0000383// Register-Memory Addition
384def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
385 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000386 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000387 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388} // isTwoAddress
389
Bill Wendlingae034ed2008-12-12 00:56:36 +0000390// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000391def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000392 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000393 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
394 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000395def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000396 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000397 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
398 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000399def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
400 "add{q}\t{$src2, $dst|$dst, $src2}",
401 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
402 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403
Evan Cheng259471d2007-10-05 17:59:57 +0000404let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405let isTwoAddress = 1 in {
406let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000407def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000408 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000409 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410
Dale Johannesen747fe522009-06-02 03:12:52 +0000411def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000412 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000413 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414
Dale Johannesen747fe522009-06-02 03:12:52 +0000415def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000416 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000417 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
418def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000419 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000420 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421} // isTwoAddress
422
Evan Chengb783fa32007-07-19 01:14:50 +0000423def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000425 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000426def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000427 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000428 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000429def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
430 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000431 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000432} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433
434let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000435// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000436def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000437 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000438 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
439 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000440
441// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000442def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000444 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
445 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000446
447// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000448def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
449 (ins GR64:$src1, i64i8imm:$src2),
450 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000451 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
452 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000453def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
454 (ins GR64:$src1, i64i32imm:$src2),
455 "sub{q}\t{$src2, $dst|$dst, $src2}",
456 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
457 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458} // isTwoAddress
459
Bill Wendlingae034ed2008-12-12 00:56:36 +0000460// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000461def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000462 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000463 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
464 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000465
466// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000467def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000468 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000469 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000470 addr:$dst),
471 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000472def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
473 "sub{q}\t{$src2, $dst|$dst, $src2}",
474 [(store (sub (load addr:$dst), i64immSExt32:$src2),
475 addr:$dst),
476 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477
Evan Cheng259471d2007-10-05 17:59:57 +0000478let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000479let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000480def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000481 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000482 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483
Dale Johannesen747fe522009-06-02 03:12:52 +0000484def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000485 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000486 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487
Dale Johannesen747fe522009-06-02 03:12:52 +0000488def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000490 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
491def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000492 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000493 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494} // isTwoAddress
495
Evan Chengb783fa32007-07-19 01:14:50 +0000496def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000497 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000498 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000499def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000501 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000502def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
503 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000504 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000505} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000506} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507
508// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000509let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000510def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000511 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000512let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000513def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000514 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515
516// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000517def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000518 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000519let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000520def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000521 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
522}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523
Evan Cheng55687072007-09-14 21:48:26 +0000524let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525let isTwoAddress = 1 in {
526let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000527// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000528def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
529 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000530 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000531 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
532 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533
Bill Wendlingf5399032008-12-12 21:15:41 +0000534// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000535def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
536 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000537 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000538 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
539 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540} // isTwoAddress
541
542// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000543
Bill Wendlingf5399032008-12-12 21:15:41 +0000544// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000546 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000547 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000548 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
549 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000550def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
551 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
552 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
553 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
554 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000555
Bill Wendlingf5399032008-12-12 21:15:41 +0000556// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000558 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000559 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000560 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000561 i64immSExt8:$src2)),
562 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000563def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
564 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
565 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
566 [(set GR64:$dst, (mul (load addr:$src1),
567 i64immSExt32:$src2)),
568 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000569} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
571// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000572let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000573def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000574 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000576def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000577 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000578let mayLoad = 1 in {
579def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
580 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000581def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000582 "idiv{q}\t$src", []>;
583}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000584}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585
586// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000587let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000589def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000590 [(set GR64:$dst, (ineg GR64:$src)),
591 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000592def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000593 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
594 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000595
596let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000597def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000598 [(set GR64:$dst, (add GR64:$src, 1)),
599 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000600def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000601 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
602 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000603
604let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000605def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000606 [(set GR64:$dst, (add GR64:$src, -1)),
607 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000608def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000609 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
610 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611
612// In 64-bit mode, single byte INC and DEC cannot be encoded.
613let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
614// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000615def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000616 [(set GR16:$dst, (add GR16:$src, 1)),
617 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000619def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000620 [(set GR32:$dst, (add GR32:$src, 1)),
621 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000623def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000624 [(set GR16:$dst, (add GR16:$src, -1)),
625 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000627def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000628 [(set GR32:$dst, (add GR32:$src, -1)),
629 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630 Requires<[In64BitMode]>;
631} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000632
633// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
634// how to unfold them.
635let isTwoAddress = 0, CodeSize = 2 in {
636 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000637 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
638 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000639 OpSize, Requires<[In64BitMode]>;
640 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000641 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
642 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000643 Requires<[In64BitMode]>;
644 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000645 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
646 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000647 OpSize, Requires<[In64BitMode]>;
648 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000649 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
650 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000651 Requires<[In64BitMode]>;
652}
Evan Cheng55687072007-09-14 21:48:26 +0000653} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654
655
Evan Cheng55687072007-09-14 21:48:26 +0000656let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000657// Shift instructions
658let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000659let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000660def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000661 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000662 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000663let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000664def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000665 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000667// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
668// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669} // isTwoAddress
670
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000671let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000674 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000675def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000676 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000678def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
681
682let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000683let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000684def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000685 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000686 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000687def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000688 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000690def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
693} // isTwoAddress
694
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000695let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000698 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000699def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000700 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000702def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000703 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
705
706let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000708def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000710 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000714def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000715 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
717} // isTwoAddress
718
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000719let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000721 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000722 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000726def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000727 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
729
730// Rotate instructions
731let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000732let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000733def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000734 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000735 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000736def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000737 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000739def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
742} // isTwoAddress
743
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000745def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000747 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000751def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
754
755let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000757def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000759 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000763def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000764 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000765 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
766} // isTwoAddress
767
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000768let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000769def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000771 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000772def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000775def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000776 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
778
779// Double shift instructions (generalizations of rotate)
780let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000781let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000782def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000783 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
784 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000785def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000786 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
787 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000788}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000789
790let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
791def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000792 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000793 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
794 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
795 (i8 imm:$src3)))]>,
796 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000798 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000799 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
800 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
801 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000802 TB;
803} // isCommutable
804} // isTwoAddress
805
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000806let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000807def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000808 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
809 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
810 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000811def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000812 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
813 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
814 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000815}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000817 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000818 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
819 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
820 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 TB;
822def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000823 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000824 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
825 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
826 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000828} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829
830//===----------------------------------------------------------------------===//
831// Logical Instructions...
832//
833
Evan Cheng5b51c242009-01-21 19:45:31 +0000834let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000835def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000837def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
839
Evan Cheng55687072007-09-14 21:48:26 +0000840let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841let isTwoAddress = 1 in {
842let isCommutable = 1 in
843def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000844 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000845 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000846 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
847 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000849 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000850 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000851 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
852 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000854 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000855 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000856 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
857 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000858def AND64ri32 : RIi32<0x81, MRM4r,
859 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
860 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000861 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
862 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000863} // isTwoAddress
864
865def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000866 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000867 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000868 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
869 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000871 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000872 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000873 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
874 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000875def AND64mi32 : RIi32<0x81, MRM4m,
876 (outs), (ins i64mem:$dst, i64i32imm:$src),
877 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
879 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880
881let isTwoAddress = 1 in {
882let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000883def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000884 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000885 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
886 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000887def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000889 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
890 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000891def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000892 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000893 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
894 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000895def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
896 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000897 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
898 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899} // isTwoAddress
900
Evan Chengb783fa32007-07-19 01:14:50 +0000901def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000902 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000903 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
904 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000905def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000906 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000907 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
908 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000909def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
910 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000911 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
912 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913
914let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000915let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000916def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000917 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000918 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
919 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000920def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000921 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000922 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
923 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000924def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
925 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000926 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
927 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000928def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000929 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000930 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000931 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
932 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000933} // isTwoAddress
934
Evan Chengb783fa32007-07-19 01:14:50 +0000935def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000937 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
938 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000939def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000941 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
942 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000943def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
944 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000945 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
946 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000947} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948
949//===----------------------------------------------------------------------===//
950// Comparison Instructions...
951//
952
953// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000954let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000956def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000957 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000958 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
959 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000960def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000962 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
963 (implicit EFLAGS)]>;
964def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
965 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000966 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000967 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
968 (implicit EFLAGS)]>;
969def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
970 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000972 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
973 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000974
Evan Chengb783fa32007-07-19 01:14:50 +0000975def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000977 [(X86cmp GR64:$src1, GR64:$src2),
978 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000979def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000981 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
982 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000983def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000984 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000985 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
986 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000987def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
988 "cmp{q}\t{$src2, $src1|$src1, $src2}",
989 [(X86cmp GR64:$src1, i64immSExt8:$src2),
990 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000991def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000992 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000993 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000994 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000995def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000996 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000997 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000998 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000999def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1000 (ins i64mem:$src1, i64i32imm:$src2),
1001 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1002 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1003 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001004} // Defs = [EFLAGS]
1005
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001006// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001007// TODO: BTC, BTR, and BTS
1008let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001009def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001010 "bt{q}\t{$src2, $src1|$src1, $src2}",
1011 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001012 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001013
1014// Unlike with the register+register form, the memory+register form of the
1015// bt instruction does not ignore the high bits of the index. From ISel's
1016// perspective, this is pretty bizarre. Disable these instructions for now.
1017//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1018// "bt{q}\t{$src2, $src1|$src1, $src2}",
1019// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1020// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001021
1022def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1023 "bt{q}\t{$src2, $src1|$src1, $src2}",
1024 [(X86bt GR64:$src1, i64immSExt8:$src2),
1025 (implicit EFLAGS)]>, TB;
1026// Note that these instructions don't need FastBTMem because that
1027// only applies when the other operand is in a register. When it's
1028// an immediate, bt is still fast.
1029def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1030 "bt{q}\t{$src2, $src1|$src1, $src2}",
1031 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1032 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001033} // Defs = [EFLAGS]
1034
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001036let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001037let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001039 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001042 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001044 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001045 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001047 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001049 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001050 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001052 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001054 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001055 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001057 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001059 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001060 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001062 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001064 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001065 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001067 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001068def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001069 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001070 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001072 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001074 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001075 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001077 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001079 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001080 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001082 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001084 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001085 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001087 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001089 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001090 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001092 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001094 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001097 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001099 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001100 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001102 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001104 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001105 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001107 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001108def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1109 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1110 "cmovo\t{$src2, $dst|$dst, $src2}",
1111 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1112 X86_COND_O, EFLAGS))]>, TB;
1113def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1114 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1115 "cmovno\t{$src2, $dst|$dst, $src2}",
1116 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1117 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001118} // isCommutable = 1
1119
1120def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1121 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1122 "cmovb\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1124 X86_COND_B, EFLAGS))]>, TB;
1125def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1126 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1127 "cmovae\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1129 X86_COND_AE, EFLAGS))]>, TB;
1130def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1131 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1132 "cmove\t{$src2, $dst|$dst, $src2}",
1133 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1134 X86_COND_E, EFLAGS))]>, TB;
1135def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1136 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1137 "cmovne\t{$src2, $dst|$dst, $src2}",
1138 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1139 X86_COND_NE, EFLAGS))]>, TB;
1140def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1141 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1142 "cmovbe\t{$src2, $dst|$dst, $src2}",
1143 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1144 X86_COND_BE, EFLAGS))]>, TB;
1145def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1146 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1147 "cmova\t{$src2, $dst|$dst, $src2}",
1148 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1149 X86_COND_A, EFLAGS))]>, TB;
1150def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1151 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1152 "cmovl\t{$src2, $dst|$dst, $src2}",
1153 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1154 X86_COND_L, EFLAGS))]>, TB;
1155def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1156 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1157 "cmovge\t{$src2, $dst|$dst, $src2}",
1158 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1159 X86_COND_GE, EFLAGS))]>, TB;
1160def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1161 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1162 "cmovle\t{$src2, $dst|$dst, $src2}",
1163 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1164 X86_COND_LE, EFLAGS))]>, TB;
1165def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1166 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1167 "cmovg\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1169 X86_COND_G, EFLAGS))]>, TB;
1170def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1171 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1172 "cmovs\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1174 X86_COND_S, EFLAGS))]>, TB;
1175def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1176 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1177 "cmovns\t{$src2, $dst|$dst, $src2}",
1178 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1179 X86_COND_NS, EFLAGS))]>, TB;
1180def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1181 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1182 "cmovp\t{$src2, $dst|$dst, $src2}",
1183 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1184 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001186 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001187 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001188 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001189 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001190def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1191 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1192 "cmovo\t{$src2, $dst|$dst, $src2}",
1193 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1194 X86_COND_O, EFLAGS))]>, TB;
1195def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1196 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1197 "cmovno\t{$src2, $dst|$dst, $src2}",
1198 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1199 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200} // isTwoAddress
1201
1202//===----------------------------------------------------------------------===//
1203// Conversion Instructions...
1204//
1205
1206// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001207def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001208 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001209 [(set GR64:$dst,
1210 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001211def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001212 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001213 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1214 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001215def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001216 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001217 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001218def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001221def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001222 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001223 [(set GR64:$dst,
1224 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001225def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001226 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001227 [(set GR64:$dst,
1228 (int_x86_sse2_cvttsd2si64
1229 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230
1231// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001232def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001233 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001235def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001236 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001237 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001238
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001239let isTwoAddress = 1 in {
1240def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001241 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001242 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001243 [(set VR128:$dst,
1244 (int_x86_sse2_cvtsi642sd VR128:$src1,
1245 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001246def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001247 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001249 [(set VR128:$dst,
1250 (int_x86_sse2_cvtsi642sd VR128:$src1,
1251 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001252} // isTwoAddress
1253
1254// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001255def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001256 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001257 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001258def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001259 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001261
1262let isTwoAddress = 1 in {
1263 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1264 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1265 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1266 [(set VR128:$dst,
1267 (int_x86_sse_cvtsi642ss VR128:$src1,
1268 GR64:$src2))]>;
1269 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1270 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1271 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1272 [(set VR128:$dst,
1273 (int_x86_sse_cvtsi642ss VR128:$src1,
1274 (loadi64 addr:$src2)))]>;
1275}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001276
1277// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001278def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001279 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001280 [(set GR64:$dst,
1281 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001282def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001283 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001284 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1285 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001286def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001287 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001288 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001289def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001290 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001291 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001292def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001293 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001294 [(set GR64:$dst,
1295 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001296def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001298 [(set GR64:$dst,
1299 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1300
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301//===----------------------------------------------------------------------===//
1302// Alias Instructions
1303//===----------------------------------------------------------------------===//
1304
Dan Gohman027cd112007-09-17 14:55:08 +00001305// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1306// equivalent due to implicit zero-extending, and it sometimes has a smaller
1307// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001308// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1309// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1310// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001311let Defs = [EFLAGS], AddedComplexity = 1,
1312 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001313def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1314 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1315 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001316
1317// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001318let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001319def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001320 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001321 [(set GR64:$dst, i64immZExt32:$src)]>;
1322
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001323//===----------------------------------------------------------------------===//
1324// Thread Local Storage Instructions
1325//===----------------------------------------------------------------------===//
1326
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001327// All calls clobber the non-callee saved registers. RSP is marked as
1328// a use to prevent stack-pointer assignments that appear immediately
1329// before calls from potentially appearing dead.
1330let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1331 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1332 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1333 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1334 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1335 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001336def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001337 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001338 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001339 ".word\t0x6666; "
1340 "rex64; "
1341 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001342 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001343 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001344
sampo9cc09a32009-01-26 01:24:32 +00001345let AddedComplexity = 5 in
1346def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1347 "movq\t%gs:$src, $dst",
1348 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1349
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001350let AddedComplexity = 5 in
1351def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1352 "movq\t%fs:$src, $dst",
1353 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1354
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001355//===----------------------------------------------------------------------===//
1356// Atomic Instructions
1357//===----------------------------------------------------------------------===//
1358
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001359let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001360def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001361 "lock\n\t"
1362 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001363 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1364}
1365
Dan Gohmana41a1c092008-08-06 15:52:50 +00001366let Constraints = "$val = $dst" in {
1367let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001368def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001369 "lock\n\t"
1370 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001371 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001372 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001373def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001374 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001375 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001376}
1377
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001378// Atomic exchange, and, or, xor
1379let Constraints = "$val = $dst", Defs = [EFLAGS],
1380 usesCustomDAGSchedInserter = 1 in {
1381def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001382 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001383 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001384def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001385 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001386 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001387def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001388 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001389 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001390def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001391 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001392 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001393def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001394 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001395 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001396def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001397 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001398 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001399def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001400 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001401 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001402def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001403 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001404 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001405}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001406
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001407//===----------------------------------------------------------------------===//
1408// Non-Instruction Patterns
1409//===----------------------------------------------------------------------===//
1410
Chris Lattner0d2dad62009-07-11 22:50:33 +00001411// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1412// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1413// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001414def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1415 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1416def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1417 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1418def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1419 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1420def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1421 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1422
Chris Lattnerc04cd042009-07-11 23:17:29 +00001423// In static codegen with small code model, we can get the address of a label
1424// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1425// the MOV64ri64i32 should accept these.
1426def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1427 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1428def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1429 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1430def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1431 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1432def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1433 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1434
1435
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001436// If we have small model and -static mode, it is safe to store global addresses
1437// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001438// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001439def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1440 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001441 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1443 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001444 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001445def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1446 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001447 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001448def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1449 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001450 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451
1452// Calls
1453// Direct PC relative function call for small code model. 32-bit displacement
1454// sign extended to 64-bit.
1455def : Pat<(X86call (i64 tglobaladdr:$dst)),
1456 (CALL64pcrel32 tglobaladdr:$dst)>;
1457def : Pat<(X86call (i64 texternalsym:$dst)),
1458 (CALL64pcrel32 texternalsym:$dst)>;
1459
1460def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1461 (CALL64pcrel32 tglobaladdr:$dst)>;
1462def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1463 (CALL64pcrel32 texternalsym:$dst)>;
1464
1465def : Pat<(X86tailcall GR64:$dst),
1466 (CALL64r GR64:$dst)>;
1467
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001468
1469// tailcall stuff
1470def : Pat<(X86tailcall GR32:$dst),
1471 (TAILCALL)>;
1472def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1473 (TAILCALL)>;
1474def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1475 (TAILCALL)>;
1476
1477def : Pat<(X86tcret GR64:$dst, imm:$off),
1478 (TCRETURNri64 GR64:$dst, imm:$off)>;
1479
1480def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1481 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1482
1483def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1484 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1485
Dan Gohmanec596042007-09-17 14:35:24 +00001486// Comparisons.
1487
1488// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001489def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001490 (TEST64rr GR64:$src1, GR64:$src1)>;
1491
Dan Gohman0a3c5222009-01-07 01:00:24 +00001492// Conditional moves with folded loads with operands swapped and conditions
1493// inverted.
1494def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1495 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1496def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1497 (CMOVB64rm GR64:$src2, addr:$src1)>;
1498def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1499 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1500def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1501 (CMOVE64rm GR64:$src2, addr:$src1)>;
1502def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1503 (CMOVA64rm GR64:$src2, addr:$src1)>;
1504def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1505 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1506def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1507 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1508def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1509 (CMOVL64rm GR64:$src2, addr:$src1)>;
1510def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1511 (CMOVG64rm GR64:$src2, addr:$src1)>;
1512def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1513 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1514def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1515 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1516def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1517 (CMOVP64rm GR64:$src2, addr:$src1)>;
1518def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1519 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1520def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1521 (CMOVS64rm GR64:$src2, addr:$src1)>;
1522def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1523 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1524def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1525 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001526
Duncan Sands082524c2008-01-23 20:39:46 +00001527// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001528def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1529
1530// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001531// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1532// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1533// partial-register updates.
1534def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1535def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1536def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1537// For other extloads, use subregs, since the high contents of the register are
1538// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001539def : Pat<(extloadi64i32 addr:$src),
1540 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1541 x86_subreg_32bit)>;
1542def : Pat<(extloadi16i1 addr:$src),
1543 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1544 x86_subreg_8bit)>,
1545 Requires<[In64BitMode]>;
1546def : Pat<(extloadi16i8 addr:$src),
1547 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1548 x86_subreg_8bit)>,
1549 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001550
Dan Gohmandd612bb2008-08-20 21:27:32 +00001551// anyext
1552def : Pat<(i64 (anyext GR8:$src)),
1553 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1554def : Pat<(i64 (anyext GR16:$src)),
1555 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001556def : Pat<(i64 (anyext GR32:$src)),
1557 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001558def : Pat<(i16 (anyext GR8:$src)),
1559 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1560 Requires<[In64BitMode]>;
1561def : Pat<(i32 (anyext GR8:$src)),
1562 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1563 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001564
1565//===----------------------------------------------------------------------===//
1566// Some peepholes
1567//===----------------------------------------------------------------------===//
1568
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001569// Odd encoding trick: -128 fits into an 8-bit immediate field while
1570// +128 doesn't, so in this special case use a sub instead of an add.
1571def : Pat<(add GR64:$src1, 128),
1572 (SUB64ri8 GR64:$src1, -128)>;
1573def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1574 (SUB64mi8 addr:$dst, -128)>;
1575
1576// The same trick applies for 32-bit immediate fields in 64-bit
1577// instructions.
1578def : Pat<(add GR64:$src1, 0x0000000080000000),
1579 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1580def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1581 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1582
Dan Gohman47a419d2008-08-07 02:54:50 +00001583// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001584def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001585 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001586// r & (2^16-1) ==> movz
1587def : Pat<(and GR64:$src, 0xffff),
1588 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1589// r & (2^8-1) ==> movz
1590def : Pat<(and GR64:$src, 0xff),
1591 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001592// r & (2^8-1) ==> movz
1593def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001594 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001595 Requires<[In64BitMode]>;
1596// r & (2^8-1) ==> movz
1597def : Pat<(and GR16:$src1, 0xff),
1598 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1599 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001600
Dan Gohmandd612bb2008-08-20 21:27:32 +00001601// sext_inreg patterns
1602def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001603 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001604def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001605 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001606def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001607 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001608def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001609 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001610 Requires<[In64BitMode]>;
1611def : Pat<(sext_inreg GR16:$src, i8),
1612 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1613 Requires<[In64BitMode]>;
1614
1615// trunc patterns
1616def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001617 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001618def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001619 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001620def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001621 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001622def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001623 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001624 Requires<[In64BitMode]>;
1625def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001626 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1627 Requires<[In64BitMode]>;
1628
1629// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001630// For now, be conservative on x86-64 and use an h-register extract only if the
1631// value is immediately zero-extended or stored, which are somewhat common
1632// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1633// from being allocated in the same instruction as the h register, as there's
1634// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001635
1636// h-register extract and zero-extend.
1637def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1638 (SUBREG_TO_REG
1639 (i64 0),
1640 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001641 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001642 x86_subreg_8bit_hi)),
1643 x86_subreg_32bit)>;
1644def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1645 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001646 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001647 x86_subreg_8bit_hi))>,
1648 Requires<[In64BitMode]>;
1649def : Pat<(srl_su GR16:$src, (i8 8)),
1650 (EXTRACT_SUBREG
1651 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001652 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001653 x86_subreg_8bit_hi)),
1654 x86_subreg_16bit)>,
1655 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001656def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1657 (MOVZX32_NOREXrr8
1658 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1659 x86_subreg_8bit_hi))>,
1660 Requires<[In64BitMode]>;
1661def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1662 (SUBREG_TO_REG
1663 (i64 0),
1664 (MOVZX32_NOREXrr8
1665 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1666 x86_subreg_8bit_hi)),
1667 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001668
1669// h-register extract and store.
1670def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1671 (MOV8mr_NOREX
1672 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001673 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001674 x86_subreg_8bit_hi))>;
1675def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1676 (MOV8mr_NOREX
1677 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001678 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001679 x86_subreg_8bit_hi))>,
1680 Requires<[In64BitMode]>;
1681def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1682 (MOV8mr_NOREX
1683 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001684 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001685 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001686 Requires<[In64BitMode]>;
1687
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001688// (shl x, 1) ==> (add x, x)
1689def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1690
Evan Cheng76a64c72008-08-30 02:03:58 +00001691// (shl x (and y, 63)) ==> (shl x, y)
1692def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1693 (SHL64rCL GR64:$src1)>;
1694def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1695 (SHL64mCL addr:$dst)>;
1696
1697def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1698 (SHR64rCL GR64:$src1)>;
1699def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1700 (SHR64mCL addr:$dst)>;
1701
1702def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1703 (SAR64rCL GR64:$src1)>;
1704def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1705 (SAR64mCL addr:$dst)>;
1706
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001707// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1708def : Pat<(or (srl GR64:$src1, CL:$amt),
1709 (shl GR64:$src2, (sub 64, CL:$amt))),
1710 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1711
1712def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1713 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1714 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1715
Dan Gohman921581d2008-10-17 01:23:35 +00001716def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1717 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1718 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1719
1720def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1721 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1722 addr:$dst),
1723 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1724
1725def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1726 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1727
1728def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1729 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1730 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1731
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001732// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1733def : Pat<(or (shl GR64:$src1, CL:$amt),
1734 (srl GR64:$src2, (sub 64, CL:$amt))),
1735 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1736
1737def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1738 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1739 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1740
Dan Gohman921581d2008-10-17 01:23:35 +00001741def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1742 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1743 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1744
1745def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1746 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1747 addr:$dst),
1748 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1749
1750def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1751 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1752
1753def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1754 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1755 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1756
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001757// X86 specific add which produces a flag.
1758def : Pat<(addc GR64:$src1, GR64:$src2),
1759 (ADD64rr GR64:$src1, GR64:$src2)>;
1760def : Pat<(addc GR64:$src1, (load addr:$src2)),
1761 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001762def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1763 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001764def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1765 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001766
1767def : Pat<(subc GR64:$src1, GR64:$src2),
1768 (SUB64rr GR64:$src1, GR64:$src2)>;
1769def : Pat<(subc GR64:$src1, (load addr:$src2)),
1770 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001771def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1772 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001773def : Pat<(subc GR64:$src1, imm:$src2),
1774 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001775
Bill Wendlingf5399032008-12-12 21:15:41 +00001776//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001777// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001778//===----------------------------------------------------------------------===//
1779
Dan Gohman99a12192009-03-04 19:44:21 +00001780// Register-Register Addition with EFLAGS result
1781def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001782 (implicit EFLAGS)),
1783 (ADD64rr GR64:$src1, GR64:$src2)>;
1784
Dan Gohman99a12192009-03-04 19:44:21 +00001785// Register-Integer Addition with EFLAGS result
1786def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001787 (implicit EFLAGS)),
1788 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001789def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001790 (implicit EFLAGS)),
1791 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001792
Dan Gohman99a12192009-03-04 19:44:21 +00001793// Register-Memory Addition with EFLAGS result
1794def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001795 (implicit EFLAGS)),
1796 (ADD64rm GR64:$src1, addr:$src2)>;
1797
Dan Gohman99a12192009-03-04 19:44:21 +00001798// Memory-Register Addition with EFLAGS result
1799def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001800 addr:$dst),
1801 (implicit EFLAGS)),
1802 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001803def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001804 addr:$dst),
1805 (implicit EFLAGS)),
1806 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001807def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001808 addr:$dst),
1809 (implicit EFLAGS)),
1810 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001811
Dan Gohman99a12192009-03-04 19:44:21 +00001812// Register-Register Subtraction with EFLAGS result
1813def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001814 (implicit EFLAGS)),
1815 (SUB64rr GR64:$src1, GR64:$src2)>;
1816
Dan Gohman99a12192009-03-04 19:44:21 +00001817// Register-Memory Subtraction with EFLAGS result
1818def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001819 (implicit EFLAGS)),
1820 (SUB64rm GR64:$src1, addr:$src2)>;
1821
Dan Gohman99a12192009-03-04 19:44:21 +00001822// Register-Integer Subtraction with EFLAGS result
1823def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001824 (implicit EFLAGS)),
1825 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001826def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001827 (implicit EFLAGS)),
1828 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001829
Dan Gohman99a12192009-03-04 19:44:21 +00001830// Memory-Register Subtraction with EFLAGS result
1831def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001832 addr:$dst),
1833 (implicit EFLAGS)),
1834 (SUB64mr addr:$dst, GR64:$src2)>;
1835
Dan Gohman99a12192009-03-04 19:44:21 +00001836// Memory-Integer Subtraction with EFLAGS result
1837def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001838 addr:$dst),
1839 (implicit EFLAGS)),
1840 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001841def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001842 addr:$dst),
1843 (implicit EFLAGS)),
1844 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001845
Dan Gohman99a12192009-03-04 19:44:21 +00001846// Register-Register Signed Integer Multiplication with EFLAGS result
1847def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001848 (implicit EFLAGS)),
1849 (IMUL64rr GR64:$src1, GR64:$src2)>;
1850
Dan Gohman99a12192009-03-04 19:44:21 +00001851// Register-Memory Signed Integer Multiplication with EFLAGS result
1852def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001853 (implicit EFLAGS)),
1854 (IMUL64rm GR64:$src1, addr:$src2)>;
1855
Dan Gohman99a12192009-03-04 19:44:21 +00001856// Register-Integer Signed Integer Multiplication with EFLAGS result
1857def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001858 (implicit EFLAGS)),
1859 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001860def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001861 (implicit EFLAGS)),
1862 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001863
Dan Gohman99a12192009-03-04 19:44:21 +00001864// Memory-Integer Signed Integer Multiplication with EFLAGS result
1865def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001866 (implicit EFLAGS)),
1867 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001868def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001869 (implicit EFLAGS)),
1870 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001871
Dan Gohman99a12192009-03-04 19:44:21 +00001872// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001873def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1874 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1875def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1876 (implicit EFLAGS)),
1877 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1878def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1879 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1880def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1881 (implicit EFLAGS)),
1882 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1883
1884def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1885 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1886def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1887 (implicit EFLAGS)),
1888 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1889def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1890 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1891def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1892 (implicit EFLAGS)),
1893 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1894
Dan Gohman99a12192009-03-04 19:44:21 +00001895def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1896 (INC64r GR64:$src)>;
1897def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1898 (implicit EFLAGS)),
1899 (INC64m addr:$dst)>;
1900def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1901 (DEC64r GR64:$src)>;
1902def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1903 (implicit EFLAGS)),
1904 (DEC64m addr:$dst)>;
1905
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001906//===----------------------------------------------------------------------===//
1907// X86-64 SSE Instructions
1908//===----------------------------------------------------------------------===//
1909
1910// Move instructions...
1911
Evan Chengb783fa32007-07-19 01:14:50 +00001912def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001913 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914 [(set VR128:$dst,
1915 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001916def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$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, (vector_extract (v2i64 VR128:$src),
1919 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001920
Evan Chengb783fa32007-07-19 01:14:50 +00001921def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001922 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001923 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001924def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001925 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001926 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1927
Evan Chengb783fa32007-07-19 01:14:50 +00001928def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001929 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001930 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001931def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001932 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001933 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001934
1935//===----------------------------------------------------------------------===//
1936// X86-64 SSE4.1 Instructions
1937//===----------------------------------------------------------------------===//
1938
Nate Begeman4294c1f2008-02-12 22:51:28 +00001939/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1940multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001941 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001942 (ins VR128:$src1, i32i8imm:$src2),
1943 !strconcat(OpcodeStr,
1944 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1945 [(set GR64:$dst,
1946 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001947 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001948 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1949 !strconcat(OpcodeStr,
1950 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1951 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1952 addr:$dst)]>, OpSize, REX_W;
1953}
1954
1955defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1956
1957let isTwoAddress = 1 in {
1958 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001959 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001960 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1961 !strconcat(OpcodeStr,
1962 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1963 [(set VR128:$dst,
1964 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1965 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001966 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001967 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1968 !strconcat(OpcodeStr,
1969 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1970 [(set VR128:$dst,
1971 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1972 imm:$src3)))]>, OpSize, REX_W;
1973 }
1974}
1975
1976defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;