blob: a221adf211fdb071afd7f6bfb6bc363924dcbe5e [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
22// 64-bits but only 8 bits are significant.
23def i64i8imm : Operand<i64>;
24
25def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000026 let PrintMethod = "printlea64mem";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
28}
29
30def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
33}
34
35//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000036// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037//
38def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Evan Chengc3495762009-03-30 21:36:47 +000039 [add, mul, X86mul_imm, shl, or, frameindex, X86Wrapper],
40 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041
42//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000043// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044//
45
Dan Gohmand16fdc02008-12-19 18:25:21 +000046def i64immSExt8 : PatLeaf<(i64 imm), [{
47 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
48 // sign extended field.
49 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
50}]>;
51
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052def i64immSExt32 : PatLeaf<(i64 imm), [{
53 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immZExt32 : PatLeaf<(i64 imm), [{
59 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
60 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
67
68def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
72
73def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
77
78//===----------------------------------------------------------------------===//
79// Instruction list...
80//
81
Dan Gohman01c9f772008-10-01 18:28:06 +000082// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83// a stack adjustment and the codegen must know that they may modify the stack
84// pointer before prolog-epilog rewriting occurs.
85// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86// sub / add which can clobber EFLAGS.
87let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
89 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000090 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000091 Requires<[In64BitMode]>;
92def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
93 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000094 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000095 Requires<[In64BitMode]>;
96}
97
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098//===----------------------------------------------------------------------===//
99// Call Instructions...
100//
Evan Cheng37e7c752007-07-21 00:34:19 +0000101let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000102 // All calls clobber the non-callee saved registers. RSP is marked as
103 // a use to prevent stack-pointer assignments that appear immediately
104 // before calls from potentially appearing dead. Uses for argument
105 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000107 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000110 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
111 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000112
113 // NOTE: this pattern doesn't match "X86call imm", because we do not know
114 // that the offset between an arbitrary immediate and the call will fit in
115 // the 32-bit pcrel field that we have.
Evan Cheng0af5a042009-03-12 18:15:39 +0000116 def CALL64pcrel32 : I<0xE8, RawFrm,
117 (outs), (ins i64i32imm:$dst, variable_ops),
Chris Lattner79552392009-03-18 00:43:52 +0000118 "call\t${dst:call}", []>,
Evan Cheng0af5a042009-03-12 18:15:39 +0000119 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000120 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000121 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000122 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000123 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 }
125
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000126
127
128let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000129def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
130 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000131 "#TC_RETURN $dst $offset",
132 []>;
133
134let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000135def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
136 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000137 "#TC_RETURN $dst $offset",
138 []>;
139
140
141let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000142 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
143 "jmp{q}\t{*}$dst # TAILCALL",
144 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000145
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000147let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000148 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000149 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000150 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 [(brind (loadi64 addr:$dst))]>;
152}
153
154//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000155// EH Pseudo Instructions
156//
157let isTerminator = 1, isReturn = 1, isBarrier = 1,
158 hasCtrlDep = 1 in {
159def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
160 "ret\t#eh_return, addr: $addr",
161 [(X86ehret GR64:$addr)]>;
162
163}
164
165//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166// Miscellaneous Instructions...
167//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000168let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000170 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000171let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
172let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000174 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000175let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000177 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
178}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000180let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000181def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000182let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000183def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000184
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000186 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000187 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
189
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000190let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000191def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000192 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 [(set GR64:$dst, lea64addr:$src)]>;
194
195let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000196def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000197 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199
Evan Cheng48679f42007-12-14 02:13:44 +0000200// Bit scan instructions.
201let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000202def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000203 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000204 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000205def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000206 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000207 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
208 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000209
Evan Cheng4e33de92007-12-14 18:49:43 +0000210def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000211 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000212 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000213def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000214 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000215 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
216 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000217} // Defs = [EFLAGS]
218
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000220let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000221def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000222 [(X86rep_movs i64)]>, REP;
223let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000224def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000225 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226
227//===----------------------------------------------------------------------===//
228// Move Instructions...
229//
230
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000231let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000232def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000233 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Evan Chengd2b9d302008-06-25 01:16:38 +0000235let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000236def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000237 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000239def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000240 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000242}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243
Dan Gohman5574cc72008-12-03 18:15:48 +0000244let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000245def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000246 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 [(set GR64:$dst, (load addr:$src))]>;
248
Evan Chengb783fa32007-07-19 01:14:50 +0000249def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000250 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000252def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000253 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 [(store i64immSExt32:$src, addr:$dst)]>;
255
256// Sign/Zero extenders
257
Dan Gohmanedde1992009-04-13 15:13:28 +0000258// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
259// operand, which makes it a rare instruction with an 8-bit register
260// operand that can never access an h register. If support for h registers
261// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000262def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000263 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000265def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000266 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000268def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000269 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000271def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000272 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000274def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000275 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000277def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000278 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
280
Dan Gohman9203ab42008-07-30 18:09:17 +0000281// Use movzbl instead of movzbq when the destination is a register; it's
282// equivalent due to implicit zero-extending, and it has a smaller encoding.
283def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
284 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
285 [(set GR64:$dst, (zext GR8:$src))]>, TB;
286def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
287 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
288 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
289// Use movzwl instead of movzwq when the destination is a register; it's
290// equivalent due to implicit zero-extending, and it has a smaller encoding.
291def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
292 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
293 [(set GR64:$dst, (zext GR16:$src))]>, TB;
294def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
295 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
296 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297
Dan Gohman47a419d2008-08-07 02:54:50 +0000298// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000299// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
300// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
301// zero-extension, however this isn't possible when the 32-bit value is
302// defined by a truncate or is copied from something where the high bits aren't
303// necessarily all zero. In such cases, we fall back to these explicit zext
304// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000305def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
306 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
307 [(set GR64:$dst, (zext GR32:$src))]>;
308def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
309 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
310 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
311
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000312// Any instruction that defines a 32-bit result leaves the high half of the
313// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
314// be copying from a truncate, but any other 32-bit operation will zero-extend
315// up to 64 bits.
316def def32 : PatLeaf<(i32 GR32:$src), [{
317 return N->getOpcode() != ISD::TRUNCATE &&
318 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
319 N->getOpcode() != ISD::CopyFromReg;
320}]>;
321
322// In the case of a 32-bit def that is known to implicitly zero-extend,
323// we can use a SUBREG_TO_REG.
324def : Pat<(i64 (zext def32:$src)),
325 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
326
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000327let neverHasSideEffects = 1 in {
328 let Defs = [RAX], Uses = [EAX] in
329 def CDQE : RI<0x98, RawFrm, (outs), (ins),
330 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000332 let Defs = [RAX,RDX], Uses = [RAX] in
333 def CQO : RI<0x99, RawFrm, (outs), (ins),
334 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
335}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336
337//===----------------------------------------------------------------------===//
338// Arithmetic Instructions...
339//
340
Evan Cheng55687072007-09-14 21:48:26 +0000341let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342let isTwoAddress = 1 in {
343let isConvertibleToThreeAddress = 1 in {
344let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000345// Register-Register Addition
346def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
347 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000348 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000349 (implicit EFLAGS)]>;
350
351// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000352def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
353 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000354 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
355 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000356def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
357 "add{q}\t{$src2, $dst|$dst, $src2}",
358 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
359 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360} // isConvertibleToThreeAddress
361
Bill Wendlingae034ed2008-12-12 00:56:36 +0000362// Register-Memory Addition
363def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
364 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000365 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000366 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000367} // isTwoAddress
368
Bill Wendlingae034ed2008-12-12 00:56:36 +0000369// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000370def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000371 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000372 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
373 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000374def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000375 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000376 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
377 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000378def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
379 "add{q}\t{$src2, $dst|$dst, $src2}",
380 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
381 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382
Evan Cheng259471d2007-10-05 17:59:57 +0000383let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384let isTwoAddress = 1 in {
385let isCommutable = 1 in
Dale Johannesend6758f92009-06-01 23:27:20 +0000386def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst),
387 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000388 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000389 [(set GR64:$dst,
390 (X86adde_flag GR64:$src1, GR64:$src2, EFLAGS)),
391 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392
Dale Johannesend6758f92009-06-01 23:27:20 +0000393def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst),
394 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000395 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000396 [(set GR64:$dst,
397 (X86adde_flag GR64:$src1, (load addr:$src2), EFLAGS)),
398 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399
Dale Johannesend6758f92009-06-01 23:27:20 +0000400def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst),
401 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000402 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000403 [(set GR64:$dst,
404 (X86adde_flag GR64:$src1, i64immSExt8:$src2, EFLAGS)),
405 (implicit EFLAGS)]>;
406def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst),
407 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000408 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000409 [(set GR64:$dst,
410 (X86adde_flag GR64:$src1, i64immSExt32:$src2,
411 EFLAGS)),
412 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413} // isTwoAddress
414
Evan Chengb783fa32007-07-19 01:14:50 +0000415def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000416 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000417 [(store (X86adde_flag (load addr:$dst), GR64:$src2, EFLAGS),
418 addr:$dst),
419 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000420def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000421 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000422 [(store (X86adde_flag (load addr:$dst), i64immSExt8:$src2,
423 EFLAGS),
424 addr:$dst),
425 (implicit EFLAGS)]>;
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 Johannesend6758f92009-06-01 23:27:20 +0000428 [(store (X86adde_flag (load addr:$dst), i64immSExt8:$src2,
429 EFLAGS),
430 addr:$dst),
431 (implicit EFLAGS)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000432} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433
434let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000435// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000436def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000437 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000438 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
439 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000440
441// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000442def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000444 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
445 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000446
447// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000448def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
449 (ins GR64:$src1, i64i8imm:$src2),
450 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000451 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
452 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000453def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
454 (ins GR64:$src1, i64i32imm:$src2),
455 "sub{q}\t{$src2, $dst|$dst, $src2}",
456 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
457 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458} // isTwoAddress
459
Bill Wendlingae034ed2008-12-12 00:56:36 +0000460// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000461def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000462 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000463 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
464 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000465
466// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000467def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000468 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000469 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000470 addr:$dst),
471 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000472def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
473 "sub{q}\t{$src2, $dst|$dst, $src2}",
474 [(store (sub (load addr:$dst), i64immSExt32:$src2),
475 addr:$dst),
476 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477
Evan Cheng259471d2007-10-05 17:59:57 +0000478let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000479let isTwoAddress = 1 in {
Dale Johannesend6758f92009-06-01 23:27:20 +0000480def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst),
481 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000482 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000483 [(set GR64:$dst,
484 (X86sube_flag GR64:$src1, GR64:$src2, EFLAGS)),
485 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486
Dale Johannesend6758f92009-06-01 23:27:20 +0000487def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst),
488 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000490 [(set GR64:$dst,
491 (X86sube_flag GR64:$src1, (load addr:$src2), EFLAGS)),
492 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493
Dale Johannesend6758f92009-06-01 23:27:20 +0000494def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst),
495 (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000496 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000497 [(set GR64:$dst,
498 (X86sube_flag GR64:$src1, i64immSExt8:$src2, EFLAGS)),
499 (implicit EFLAGS)]>;
500def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst),
501 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000502 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000503 [(set GR64:$dst,
504 (X86sube_flag GR64:$src1, i64immSExt32:$src2,
505 EFLAGS)),
506 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507} // isTwoAddress
508
Evan Chengb783fa32007-07-19 01:14:50 +0000509def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000510 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000511 [(store (X86sube_flag (load addr:$dst), GR64:$src2, EFLAGS),
512 addr:$dst),
513 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000514def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000515 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000516 [(store (X86sube_flag (load addr:$dst), i64immSExt8:$src2,
517 EFLAGS),
518 addr:$dst),
519 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000520def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
521 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesend6758f92009-06-01 23:27:20 +0000522 [(store (X86sube_flag (load addr:$dst), i64immSExt32:$src2,
523 EFLAGS),
524 addr:$dst),
525 (implicit EFLAGS)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000526} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000527} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
529// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000530let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000531def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000532 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000533let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000534def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000535 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536
537// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000538def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000539 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000540let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000541def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000542 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
543}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544
Evan Cheng55687072007-09-14 21:48:26 +0000545let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546let isTwoAddress = 1 in {
547let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000548// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000549def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
550 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000551 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000552 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
553 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554
Bill Wendlingf5399032008-12-12 21:15:41 +0000555// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000556def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
557 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000558 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000559 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
560 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561} // isTwoAddress
562
563// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000564
Bill Wendlingf5399032008-12-12 21:15:41 +0000565// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000566def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000567 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000568 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000569 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
570 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000571def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
572 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
573 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
574 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
575 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000576
Bill Wendlingf5399032008-12-12 21:15:41 +0000577// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000579 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000580 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000581 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000582 i64immSExt8:$src2)),
583 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000584def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
585 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
586 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
587 [(set GR64:$dst, (mul (load addr:$src1),
588 i64immSExt32:$src2)),
589 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000590} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591
592// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000593let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000594def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000595 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000596// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000597def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000598 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000599let mayLoad = 1 in {
600def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
601 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000602def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000603 "idiv{q}\t$src", []>;
604}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000605}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606
607// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000608let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000610def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000611 [(set GR64:$dst, (ineg GR64:$src)),
612 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000613def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000614 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
615 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616
617let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000618def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000619 [(set GR64:$dst, (add GR64:$src, 1)),
620 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000621def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000622 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
623 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624
625let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000626def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000627 [(set GR64:$dst, (add GR64:$src, -1)),
628 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000629def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000630 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
631 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632
633// In 64-bit mode, single byte INC and DEC cannot be encoded.
634let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
635// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000636def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000637 [(set GR16:$dst, (add GR16:$src, 1)),
638 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000640def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000641 [(set GR32:$dst, (add GR32:$src, 1)),
642 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000644def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000645 [(set GR16:$dst, (add GR16:$src, -1)),
646 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000648def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000649 [(set GR32:$dst, (add GR32:$src, -1)),
650 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 Requires<[In64BitMode]>;
652} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000653
654// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
655// how to unfold them.
656let isTwoAddress = 0, CodeSize = 2 in {
657 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000658 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
659 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000660 OpSize, Requires<[In64BitMode]>;
661 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000662 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
663 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000664 Requires<[In64BitMode]>;
665 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000666 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
667 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000668 OpSize, Requires<[In64BitMode]>;
669 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000670 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
671 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000672 Requires<[In64BitMode]>;
673}
Evan Cheng55687072007-09-14 21:48:26 +0000674} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000675
676
Evan Cheng55687072007-09-14 21:48:26 +0000677let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678// Shift instructions
679let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000680let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000681def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000682 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000683 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000684let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000685def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000687 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000688// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
689// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690} // isTwoAddress
691
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000692let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000693def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000694 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000695 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000696def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000699def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000700 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 [(store (shl (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 SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000706 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000708def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000710 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(set GR64:$dst, (srl 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 SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000718 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000719 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000721 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
726
727let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000728let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000729def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000730 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000731 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000732def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000733 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000735def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000736 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
738} // isTwoAddress
739
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000740let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000741def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000742 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000743 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000744def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000745 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000747def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000748 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
750
751// Rotate instructions
752let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000753let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000754def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000757def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000758 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(set GR64:$dst, (rotl 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 ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000768 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000769def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000770 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000772def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
775
776let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000777let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000778def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000779 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000780 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000781def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000782 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000783 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000784def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000785 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
787} // isTwoAddress
788
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000789let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000790def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000791 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000792 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000793def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000794 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000795 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000796def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000797 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
799
800// Double shift instructions (generalizations of rotate)
801let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000802let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000803def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000804 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
805 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000806def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000807 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
808 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000809}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000810
811let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
812def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000813 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000814 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
815 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
816 (i8 imm:$src3)))]>,
817 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000819 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000820 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
821 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
822 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823 TB;
824} // isCommutable
825} // isTwoAddress
826
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000827let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000828def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000829 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
830 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
831 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000832def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000833 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
834 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
835 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000836}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000838 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000839 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
840 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
841 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 TB;
843def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000844 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000845 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
846 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
847 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000849} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850
851//===----------------------------------------------------------------------===//
852// Logical Instructions...
853//
854
Evan Cheng5b51c242009-01-21 19:45:31 +0000855let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000856def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000858def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
860
Evan Cheng55687072007-09-14 21:48:26 +0000861let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862let isTwoAddress = 1 in {
863let isCommutable = 1 in
864def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000865 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000866 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000867 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
868 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000870 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000871 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000872 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
873 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000875 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000876 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000877 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
878 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000879def AND64ri32 : RIi32<0x81, MRM4r,
880 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
881 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000882 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
883 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884} // isTwoAddress
885
886def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000887 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000889 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
890 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000892 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000893 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000894 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
895 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000896def AND64mi32 : RIi32<0x81, MRM4m,
897 (outs), (ins i64mem:$dst, i64i32imm:$src),
898 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000899 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
900 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000901
902let isTwoAddress = 1 in {
903let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000904def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000906 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
907 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000908def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000909 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000910 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
911 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000912def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000913 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000914 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
915 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000916def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
917 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000918 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
919 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920} // isTwoAddress
921
Evan Chengb783fa32007-07-19 01:14:50 +0000922def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000923 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000924 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
925 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000926def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000927 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000928 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
929 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000930def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
931 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000932 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
933 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934
935let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000936let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000937def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000938 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000939 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
940 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000941def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000943 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
944 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000945def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
946 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000947 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
948 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000950 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000951 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000952 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
953 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954} // isTwoAddress
955
Evan Chengb783fa32007-07-19 01:14:50 +0000956def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000957 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000958 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
959 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000960def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000962 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
963 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000964def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
965 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000966 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
967 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000968} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000969
970//===----------------------------------------------------------------------===//
971// Comparison Instructions...
972//
973
974// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000975let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000977def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000978 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000979 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
980 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000981def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000982 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000983 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
984 (implicit EFLAGS)]>;
985def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
986 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000987 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000988 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
989 (implicit EFLAGS)]>;
990def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
991 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000992 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000993 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
994 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995
Evan Chengb783fa32007-07-19 01:14:50 +0000996def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000997 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000998 [(X86cmp GR64:$src1, GR64:$src2),
999 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001000def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001001 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001002 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1003 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001004def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001005 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001006 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1007 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001008def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1009 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1010 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1011 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001012def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001013 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001014 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001015 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001016def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001017 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001018 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001019 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001020def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1021 (ins i64mem:$src1, i64i32imm:$src2),
1022 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1023 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1024 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001025} // Defs = [EFLAGS]
1026
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001027// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001028// TODO: BTC, BTR, and BTS
1029let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001030def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001031 "bt{q}\t{$src2, $src1|$src1, $src2}",
1032 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001033 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001034
1035// Unlike with the register+register form, the memory+register form of the
1036// bt instruction does not ignore the high bits of the index. From ISel's
1037// perspective, this is pretty bizarre. Disable these instructions for now.
1038//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1039// "bt{q}\t{$src2, $src1|$src1, $src2}",
1040// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1041// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001042
1043def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1044 "bt{q}\t{$src2, $src1|$src1, $src2}",
1045 [(X86bt GR64:$src1, i64immSExt8:$src2),
1046 (implicit EFLAGS)]>, TB;
1047// Note that these instructions don't need FastBTMem because that
1048// only applies when the other operand is in a register. When it's
1049// an immediate, bt is still fast.
1050def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1051 "bt{q}\t{$src2, $src1|$src1, $src2}",
1052 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1053 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001054} // Defs = [EFLAGS]
1055
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001057let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001058let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001059def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001060 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001061 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001062 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001063 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001065 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001066 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001068 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001070 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001071 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001073 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001075 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001076 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001077 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001078 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001080 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001081 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001083 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001085 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001086 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001088 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001090 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001093 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001095 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001096 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001097 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001098 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001100 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001103 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001105 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001106 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001107 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001108 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001109def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001110 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001111 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001112 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001113 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001115 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001116 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001117 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001118 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001120 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001121 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001123 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001124def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001125 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001127 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001128 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001129def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1130 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1131 "cmovo\t{$src2, $dst|$dst, $src2}",
1132 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1133 X86_COND_O, EFLAGS))]>, TB;
1134def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1135 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1136 "cmovno\t{$src2, $dst|$dst, $src2}",
1137 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1138 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001139} // isCommutable = 1
1140
1141def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1142 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1143 "cmovb\t{$src2, $dst|$dst, $src2}",
1144 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1145 X86_COND_B, EFLAGS))]>, TB;
1146def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1147 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1148 "cmovae\t{$src2, $dst|$dst, $src2}",
1149 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1150 X86_COND_AE, EFLAGS))]>, TB;
1151def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1152 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1153 "cmove\t{$src2, $dst|$dst, $src2}",
1154 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1155 X86_COND_E, EFLAGS))]>, TB;
1156def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1157 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1158 "cmovne\t{$src2, $dst|$dst, $src2}",
1159 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1160 X86_COND_NE, EFLAGS))]>, TB;
1161def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1162 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1163 "cmovbe\t{$src2, $dst|$dst, $src2}",
1164 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1165 X86_COND_BE, EFLAGS))]>, TB;
1166def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1167 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1168 "cmova\t{$src2, $dst|$dst, $src2}",
1169 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1170 X86_COND_A, EFLAGS))]>, TB;
1171def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1172 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1173 "cmovl\t{$src2, $dst|$dst, $src2}",
1174 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1175 X86_COND_L, EFLAGS))]>, TB;
1176def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1177 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1178 "cmovge\t{$src2, $dst|$dst, $src2}",
1179 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1180 X86_COND_GE, EFLAGS))]>, TB;
1181def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1182 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1183 "cmovle\t{$src2, $dst|$dst, $src2}",
1184 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1185 X86_COND_LE, EFLAGS))]>, TB;
1186def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1187 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1188 "cmovg\t{$src2, $dst|$dst, $src2}",
1189 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1190 X86_COND_G, EFLAGS))]>, TB;
1191def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1192 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1193 "cmovs\t{$src2, $dst|$dst, $src2}",
1194 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1195 X86_COND_S, EFLAGS))]>, TB;
1196def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1197 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1198 "cmovns\t{$src2, $dst|$dst, $src2}",
1199 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1200 X86_COND_NS, EFLAGS))]>, TB;
1201def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1202 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1203 "cmovp\t{$src2, $dst|$dst, $src2}",
1204 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1205 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001207 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001208 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001210 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001211def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1212 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1213 "cmovo\t{$src2, $dst|$dst, $src2}",
1214 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1215 X86_COND_O, EFLAGS))]>, TB;
1216def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1217 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1218 "cmovno\t{$src2, $dst|$dst, $src2}",
1219 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1220 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001221} // isTwoAddress
1222
1223//===----------------------------------------------------------------------===//
1224// Conversion Instructions...
1225//
1226
1227// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001228def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001229 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001230 [(set GR64:$dst,
1231 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001232def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001233 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001234 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1235 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001236def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001237 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001239def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001240 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001241 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001242def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001243 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001244 [(set GR64:$dst,
1245 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001246def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001247 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001248 [(set GR64:$dst,
1249 (int_x86_sse2_cvttsd2si64
1250 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001251
1252// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001253def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001255 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001256def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001259
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260let isTwoAddress = 1 in {
1261def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001262 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001263 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001264 [(set VR128:$dst,
1265 (int_x86_sse2_cvtsi642sd VR128:$src1,
1266 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001267def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001268 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001269 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001270 [(set VR128:$dst,
1271 (int_x86_sse2_cvtsi642sd VR128:$src1,
1272 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273} // isTwoAddress
1274
1275// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001276def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001277 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001278 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001279def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001282
1283let isTwoAddress = 1 in {
1284 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1285 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1286 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1287 [(set VR128:$dst,
1288 (int_x86_sse_cvtsi642ss VR128:$src1,
1289 GR64:$src2))]>;
1290 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1291 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1292 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1293 [(set VR128:$dst,
1294 (int_x86_sse_cvtsi642ss VR128:$src1,
1295 (loadi64 addr:$src2)))]>;
1296}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001297
1298// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001299def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001300 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001301 [(set GR64:$dst,
1302 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001303def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001304 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001305 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1306 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001307def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001308 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001310def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001311 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001313def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001314 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001315 [(set GR64:$dst,
1316 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001317def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001318 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001319 [(set GR64:$dst,
1320 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1321
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322//===----------------------------------------------------------------------===//
1323// Alias Instructions
1324//===----------------------------------------------------------------------===//
1325
Dan Gohman027cd112007-09-17 14:55:08 +00001326// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1327// equivalent due to implicit zero-extending, and it sometimes has a smaller
1328// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1330// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1331// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001332let Defs = [EFLAGS], AddedComplexity = 1,
1333 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001334def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1335 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1336 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337
1338// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001339let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001340def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001341 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342 [(set GR64:$dst, i64immZExt32:$src)]>;
1343
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001344//===----------------------------------------------------------------------===//
1345// Thread Local Storage Instructions
1346//===----------------------------------------------------------------------===//
1347
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001348// All calls clobber the non-callee saved registers. RSP is marked as
1349// a use to prevent stack-pointer assignments that appear immediately
1350// before calls from potentially appearing dead.
1351let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1352 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1353 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1354 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1355 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1356 Uses = [RSP] in
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001357def TLS_addr64 : I<0, Pseudo, (outs), (ins i64imm:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001358 ".byte\t0x66; "
1359 "leaq\t${sym:mem}(%rip), %rdi; "
1360 ".word\t0x6666; "
1361 "rex64; "
1362 "call\t__tls_get_addr@PLT",
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001363 [(X86tlsaddr tglobaltlsaddr:$sym)]>,
1364 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001365
sampo9cc09a32009-01-26 01:24:32 +00001366let AddedComplexity = 5 in
1367def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1368 "movq\t%gs:$src, $dst",
1369 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1370
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001371let AddedComplexity = 5 in
1372def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1373 "movq\t%fs:$src, $dst",
1374 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1375
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001376//===----------------------------------------------------------------------===//
1377// Atomic Instructions
1378//===----------------------------------------------------------------------===//
1379
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001380let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001381def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001382 "lock\n\t"
1383 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001384 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1385}
1386
Dan Gohmana41a1c092008-08-06 15:52:50 +00001387let Constraints = "$val = $dst" in {
1388let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001389def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001390 "lock\n\t"
1391 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001392 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001393 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001394def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001395 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001396 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001397}
1398
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001399// Atomic exchange, and, or, xor
1400let Constraints = "$val = $dst", Defs = [EFLAGS],
1401 usesCustomDAGSchedInserter = 1 in {
1402def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001403 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001404 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001405def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001406 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001407 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001408def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001409 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001410 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001411def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001412 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001413 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001414def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001415 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001416 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001417def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001418 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001419 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001420def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001421 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001422 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001423def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001424 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001425 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001426}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001427
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001428//===----------------------------------------------------------------------===//
1429// Non-Instruction Patterns
1430//===----------------------------------------------------------------------===//
1431
Bill Wendlingfef06052008-09-16 21:48:12 +00001432// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001433def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1434 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1435def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1436 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1437def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1438 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1439def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1440 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1441
1442def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1443 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001444 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001445def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1446 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001447 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001448def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1449 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001450 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1452 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001453 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454
1455// Calls
1456// Direct PC relative function call for small code model. 32-bit displacement
1457// sign extended to 64-bit.
1458def : Pat<(X86call (i64 tglobaladdr:$dst)),
1459 (CALL64pcrel32 tglobaladdr:$dst)>;
1460def : Pat<(X86call (i64 texternalsym:$dst)),
1461 (CALL64pcrel32 texternalsym:$dst)>;
1462
1463def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1464 (CALL64pcrel32 tglobaladdr:$dst)>;
1465def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1466 (CALL64pcrel32 texternalsym:$dst)>;
1467
1468def : Pat<(X86tailcall GR64:$dst),
1469 (CALL64r GR64:$dst)>;
1470
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001471
1472// tailcall stuff
1473def : Pat<(X86tailcall GR32:$dst),
1474 (TAILCALL)>;
1475def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1476 (TAILCALL)>;
1477def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1478 (TAILCALL)>;
1479
1480def : Pat<(X86tcret GR64:$dst, imm:$off),
1481 (TCRETURNri64 GR64:$dst, imm:$off)>;
1482
1483def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1484 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1485
1486def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1487 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1488
Dan Gohmanec596042007-09-17 14:35:24 +00001489// Comparisons.
1490
1491// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001492def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001493 (TEST64rr GR64:$src1, GR64:$src1)>;
1494
Dan Gohman0a3c5222009-01-07 01:00:24 +00001495// Conditional moves with folded loads with operands swapped and conditions
1496// inverted.
1497def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1498 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1499def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1500 (CMOVB64rm GR64:$src2, addr:$src1)>;
1501def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1502 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1503def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1504 (CMOVE64rm GR64:$src2, addr:$src1)>;
1505def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1506 (CMOVA64rm GR64:$src2, addr:$src1)>;
1507def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1508 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1509def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1510 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1511def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1512 (CMOVL64rm GR64:$src2, addr:$src1)>;
1513def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1514 (CMOVG64rm GR64:$src2, addr:$src1)>;
1515def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1516 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1517def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1518 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1519def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1520 (CMOVP64rm GR64:$src2, addr:$src1)>;
1521def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1522 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1523def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1524 (CMOVS64rm GR64:$src2, addr:$src1)>;
1525def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1526 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1527def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1528 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001529
Duncan Sands082524c2008-01-23 20:39:46 +00001530// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001531def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1532
1533// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001534// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1535// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1536// partial-register updates.
1537def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1538def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1539def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1540// For other extloads, use subregs, since the high contents of the register are
1541// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001542def : Pat<(extloadi64i32 addr:$src),
1543 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1544 x86_subreg_32bit)>;
1545def : Pat<(extloadi16i1 addr:$src),
1546 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1547 x86_subreg_8bit)>,
1548 Requires<[In64BitMode]>;
1549def : Pat<(extloadi16i8 addr:$src),
1550 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1551 x86_subreg_8bit)>,
1552 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001553
Dan Gohmandd612bb2008-08-20 21:27:32 +00001554// anyext
1555def : Pat<(i64 (anyext GR8:$src)),
1556 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1557def : Pat<(i64 (anyext GR16:$src)),
1558 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001559def : Pat<(i64 (anyext GR32:$src)),
1560 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001561def : Pat<(i16 (anyext GR8:$src)),
1562 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1563 Requires<[In64BitMode]>;
1564def : Pat<(i32 (anyext GR8:$src)),
1565 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1566 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001567
1568//===----------------------------------------------------------------------===//
1569// Some peepholes
1570//===----------------------------------------------------------------------===//
1571
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001572// Odd encoding trick: -128 fits into an 8-bit immediate field while
1573// +128 doesn't, so in this special case use a sub instead of an add.
1574def : Pat<(add GR64:$src1, 128),
1575 (SUB64ri8 GR64:$src1, -128)>;
1576def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1577 (SUB64mi8 addr:$dst, -128)>;
1578
1579// The same trick applies for 32-bit immediate fields in 64-bit
1580// instructions.
1581def : Pat<(add GR64:$src1, 0x0000000080000000),
1582 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1583def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1584 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1585
Dan Gohman47a419d2008-08-07 02:54:50 +00001586// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001587def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001588 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001589// r & (2^16-1) ==> movz
1590def : Pat<(and GR64:$src, 0xffff),
1591 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1592// r & (2^8-1) ==> movz
1593def : Pat<(and GR64:$src, 0xff),
1594 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001595// r & (2^8-1) ==> movz
1596def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001597 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001598 Requires<[In64BitMode]>;
1599// r & (2^8-1) ==> movz
1600def : Pat<(and GR16:$src1, 0xff),
1601 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1602 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001603
Dan Gohmandd612bb2008-08-20 21:27:32 +00001604// sext_inreg patterns
1605def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001606 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001607def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001608 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001609def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001610 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001611def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001612 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001613 Requires<[In64BitMode]>;
1614def : Pat<(sext_inreg GR16:$src, i8),
1615 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1616 Requires<[In64BitMode]>;
1617
1618// trunc patterns
1619def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001620 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001621def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001622 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001623def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001624 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001625def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001626 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001627 Requires<[In64BitMode]>;
1628def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001629 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1630 Requires<[In64BitMode]>;
1631
1632// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001633// For now, be conservative on x86-64 and use an h-register extract only if the
1634// value is immediately zero-extended or stored, which are somewhat common
1635// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1636// from being allocated in the same instruction as the h register, as there's
1637// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001638
1639// h-register extract and zero-extend.
1640def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1641 (SUBREG_TO_REG
1642 (i64 0),
1643 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001644 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001645 x86_subreg_8bit_hi)),
1646 x86_subreg_32bit)>;
1647def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1648 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001649 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001650 x86_subreg_8bit_hi))>,
1651 Requires<[In64BitMode]>;
1652def : Pat<(srl_su GR16:$src, (i8 8)),
1653 (EXTRACT_SUBREG
1654 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001655 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001656 x86_subreg_8bit_hi)),
1657 x86_subreg_16bit)>,
1658 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001659def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1660 (MOVZX32_NOREXrr8
1661 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1662 x86_subreg_8bit_hi))>,
1663 Requires<[In64BitMode]>;
1664def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1665 (SUBREG_TO_REG
1666 (i64 0),
1667 (MOVZX32_NOREXrr8
1668 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1669 x86_subreg_8bit_hi)),
1670 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001671
1672// h-register extract and store.
1673def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1674 (MOV8mr_NOREX
1675 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001676 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001677 x86_subreg_8bit_hi))>;
1678def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1679 (MOV8mr_NOREX
1680 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001681 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001682 x86_subreg_8bit_hi))>,
1683 Requires<[In64BitMode]>;
1684def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1685 (MOV8mr_NOREX
1686 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001687 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001688 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001689 Requires<[In64BitMode]>;
1690
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001691// (shl x, 1) ==> (add x, x)
1692def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1693
Evan Cheng76a64c72008-08-30 02:03:58 +00001694// (shl x (and y, 63)) ==> (shl x, y)
1695def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1696 (SHL64rCL GR64:$src1)>;
1697def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1698 (SHL64mCL addr:$dst)>;
1699
1700def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1701 (SHR64rCL GR64:$src1)>;
1702def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1703 (SHR64mCL addr:$dst)>;
1704
1705def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1706 (SAR64rCL GR64:$src1)>;
1707def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1708 (SAR64mCL addr:$dst)>;
1709
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001710// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1711def : Pat<(or (srl GR64:$src1, CL:$amt),
1712 (shl GR64:$src2, (sub 64, CL:$amt))),
1713 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1714
1715def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1716 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1717 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1718
Dan Gohman921581d2008-10-17 01:23:35 +00001719def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1720 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1721 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1722
1723def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1724 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1725 addr:$dst),
1726 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1727
1728def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1729 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1730
1731def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1732 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1733 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1734
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001735// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1736def : Pat<(or (shl GR64:$src1, CL:$amt),
1737 (srl GR64:$src2, (sub 64, CL:$amt))),
1738 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1739
1740def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1741 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1742 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1743
Dan Gohman921581d2008-10-17 01:23:35 +00001744def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1745 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1746 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1747
1748def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1749 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1750 addr:$dst),
1751 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1752
1753def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1754 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1755
1756def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1757 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1758 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1759
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001760// X86 specific add which produces a flag.
1761def : Pat<(addc GR64:$src1, GR64:$src2),
1762 (ADD64rr GR64:$src1, GR64:$src2)>;
1763def : Pat<(addc GR64:$src1, (load addr:$src2)),
1764 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001765def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1766 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001767def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1768 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001769
1770def : Pat<(subc GR64:$src1, GR64:$src2),
1771 (SUB64rr GR64:$src1, GR64:$src2)>;
1772def : Pat<(subc GR64:$src1, (load addr:$src2)),
1773 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001774def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1775 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001776def : Pat<(subc GR64:$src1, imm:$src2),
1777 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778
Bill Wendlingf5399032008-12-12 21:15:41 +00001779//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001780// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001781//===----------------------------------------------------------------------===//
1782
Dan Gohman99a12192009-03-04 19:44:21 +00001783// Register-Register Addition with EFLAGS result
1784def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001785 (implicit EFLAGS)),
1786 (ADD64rr GR64:$src1, GR64:$src2)>;
1787
Dan Gohman99a12192009-03-04 19:44:21 +00001788// Register-Integer Addition with EFLAGS result
1789def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001790 (implicit EFLAGS)),
1791 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001792def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001793 (implicit EFLAGS)),
1794 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001795
Dan Gohman99a12192009-03-04 19:44:21 +00001796// Register-Memory Addition with EFLAGS result
1797def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001798 (implicit EFLAGS)),
1799 (ADD64rm GR64:$src1, addr:$src2)>;
1800
Dan Gohman99a12192009-03-04 19:44:21 +00001801// Memory-Register Addition with EFLAGS result
1802def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001803 addr:$dst),
1804 (implicit EFLAGS)),
1805 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001806def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001807 addr:$dst),
1808 (implicit EFLAGS)),
1809 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001810def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001811 addr:$dst),
1812 (implicit EFLAGS)),
1813 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001814
Dan Gohman99a12192009-03-04 19:44:21 +00001815// Register-Register Subtraction with EFLAGS result
1816def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001817 (implicit EFLAGS)),
1818 (SUB64rr GR64:$src1, GR64:$src2)>;
1819
Dan Gohman99a12192009-03-04 19:44:21 +00001820// Register-Memory Subtraction with EFLAGS result
1821def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001822 (implicit EFLAGS)),
1823 (SUB64rm GR64:$src1, addr:$src2)>;
1824
Dan Gohman99a12192009-03-04 19:44:21 +00001825// Register-Integer Subtraction with EFLAGS result
1826def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001827 (implicit EFLAGS)),
1828 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001829def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001830 (implicit EFLAGS)),
1831 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001832
Dan Gohman99a12192009-03-04 19:44:21 +00001833// Memory-Register Subtraction with EFLAGS result
1834def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001835 addr:$dst),
1836 (implicit EFLAGS)),
1837 (SUB64mr addr:$dst, GR64:$src2)>;
1838
Dan Gohman99a12192009-03-04 19:44:21 +00001839// Memory-Integer Subtraction with EFLAGS result
1840def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001841 addr:$dst),
1842 (implicit EFLAGS)),
1843 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001844def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001845 addr:$dst),
1846 (implicit EFLAGS)),
1847 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001848
Dan Gohman99a12192009-03-04 19:44:21 +00001849// Register-Register Signed Integer Multiplication with EFLAGS result
1850def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001851 (implicit EFLAGS)),
1852 (IMUL64rr GR64:$src1, GR64:$src2)>;
1853
Dan Gohman99a12192009-03-04 19:44:21 +00001854// Register-Memory Signed Integer Multiplication with EFLAGS result
1855def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001856 (implicit EFLAGS)),
1857 (IMUL64rm GR64:$src1, addr:$src2)>;
1858
Dan Gohman99a12192009-03-04 19:44:21 +00001859// Register-Integer Signed Integer Multiplication with EFLAGS result
1860def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001861 (implicit EFLAGS)),
1862 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001863def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001864 (implicit EFLAGS)),
1865 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001866
Dan Gohman99a12192009-03-04 19:44:21 +00001867// Memory-Integer Signed Integer Multiplication with EFLAGS result
1868def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001869 (implicit EFLAGS)),
1870 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001871def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001872 (implicit EFLAGS)),
1873 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001874
Dan Gohman99a12192009-03-04 19:44:21 +00001875// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001876def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1877 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1878def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1879 (implicit EFLAGS)),
1880 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1881def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1882 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1883def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1884 (implicit EFLAGS)),
1885 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1886
1887def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1888 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1889def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1890 (implicit EFLAGS)),
1891 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1892def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1893 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1894def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1895 (implicit EFLAGS)),
1896 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1897
Dan Gohman99a12192009-03-04 19:44:21 +00001898def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1899 (INC64r GR64:$src)>;
1900def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1901 (implicit EFLAGS)),
1902 (INC64m addr:$dst)>;
1903def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1904 (DEC64r GR64:$src)>;
1905def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1906 (implicit EFLAGS)),
1907 (DEC64m addr:$dst)>;
1908
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001909//===----------------------------------------------------------------------===//
1910// X86-64 SSE Instructions
1911//===----------------------------------------------------------------------===//
1912
1913// Move instructions...
1914
Evan Chengb783fa32007-07-19 01:14:50 +00001915def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001916 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001917 [(set VR128:$dst,
1918 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001919def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001920 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1922 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001923
Evan Chengb783fa32007-07-19 01:14:50 +00001924def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001925 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001926 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001927def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001928 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001929 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1930
Evan Chengb783fa32007-07-19 01:14:50 +00001931def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001932 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001933 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001934def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001935 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001936 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001937
1938//===----------------------------------------------------------------------===//
1939// X86-64 SSE4.1 Instructions
1940//===----------------------------------------------------------------------===//
1941
Nate Begeman4294c1f2008-02-12 22:51:28 +00001942/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1943multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001944 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001945 (ins VR128:$src1, i32i8imm:$src2),
1946 !strconcat(OpcodeStr,
1947 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1948 [(set GR64:$dst,
1949 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001950 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001951 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1952 !strconcat(OpcodeStr,
1953 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1954 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1955 addr:$dst)]>, OpSize, REX_W;
1956}
1957
1958defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1959
1960let isTwoAddress = 1 in {
1961 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001962 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001963 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1964 !strconcat(OpcodeStr,
1965 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1966 [(set VR128:$dst,
1967 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1968 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001969 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001970 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1971 !strconcat(OpcodeStr,
1972 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1973 [(set VR128:$dst,
1974 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1975 imm:$src3)))]>, OpSize, REX_W;
1976 }
1977}
1978
1979defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;