blob: 0544d362c3d82c4f74fb4a6f8bebf4d7b5867f76 [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",
Evan Chengc3495762009-03-30 21:36:47 +000048 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
49 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
51//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000052// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053//
54
Dan Gohmand16fdc02008-12-19 18:25:21 +000055def i64immSExt8 : PatLeaf<(i64 imm), [{
56 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
57 // sign extended field.
58 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
59}]>;
60
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061def i64immSExt32 : PatLeaf<(i64 imm), [{
62 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
63 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000064 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065}]>;
66
67def i64immZExt32 : PatLeaf<(i64 imm), [{
68 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
69 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000070 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071}]>;
72
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
74def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
75def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
76
77def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
78def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
79def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
80def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
81
82def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
83def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
84def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
85def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
86
87//===----------------------------------------------------------------------===//
88// Instruction list...
89//
90
Dan Gohman01c9f772008-10-01 18:28:06 +000091// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
92// a stack adjustment and the codegen must know that they may modify the stack
93// pointer before prolog-epilog rewriting occurs.
94// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
95// sub / add which can clobber EFLAGS.
96let Defs = [RSP, EFLAGS], Uses = [RSP] in {
97def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
98 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000099 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000100 Requires<[In64BitMode]>;
101def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
102 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000103 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000104 Requires<[In64BitMode]>;
105}
106
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000107//===----------------------------------------------------------------------===//
108// Call Instructions...
109//
Evan Cheng37e7c752007-07-21 00:34:19 +0000110let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000111 // All calls clobber the non-callee saved registers. RSP is marked as
112 // a use to prevent stack-pointer assignments that appear immediately
113 // before calls from potentially appearing dead. Uses for argument
114 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000116 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000117 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
118 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000119 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
120 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000121
122 // NOTE: this pattern doesn't match "X86call imm", because we do not know
123 // that the offset between an arbitrary immediate and the call will fit in
124 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000125 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000126 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
127 "call\t$dst", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000128 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000129 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000130 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000131 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000132 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 }
134
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000135
136
137let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000138def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
139 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000140 "#TC_RETURN $dst $offset",
141 []>;
142
143let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000144def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
145 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000146 "#TC_RETURN $dst $offset",
147 []>;
148
149
150let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000151 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
152 "jmp{q}\t{*}$dst # TAILCALL",
153 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000154
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000156let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000157 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000159 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160 [(brind (loadi64 addr:$dst))]>;
161}
162
163//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000164// EH Pseudo Instructions
165//
166let isTerminator = 1, isReturn = 1, isBarrier = 1,
167 hasCtrlDep = 1 in {
168def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
169 "ret\t#eh_return, addr: $addr",
170 [(X86ehret GR64:$addr)]>;
171
172}
173
174//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175// Miscellaneous Instructions...
176//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000177let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000179 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000180let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
181let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000183 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000184let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000186 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
187}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188
Bill Wendling4c2638c2009-06-15 19:39:04 +0000189let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
190def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000191 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000192def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000193 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000194def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000195 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000196}
197
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000198let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000199def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000200let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000201def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000202
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000204 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000205 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
207
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000208let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000209def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000210 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211 [(set GR64:$dst, lea64addr:$src)]>;
212
213let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000214def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000215 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
Evan Cheng48679f42007-12-14 02:13:44 +0000218// Bit scan instructions.
219let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000220def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000221 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000222 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000223def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$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 (loadi64 addr:$src))),
226 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000227
Evan Cheng4e33de92007-12-14 18:49:43 +0000228def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000229 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000230 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000231def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$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 (loadi64 addr:$src))),
234 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000235} // Defs = [EFLAGS]
236
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000238let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000239def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000240 [(X86rep_movs i64)]>, REP;
241let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000242def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000243 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244
245//===----------------------------------------------------------------------===//
246// Move Instructions...
247//
248
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000249let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000250def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000251 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252
Evan Chengd2b9d302008-06-25 01:16:38 +0000253let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000254def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000255 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000257def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000258 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000260}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261
Dan Gohman5574cc72008-12-03 18:15:48 +0000262let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000263def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000264 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265 [(set GR64:$dst, (load addr:$src))]>;
266
Evan Chengb783fa32007-07-19 01:14:50 +0000267def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000268 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000270def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$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 i64immSExt32:$src, addr:$dst)]>;
273
274// Sign/Zero extenders
275
Dan Gohmanedde1992009-04-13 15:13:28 +0000276// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
277// operand, which makes it a rare instruction with an 8-bit register
278// operand that can never access an h register. If support for h registers
279// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000280def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000281 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000283def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$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, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000286def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000287 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000289def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$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, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000292def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000293 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000295def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$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, (sextloadi64i32 addr:$src))]>;
298
Dan Gohman9203ab42008-07-30 18:09:17 +0000299// Use movzbl instead of movzbq when the destination is a register; it's
300// equivalent due to implicit zero-extending, and it has a smaller encoding.
301def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
302 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
303 [(set GR64:$dst, (zext GR8:$src))]>, TB;
304def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
305 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
307// Use movzwl instead of movzwq when the destination is a register; it's
308// equivalent due to implicit zero-extending, and it has a smaller encoding.
309def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
310 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
311 [(set GR64:$dst, (zext GR16:$src))]>, TB;
312def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
313 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
314 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315
Dan Gohman47a419d2008-08-07 02:54:50 +0000316// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000317// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
318// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
319// zero-extension, however this isn't possible when the 32-bit value is
320// defined by a truncate or is copied from something where the high bits aren't
321// necessarily all zero. In such cases, we fall back to these explicit zext
322// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000323def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
324 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
325 [(set GR64:$dst, (zext GR32:$src))]>;
326def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
327 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
328 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
329
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000330// Any instruction that defines a 32-bit result leaves the high half of the
331// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
332// be copying from a truncate, but any other 32-bit operation will zero-extend
333// up to 64 bits.
334def def32 : PatLeaf<(i32 GR32:$src), [{
335 return N->getOpcode() != ISD::TRUNCATE &&
336 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
337 N->getOpcode() != ISD::CopyFromReg;
338}]>;
339
340// In the case of a 32-bit def that is known to implicitly zero-extend,
341// we can use a SUBREG_TO_REG.
342def : Pat<(i64 (zext def32:$src)),
343 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
344
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000345let neverHasSideEffects = 1 in {
346 let Defs = [RAX], Uses = [EAX] in
347 def CDQE : RI<0x98, RawFrm, (outs), (ins),
348 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000350 let Defs = [RAX,RDX], Uses = [RAX] in
351 def CQO : RI<0x99, RawFrm, (outs), (ins),
352 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
353}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354
355//===----------------------------------------------------------------------===//
356// Arithmetic Instructions...
357//
358
Evan Cheng55687072007-09-14 21:48:26 +0000359let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360let isTwoAddress = 1 in {
361let isConvertibleToThreeAddress = 1 in {
362let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000363// Register-Register Addition
364def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
365 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000366 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000367 (implicit EFLAGS)]>;
368
369// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000370def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
371 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000372 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
373 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000374def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
375 "add{q}\t{$src2, $dst|$dst, $src2}",
376 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
377 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378} // isConvertibleToThreeAddress
379
Bill Wendlingae034ed2008-12-12 00:56:36 +0000380// Register-Memory Addition
381def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
382 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000383 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000384 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385} // isTwoAddress
386
Bill Wendlingae034ed2008-12-12 00:56:36 +0000387// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000388def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000389 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000390 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
391 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000392def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000394 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
395 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000396def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
397 "add{q}\t{$src2, $dst|$dst, $src2}",
398 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
399 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400
Evan Cheng259471d2007-10-05 17:59:57 +0000401let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402let isTwoAddress = 1 in {
403let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000404def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000405 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000406 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407
Dale Johannesen747fe522009-06-02 03:12:52 +0000408def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000410 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411
Dale Johannesen747fe522009-06-02 03:12:52 +0000412def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000413 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000414 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
415def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000416 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000417 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418} // isTwoAddress
419
Evan Chengb783fa32007-07-19 01:14:50 +0000420def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000421 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000422 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000423def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000426def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
427 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000428 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000429} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000430
431let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000432// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000433def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000434 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000435 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
436 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000437
438// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000439def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000440 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000441 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
442 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000443
444// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000445def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
446 (ins GR64:$src1, i64i8imm:$src2),
447 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000448 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
449 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000450def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
451 (ins GR64:$src1, i64i32imm:$src2),
452 "sub{q}\t{$src2, $dst|$dst, $src2}",
453 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
454 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000455} // isTwoAddress
456
Bill Wendlingae034ed2008-12-12 00:56:36 +0000457// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000458def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000460 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
461 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000462
463// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000464def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000465 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000466 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000467 addr:$dst),
468 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000469def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
470 "sub{q}\t{$src2, $dst|$dst, $src2}",
471 [(store (sub (load addr:$dst), i64immSExt32:$src2),
472 addr:$dst),
473 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
Evan Cheng259471d2007-10-05 17:59:57 +0000475let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000477def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000479 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480
Dale Johannesen747fe522009-06-02 03:12:52 +0000481def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000482 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000483 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484
Dale Johannesen747fe522009-06-02 03:12:52 +0000485def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000487 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
488def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000490 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491} // isTwoAddress
492
Evan Chengb783fa32007-07-19 01:14:50 +0000493def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000494 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000495 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000496def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000499def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
500 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000501 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000502} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000503} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504
505// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000506let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000507def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000508 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000509let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000510def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000511 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512
513// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000514def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000515 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000516let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000517def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000518 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
519}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520
Evan Cheng55687072007-09-14 21:48:26 +0000521let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522let isTwoAddress = 1 in {
523let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000524// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000525def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
526 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000527 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000528 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
529 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530
Bill Wendlingf5399032008-12-12 21:15:41 +0000531// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000532def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
533 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000534 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000535 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
536 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537} // isTwoAddress
538
539// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000540
Bill Wendlingf5399032008-12-12 21:15:41 +0000541// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000543 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000544 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000545 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
546 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000547def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
548 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
549 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
550 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
551 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000552
Bill Wendlingf5399032008-12-12 21:15:41 +0000553// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000555 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000556 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000557 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000558 i64immSExt8:$src2)),
559 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000560def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
561 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
562 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
563 [(set GR64:$dst, (mul (load addr:$src1),
564 i64immSExt32:$src2)),
565 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000566} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567
568// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000569let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000570def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000571 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000573def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000574 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000575let mayLoad = 1 in {
576def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
577 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000578def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000579 "idiv{q}\t$src", []>;
580}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000581}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582
583// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000584let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000586def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000587 [(set GR64:$dst, (ineg GR64:$src)),
588 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000589def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000590 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
591 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592
593let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000594def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000595 [(set GR64:$dst, (add GR64:$src, 1)),
596 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000597def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000598 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
599 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600
601let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000602def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000603 [(set GR64:$dst, (add GR64:$src, -1)),
604 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000605def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000606 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
607 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608
609// In 64-bit mode, single byte INC and DEC cannot be encoded.
610let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
611// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000612def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000613 [(set GR16:$dst, (add GR16:$src, 1)),
614 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000616def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000617 [(set GR32:$dst, (add GR32:$src, 1)),
618 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000620def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000621 [(set GR16:$dst, (add GR16:$src, -1)),
622 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000624def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000625 [(set GR32:$dst, (add GR32:$src, -1)),
626 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 Requires<[In64BitMode]>;
628} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000629
630// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
631// how to unfold them.
632let isTwoAddress = 0, CodeSize = 2 in {
633 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000634 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
635 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000636 OpSize, Requires<[In64BitMode]>;
637 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000638 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
639 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000640 Requires<[In64BitMode]>;
641 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000642 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
643 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000644 OpSize, Requires<[In64BitMode]>;
645 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000646 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
647 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000648 Requires<[In64BitMode]>;
649}
Evan Cheng55687072007-09-14 21:48:26 +0000650} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651
652
Evan Cheng55687072007-09-14 21:48:26 +0000653let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654// Shift instructions
655let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000656let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000657def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000658 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000659 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000660let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000661def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000662 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000664// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
665// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666} // isTwoAddress
667
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000668let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000669def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000670 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000671 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000675def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000676 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
678
679let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000680let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000681def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000682 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000683 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000684def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000685 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000687def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000688 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
690} // isTwoAddress
691
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000692let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000693def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000694 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000695 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000699def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000700 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
702
703let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000704let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000705def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000706 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000708def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000710 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
714} // isTwoAddress
715
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000716let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000717def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000718 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000719 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000721 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
726
727// Rotate instructions
728let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000729let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000730def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000731 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000732 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000733def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000734 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000735 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000736def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000737 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
739} // isTwoAddress
740
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000742def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000743 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000744 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000745def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000746 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
751
752let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000753let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000754def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000757def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
763} // isTwoAddress
764
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000765let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000766def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000768 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000769def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000772def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
775
776// Double shift instructions (generalizations of rotate)
777let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000778let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000779def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000780 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
781 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000782def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000783 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
784 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000785}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786
787let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
788def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000789 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000790 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
791 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
792 (i8 imm:$src3)))]>,
793 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000795 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000796 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
797 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
798 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 TB;
800} // isCommutable
801} // isTwoAddress
802
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000803let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000804def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000805 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
806 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
807 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000808def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000809 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
810 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
811 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000812}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000814 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000815 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
816 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
817 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 TB;
819def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000820 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000821 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
822 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
823 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000825} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826
827//===----------------------------------------------------------------------===//
828// Logical Instructions...
829//
830
Evan Cheng5b51c242009-01-21 19:45:31 +0000831let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000832def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000834def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
836
Evan Cheng55687072007-09-14 21:48:26 +0000837let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838let isTwoAddress = 1 in {
839let isCommutable = 1 in
840def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000841 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000842 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000843 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
844 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000846 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000847 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000848 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
849 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000851 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000852 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000853 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
854 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000855def AND64ri32 : RIi32<0x81, MRM4r,
856 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
857 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000858 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
859 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860} // isTwoAddress
861
862def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000863 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000864 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000865 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
866 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000868 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000869 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000870 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
871 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000872def AND64mi32 : RIi32<0x81, MRM4m,
873 (outs), (ins i64mem:$dst, i64i32imm:$src),
874 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000875 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
876 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877
878let isTwoAddress = 1 in {
879let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000880def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000881 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000882 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
883 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000884def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000886 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
887 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000888def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000889 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000890 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
891 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000892def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
893 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000894 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
895 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000896} // isTwoAddress
897
Evan Chengb783fa32007-07-19 01:14:50 +0000898def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000899 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000900 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
901 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000902def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000903 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000904 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
905 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000906def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
907 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000908 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
909 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000910
911let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000912let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000913def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000914 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000915 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
916 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000917def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000919 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
920 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000921def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
922 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000923 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
924 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000925def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000926 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000927 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000928 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
929 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930} // isTwoAddress
931
Evan Chengb783fa32007-07-19 01:14:50 +0000932def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000933 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000934 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
935 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000936def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000938 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
939 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000940def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
941 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000942 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
943 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000944} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945
946//===----------------------------------------------------------------------===//
947// Comparison Instructions...
948//
949
950// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000951let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000953def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000955 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
956 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000957def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000958 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000959 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
960 (implicit EFLAGS)]>;
961def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
962 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000963 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000964 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
965 (implicit EFLAGS)]>;
966def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
967 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000969 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
970 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971
Evan Chengb783fa32007-07-19 01:14:50 +0000972def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000973 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000974 [(X86cmp GR64:$src1, GR64:$src2),
975 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000976def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000977 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000978 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
979 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000980def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000981 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000982 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
983 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000984def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
985 "cmp{q}\t{$src2, $src1|$src1, $src2}",
986 [(X86cmp GR64:$src1, i64immSExt8:$src2),
987 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000988def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000990 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000991 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000992def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000993 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000994 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000995 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000996def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
997 (ins i64mem:$src1, i64i32imm:$src2),
998 "cmp{q}\t{$src2, $src1|$src1, $src2}",
999 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1000 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001001} // Defs = [EFLAGS]
1002
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001003// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001004// TODO: BTC, BTR, and BTS
1005let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001006def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001007 "bt{q}\t{$src2, $src1|$src1, $src2}",
1008 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001009 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001010
1011// Unlike with the register+register form, the memory+register form of the
1012// bt instruction does not ignore the high bits of the index. From ISel's
1013// perspective, this is pretty bizarre. Disable these instructions for now.
1014//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1015// "bt{q}\t{$src2, $src1|$src1, $src2}",
1016// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1017// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001018
1019def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1020 "bt{q}\t{$src2, $src1|$src1, $src2}",
1021 [(X86bt GR64:$src1, i64immSExt8:$src2),
1022 (implicit EFLAGS)]>, TB;
1023// Note that these instructions don't need FastBTMem because that
1024// only applies when the other operand is in a register. When it's
1025// an immediate, bt is still fast.
1026def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1027 "bt{q}\t{$src2, $src1|$src1, $src2}",
1028 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1029 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001030} // Defs = [EFLAGS]
1031
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001032// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001033let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001034let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001036 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001037 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001039 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001041 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001042 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001044 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001046 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001047 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001049 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001051 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001052 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001054 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001056 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001057 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001059 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001061 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001062 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001064 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001066 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001067 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001068 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001069 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001071 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001072 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001074 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001076 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001079 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001081 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001082 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001084 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001086 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001087 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001089 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001091 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001092 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001094 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001096 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001097 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001099 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001101 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001102 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001104 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001105def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1106 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1107 "cmovo\t{$src2, $dst|$dst, $src2}",
1108 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1109 X86_COND_O, EFLAGS))]>, TB;
1110def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1111 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1112 "cmovno\t{$src2, $dst|$dst, $src2}",
1113 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1114 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001115} // isCommutable = 1
1116
1117def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1118 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1119 "cmovb\t{$src2, $dst|$dst, $src2}",
1120 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1121 X86_COND_B, EFLAGS))]>, TB;
1122def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1123 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1124 "cmovae\t{$src2, $dst|$dst, $src2}",
1125 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1126 X86_COND_AE, EFLAGS))]>, TB;
1127def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1128 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1129 "cmove\t{$src2, $dst|$dst, $src2}",
1130 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1131 X86_COND_E, EFLAGS))]>, TB;
1132def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1133 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1134 "cmovne\t{$src2, $dst|$dst, $src2}",
1135 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1136 X86_COND_NE, EFLAGS))]>, TB;
1137def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1138 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1139 "cmovbe\t{$src2, $dst|$dst, $src2}",
1140 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1141 X86_COND_BE, EFLAGS))]>, TB;
1142def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1143 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1144 "cmova\t{$src2, $dst|$dst, $src2}",
1145 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1146 X86_COND_A, EFLAGS))]>, TB;
1147def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1148 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1149 "cmovl\t{$src2, $dst|$dst, $src2}",
1150 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1151 X86_COND_L, EFLAGS))]>, TB;
1152def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1153 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1154 "cmovge\t{$src2, $dst|$dst, $src2}",
1155 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1156 X86_COND_GE, EFLAGS))]>, TB;
1157def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1158 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1159 "cmovle\t{$src2, $dst|$dst, $src2}",
1160 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1161 X86_COND_LE, EFLAGS))]>, TB;
1162def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1163 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1164 "cmovg\t{$src2, $dst|$dst, $src2}",
1165 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1166 X86_COND_G, EFLAGS))]>, TB;
1167def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1168 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1169 "cmovs\t{$src2, $dst|$dst, $src2}",
1170 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1171 X86_COND_S, EFLAGS))]>, TB;
1172def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1173 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1174 "cmovns\t{$src2, $dst|$dst, $src2}",
1175 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1176 X86_COND_NS, EFLAGS))]>, TB;
1177def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1178 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1179 "cmovp\t{$src2, $dst|$dst, $src2}",
1180 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1181 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001183 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001184 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001186 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001187def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1188 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1189 "cmovo\t{$src2, $dst|$dst, $src2}",
1190 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1191 X86_COND_O, EFLAGS))]>, TB;
1192def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1193 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1194 "cmovno\t{$src2, $dst|$dst, $src2}",
1195 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1196 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197} // isTwoAddress
1198
1199//===----------------------------------------------------------------------===//
1200// Conversion Instructions...
1201//
1202
1203// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001204def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001205 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001206 [(set GR64:$dst,
1207 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001208def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001209 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001210 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1211 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001212def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001213 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001214 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001215def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$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 (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001218def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001220 [(set GR64:$dst,
1221 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001222def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001223 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001224 [(set GR64:$dst,
1225 (int_x86_sse2_cvttsd2si64
1226 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227
1228// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001229def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001230 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001232def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$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 (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001235
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001236let isTwoAddress = 1 in {
1237def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001238 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001239 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001240 [(set VR128:$dst,
1241 (int_x86_sse2_cvtsi642sd VR128:$src1,
1242 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001244 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001245 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001246 [(set VR128:$dst,
1247 (int_x86_sse2_cvtsi642sd VR128:$src1,
1248 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249} // isTwoAddress
1250
1251// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001252def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001253 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001254 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001255def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$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 (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001258
1259let isTwoAddress = 1 in {
1260 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1261 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1262 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1263 [(set VR128:$dst,
1264 (int_x86_sse_cvtsi642ss VR128:$src1,
1265 GR64:$src2))]>;
1266 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1267 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1268 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1269 [(set VR128:$dst,
1270 (int_x86_sse_cvtsi642ss VR128:$src1,
1271 (loadi64 addr:$src2)))]>;
1272}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273
1274// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001275def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001276 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001277 [(set GR64:$dst,
1278 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001279def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001281 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1282 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001283def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001284 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001285 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001286def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$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 (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001289def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001290 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001291 [(set GR64:$dst,
1292 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001293def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001294 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001295 [(set GR64:$dst,
1296 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1297
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298//===----------------------------------------------------------------------===//
1299// Alias Instructions
1300//===----------------------------------------------------------------------===//
1301
Dan Gohman027cd112007-09-17 14:55:08 +00001302// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1303// equivalent due to implicit zero-extending, and it sometimes has a smaller
1304// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1306// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1307// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001308let Defs = [EFLAGS], AddedComplexity = 1,
1309 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001310def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1311 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1312 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313
1314// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001315let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001316def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001317 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001318 [(set GR64:$dst, i64immZExt32:$src)]>;
1319
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001320//===----------------------------------------------------------------------===//
1321// Thread Local Storage Instructions
1322//===----------------------------------------------------------------------===//
1323
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001324// All calls clobber the non-callee saved registers. RSP is marked as
1325// a use to prevent stack-pointer assignments that appear immediately
1326// before calls from potentially appearing dead.
1327let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1328 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1329 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1330 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1331 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1332 Uses = [RSP] in
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001333def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001334 ".byte\t0x66; "
1335 "leaq\t${sym:mem}(%rip), %rdi; "
1336 ".word\t0x6666; "
1337 "rex64; "
1338 "call\t__tls_get_addr@PLT",
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001339 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1340 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001341
sampo9cc09a32009-01-26 01:24:32 +00001342let AddedComplexity = 5 in
1343def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1344 "movq\t%gs:$src, $dst",
1345 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1346
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001347let AddedComplexity = 5 in
1348def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1349 "movq\t%fs:$src, $dst",
1350 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1351
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001352//===----------------------------------------------------------------------===//
1353// Atomic Instructions
1354//===----------------------------------------------------------------------===//
1355
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001356let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001357def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001358 "lock\n\t"
1359 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001360 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1361}
1362
Dan Gohmana41a1c092008-08-06 15:52:50 +00001363let Constraints = "$val = $dst" in {
1364let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001365def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001366 "lock\n\t"
1367 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001368 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001369 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001370def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001371 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001372 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001373}
1374
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001375// Atomic exchange, and, or, xor
1376let Constraints = "$val = $dst", Defs = [EFLAGS],
1377 usesCustomDAGSchedInserter = 1 in {
1378def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001379 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001380 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001381def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001382 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001383 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001384def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001385 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001386 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001387def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001388 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001389 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001390def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001391 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001392 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001393def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001394 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001395 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001396def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001397 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001398 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001399def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001400 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001401 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001402}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001403
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001404//===----------------------------------------------------------------------===//
1405// Non-Instruction Patterns
1406//===----------------------------------------------------------------------===//
1407
Bill Wendlingfef06052008-09-16 21:48:12 +00001408// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001409def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1410 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1411def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1412 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1413def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1414 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1415def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1416 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1417
1418def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1419 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001420 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001421def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1422 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001423 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001424def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1425 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001426 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001427def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1428 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Dan Gohmanb36f9f82009-06-03 00:37:20 +00001429 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001430
1431// Calls
1432// Direct PC relative function call for small code model. 32-bit displacement
1433// sign extended to 64-bit.
1434def : Pat<(X86call (i64 tglobaladdr:$dst)),
1435 (CALL64pcrel32 tglobaladdr:$dst)>;
1436def : Pat<(X86call (i64 texternalsym:$dst)),
1437 (CALL64pcrel32 texternalsym:$dst)>;
1438
1439def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1440 (CALL64pcrel32 tglobaladdr:$dst)>;
1441def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1442 (CALL64pcrel32 texternalsym:$dst)>;
1443
1444def : Pat<(X86tailcall GR64:$dst),
1445 (CALL64r GR64:$dst)>;
1446
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001447
1448// tailcall stuff
1449def : Pat<(X86tailcall GR32:$dst),
1450 (TAILCALL)>;
1451def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1452 (TAILCALL)>;
1453def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1454 (TAILCALL)>;
1455
1456def : Pat<(X86tcret GR64:$dst, imm:$off),
1457 (TCRETURNri64 GR64:$dst, imm:$off)>;
1458
1459def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1460 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1461
1462def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1463 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1464
Dan Gohmanec596042007-09-17 14:35:24 +00001465// Comparisons.
1466
1467// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001468def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001469 (TEST64rr GR64:$src1, GR64:$src1)>;
1470
Dan Gohman0a3c5222009-01-07 01:00:24 +00001471// Conditional moves with folded loads with operands swapped and conditions
1472// inverted.
1473def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1474 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1475def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1476 (CMOVB64rm GR64:$src2, addr:$src1)>;
1477def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1478 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1479def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1480 (CMOVE64rm GR64:$src2, addr:$src1)>;
1481def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1482 (CMOVA64rm GR64:$src2, addr:$src1)>;
1483def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1484 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1485def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1486 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1487def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1488 (CMOVL64rm GR64:$src2, addr:$src1)>;
1489def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1490 (CMOVG64rm GR64:$src2, addr:$src1)>;
1491def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1492 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1493def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1494 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1495def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1496 (CMOVP64rm GR64:$src2, addr:$src1)>;
1497def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1498 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1499def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1500 (CMOVS64rm GR64:$src2, addr:$src1)>;
1501def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1502 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1503def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1504 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001505
Duncan Sands082524c2008-01-23 20:39:46 +00001506// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001507def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1508
1509// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001510// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1511// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1512// partial-register updates.
1513def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1514def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1515def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1516// For other extloads, use subregs, since the high contents of the register are
1517// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001518def : Pat<(extloadi64i32 addr:$src),
1519 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1520 x86_subreg_32bit)>;
1521def : Pat<(extloadi16i1 addr:$src),
1522 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1523 x86_subreg_8bit)>,
1524 Requires<[In64BitMode]>;
1525def : Pat<(extloadi16i8 addr:$src),
1526 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1527 x86_subreg_8bit)>,
1528 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529
Dan Gohmandd612bb2008-08-20 21:27:32 +00001530// anyext
1531def : Pat<(i64 (anyext GR8:$src)),
1532 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1533def : Pat<(i64 (anyext GR16:$src)),
1534 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001535def : Pat<(i64 (anyext GR32:$src)),
1536 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001537def : Pat<(i16 (anyext GR8:$src)),
1538 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1539 Requires<[In64BitMode]>;
1540def : Pat<(i32 (anyext GR8:$src)),
1541 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1542 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001543
1544//===----------------------------------------------------------------------===//
1545// Some peepholes
1546//===----------------------------------------------------------------------===//
1547
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001548// Odd encoding trick: -128 fits into an 8-bit immediate field while
1549// +128 doesn't, so in this special case use a sub instead of an add.
1550def : Pat<(add GR64:$src1, 128),
1551 (SUB64ri8 GR64:$src1, -128)>;
1552def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1553 (SUB64mi8 addr:$dst, -128)>;
1554
1555// The same trick applies for 32-bit immediate fields in 64-bit
1556// instructions.
1557def : Pat<(add GR64:$src1, 0x0000000080000000),
1558 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1559def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1560 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1561
Dan Gohman47a419d2008-08-07 02:54:50 +00001562// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001563def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001564 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001565// r & (2^16-1) ==> movz
1566def : Pat<(and GR64:$src, 0xffff),
1567 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1568// r & (2^8-1) ==> movz
1569def : Pat<(and GR64:$src, 0xff),
1570 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001571// r & (2^8-1) ==> movz
1572def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001573 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001574 Requires<[In64BitMode]>;
1575// r & (2^8-1) ==> movz
1576def : Pat<(and GR16:$src1, 0xff),
1577 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1578 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001579
Dan Gohmandd612bb2008-08-20 21:27:32 +00001580// sext_inreg patterns
1581def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001582 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001583def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001584 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001585def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001586 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001587def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001588 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001589 Requires<[In64BitMode]>;
1590def : Pat<(sext_inreg GR16:$src, i8),
1591 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1592 Requires<[In64BitMode]>;
1593
1594// trunc patterns
1595def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001596 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001597def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001598 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001599def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001600 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001601def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001602 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001603 Requires<[In64BitMode]>;
1604def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001605 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1606 Requires<[In64BitMode]>;
1607
1608// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001609// For now, be conservative on x86-64 and use an h-register extract only if the
1610// value is immediately zero-extended or stored, which are somewhat common
1611// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1612// from being allocated in the same instruction as the h register, as there's
1613// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001614
1615// h-register extract and zero-extend.
1616def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1617 (SUBREG_TO_REG
1618 (i64 0),
1619 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001620 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001621 x86_subreg_8bit_hi)),
1622 x86_subreg_32bit)>;
1623def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1624 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001625 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001626 x86_subreg_8bit_hi))>,
1627 Requires<[In64BitMode]>;
1628def : Pat<(srl_su GR16:$src, (i8 8)),
1629 (EXTRACT_SUBREG
1630 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001631 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001632 x86_subreg_8bit_hi)),
1633 x86_subreg_16bit)>,
1634 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001635def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1636 (MOVZX32_NOREXrr8
1637 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1638 x86_subreg_8bit_hi))>,
1639 Requires<[In64BitMode]>;
1640def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1641 (SUBREG_TO_REG
1642 (i64 0),
1643 (MOVZX32_NOREXrr8
1644 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1645 x86_subreg_8bit_hi)),
1646 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001647
1648// h-register extract and store.
1649def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1650 (MOV8mr_NOREX
1651 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001652 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001653 x86_subreg_8bit_hi))>;
1654def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1655 (MOV8mr_NOREX
1656 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001657 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001658 x86_subreg_8bit_hi))>,
1659 Requires<[In64BitMode]>;
1660def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1661 (MOV8mr_NOREX
1662 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001663 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001664 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001665 Requires<[In64BitMode]>;
1666
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001667// (shl x, 1) ==> (add x, x)
1668def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1669
Evan Cheng76a64c72008-08-30 02:03:58 +00001670// (shl x (and y, 63)) ==> (shl x, y)
1671def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1672 (SHL64rCL GR64:$src1)>;
1673def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1674 (SHL64mCL addr:$dst)>;
1675
1676def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1677 (SHR64rCL GR64:$src1)>;
1678def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1679 (SHR64mCL addr:$dst)>;
1680
1681def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1682 (SAR64rCL GR64:$src1)>;
1683def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1684 (SAR64mCL addr:$dst)>;
1685
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1687def : Pat<(or (srl GR64:$src1, CL:$amt),
1688 (shl GR64:$src2, (sub 64, CL:$amt))),
1689 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1690
1691def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1692 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1693 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1694
Dan Gohman921581d2008-10-17 01:23:35 +00001695def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1696 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1697 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1698
1699def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1700 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1701 addr:$dst),
1702 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1703
1704def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1705 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1706
1707def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1708 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1709 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1710
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001711// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1712def : Pat<(or (shl GR64:$src1, CL:$amt),
1713 (srl GR64:$src2, (sub 64, CL:$amt))),
1714 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1715
1716def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1717 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1718 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1719
Dan Gohman921581d2008-10-17 01:23:35 +00001720def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1721 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1722 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1723
1724def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1725 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1726 addr:$dst),
1727 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1728
1729def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1730 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1731
1732def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1733 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1734 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1735
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001736// X86 specific add which produces a flag.
1737def : Pat<(addc GR64:$src1, GR64:$src2),
1738 (ADD64rr GR64:$src1, GR64:$src2)>;
1739def : Pat<(addc GR64:$src1, (load addr:$src2)),
1740 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001741def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1742 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001743def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1744 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001745
1746def : Pat<(subc GR64:$src1, GR64:$src2),
1747 (SUB64rr GR64:$src1, GR64:$src2)>;
1748def : Pat<(subc GR64:$src1, (load addr:$src2)),
1749 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1751 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001752def : Pat<(subc GR64:$src1, imm:$src2),
1753 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754
Bill Wendlingf5399032008-12-12 21:15:41 +00001755//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001756// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001757//===----------------------------------------------------------------------===//
1758
Dan Gohman99a12192009-03-04 19:44:21 +00001759// Register-Register Addition with EFLAGS result
1760def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001761 (implicit EFLAGS)),
1762 (ADD64rr GR64:$src1, GR64:$src2)>;
1763
Dan Gohman99a12192009-03-04 19:44:21 +00001764// Register-Integer Addition with EFLAGS result
1765def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001766 (implicit EFLAGS)),
1767 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001768def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001769 (implicit EFLAGS)),
1770 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001771
Dan Gohman99a12192009-03-04 19:44:21 +00001772// Register-Memory Addition with EFLAGS result
1773def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001774 (implicit EFLAGS)),
1775 (ADD64rm GR64:$src1, addr:$src2)>;
1776
Dan Gohman99a12192009-03-04 19:44:21 +00001777// Memory-Register Addition with EFLAGS result
1778def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001779 addr:$dst),
1780 (implicit EFLAGS)),
1781 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001782def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001783 addr:$dst),
1784 (implicit EFLAGS)),
1785 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001786def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001787 addr:$dst),
1788 (implicit EFLAGS)),
1789 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001790
Dan Gohman99a12192009-03-04 19:44:21 +00001791// Register-Register Subtraction with EFLAGS result
1792def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001793 (implicit EFLAGS)),
1794 (SUB64rr GR64:$src1, GR64:$src2)>;
1795
Dan Gohman99a12192009-03-04 19:44:21 +00001796// Register-Memory Subtraction with EFLAGS result
1797def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001798 (implicit EFLAGS)),
1799 (SUB64rm GR64:$src1, addr:$src2)>;
1800
Dan Gohman99a12192009-03-04 19:44:21 +00001801// Register-Integer Subtraction with EFLAGS result
1802def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001803 (implicit EFLAGS)),
1804 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001805def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001806 (implicit EFLAGS)),
1807 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001808
Dan Gohman99a12192009-03-04 19:44:21 +00001809// Memory-Register Subtraction with EFLAGS result
1810def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001811 addr:$dst),
1812 (implicit EFLAGS)),
1813 (SUB64mr addr:$dst, GR64:$src2)>;
1814
Dan Gohman99a12192009-03-04 19:44:21 +00001815// Memory-Integer Subtraction with EFLAGS result
1816def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001817 addr:$dst),
1818 (implicit EFLAGS)),
1819 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001820def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001821 addr:$dst),
1822 (implicit EFLAGS)),
1823 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001824
Dan Gohman99a12192009-03-04 19:44:21 +00001825// Register-Register Signed Integer Multiplication with EFLAGS result
1826def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001827 (implicit EFLAGS)),
1828 (IMUL64rr GR64:$src1, GR64:$src2)>;
1829
Dan Gohman99a12192009-03-04 19:44:21 +00001830// Register-Memory Signed Integer Multiplication with EFLAGS result
1831def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001832 (implicit EFLAGS)),
1833 (IMUL64rm GR64:$src1, addr:$src2)>;
1834
Dan Gohman99a12192009-03-04 19:44:21 +00001835// Register-Integer Signed Integer Multiplication with EFLAGS result
1836def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001837 (implicit EFLAGS)),
1838 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001839def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001840 (implicit EFLAGS)),
1841 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001842
Dan Gohman99a12192009-03-04 19:44:21 +00001843// Memory-Integer Signed Integer Multiplication with EFLAGS result
1844def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001845 (implicit EFLAGS)),
1846 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001847def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001848 (implicit EFLAGS)),
1849 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001850
Dan Gohman99a12192009-03-04 19:44:21 +00001851// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001852def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1853 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1854def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1855 (implicit EFLAGS)),
1856 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1857def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1858 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1859def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1860 (implicit EFLAGS)),
1861 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1862
1863def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1864 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1865def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1866 (implicit EFLAGS)),
1867 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1868def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1869 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1870def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1871 (implicit EFLAGS)),
1872 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1873
Dan Gohman99a12192009-03-04 19:44:21 +00001874def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1875 (INC64r GR64:$src)>;
1876def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1877 (implicit EFLAGS)),
1878 (INC64m addr:$dst)>;
1879def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1880 (DEC64r GR64:$src)>;
1881def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1882 (implicit EFLAGS)),
1883 (DEC64m addr:$dst)>;
1884
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001885//===----------------------------------------------------------------------===//
1886// X86-64 SSE Instructions
1887//===----------------------------------------------------------------------===//
1888
1889// Move instructions...
1890
Evan Chengb783fa32007-07-19 01:14:50 +00001891def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001892 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001893 [(set VR128:$dst,
1894 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001895def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001896 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001897 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1898 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001899
Evan Chengb783fa32007-07-19 01:14:50 +00001900def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001901 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001902 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001903def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001904 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001905 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1906
Evan Chengb783fa32007-07-19 01:14:50 +00001907def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001908 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001909 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001910def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001911 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001912 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001913
1914//===----------------------------------------------------------------------===//
1915// X86-64 SSE4.1 Instructions
1916//===----------------------------------------------------------------------===//
1917
Nate Begeman4294c1f2008-02-12 22:51:28 +00001918/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1919multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001920 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001921 (ins VR128:$src1, i32i8imm:$src2),
1922 !strconcat(OpcodeStr,
1923 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1924 [(set GR64:$dst,
1925 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001926 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001927 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1928 !strconcat(OpcodeStr,
1929 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1930 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1931 addr:$dst)]>, OpSize, REX_W;
1932}
1933
1934defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1935
1936let isTwoAddress = 1 in {
1937 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001938 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001939 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1940 !strconcat(OpcodeStr,
1941 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1942 [(set VR128:$dst,
1943 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1944 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001945 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001946 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1947 !strconcat(OpcodeStr,
1948 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1949 [(set VR128:$dst,
1950 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1951 imm:$src3)))]>, OpSize, REX_W;
1952 }
1953}
1954
1955defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;