blob: c37a93377ed5e6c1969b18b3877a0a853f55fc50 [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
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000264def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000265 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000267def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000268 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000270def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000271 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000273def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000274 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
276
Dan Gohman9203ab42008-07-30 18:09:17 +0000277// Use movzbl instead of movzbq when the destination is a register; it's
278// equivalent due to implicit zero-extending, and it has a smaller encoding.
279def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
280 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
281 [(set GR64:$dst, (zext GR8:$src))]>, TB;
282def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
283 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
284 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
285// Use movzwl instead of movzwq when the destination is a register; it's
286// equivalent due to implicit zero-extending, and it has a smaller encoding.
287def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
288 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
289 [(set GR64:$dst, (zext GR16:$src))]>, TB;
290def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
291 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293
Dan Gohman47a419d2008-08-07 02:54:50 +0000294// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000295// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
296// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
297// zero-extension, however this isn't possible when the 32-bit value is
298// defined by a truncate or is copied from something where the high bits aren't
299// necessarily all zero. In such cases, we fall back to these explicit zext
300// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000301def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
302 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
303 [(set GR64:$dst, (zext GR32:$src))]>;
304def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
305 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
306 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
307
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000308// Any instruction that defines a 32-bit result leaves the high half of the
309// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
310// be copying from a truncate, but any other 32-bit operation will zero-extend
311// up to 64 bits.
312def def32 : PatLeaf<(i32 GR32:$src), [{
313 return N->getOpcode() != ISD::TRUNCATE &&
314 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
315 N->getOpcode() != ISD::CopyFromReg;
316}]>;
317
318// In the case of a 32-bit def that is known to implicitly zero-extend,
319// we can use a SUBREG_TO_REG.
320def : Pat<(i64 (zext def32:$src)),
321 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
322
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000323let neverHasSideEffects = 1 in {
324 let Defs = [RAX], Uses = [EAX] in
325 def CDQE : RI<0x98, RawFrm, (outs), (ins),
326 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000328 let Defs = [RAX,RDX], Uses = [RAX] in
329 def CQO : RI<0x99, RawFrm, (outs), (ins),
330 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
331}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332
333//===----------------------------------------------------------------------===//
334// Arithmetic Instructions...
335//
336
Evan Cheng55687072007-09-14 21:48:26 +0000337let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338let isTwoAddress = 1 in {
339let isConvertibleToThreeAddress = 1 in {
340let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000341// Register-Register Addition
342def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
343 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000344 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000345 (implicit EFLAGS)]>;
346
347// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000348def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
349 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000350 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
351 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000352def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
353 "add{q}\t{$src2, $dst|$dst, $src2}",
354 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
355 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356} // isConvertibleToThreeAddress
357
Bill Wendlingae034ed2008-12-12 00:56:36 +0000358// Register-Memory Addition
359def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
360 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000361 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000362 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363} // isTwoAddress
364
Bill Wendlingae034ed2008-12-12 00:56:36 +0000365// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000366def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000367 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000368 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
369 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000370def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2), addr:$dst),
373 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000374def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
375 "add{q}\t{$src2, $dst|$dst, $src2}",
376 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
377 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378
Evan Cheng259471d2007-10-05 17:59:57 +0000379let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380let isTwoAddress = 1 in {
381let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000382def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000383 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000384 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
Evan Chengb783fa32007-07-19 01:14:50 +0000386def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000387 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000388 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
Evan Chengb783fa32007-07-19 01:14:50 +0000390def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000391 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000392 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000393def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
394 "adc{q}\t{$src2, $dst|$dst, $src2}",
395 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396} // isTwoAddress
397
Evan Chengb783fa32007-07-19 01:14:50 +0000398def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000399 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000400 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000401def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000402 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000403 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000404def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
405 "adc{q}\t{$src2, $dst|$dst, $src2}",
406 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000407} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408
409let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000410// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000411def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000412 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000413 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
414 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000415
416// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000417def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000418 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000419 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
420 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000421
422// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000423def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
424 (ins GR64:$src1, i64i8imm:$src2),
425 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000426 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
427 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000428def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
429 (ins GR64:$src1, i64i32imm:$src2),
430 "sub{q}\t{$src2, $dst|$dst, $src2}",
431 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
432 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433} // isTwoAddress
434
Bill Wendlingae034ed2008-12-12 00:56:36 +0000435// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000436def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, 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 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
439 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000440
441// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000442def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000444 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000445 addr:$dst),
446 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000447def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
448 "sub{q}\t{$src2, $dst|$dst, $src2}",
449 [(store (sub (load addr:$dst), i64immSExt32:$src2),
450 addr:$dst),
451 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452
Evan Cheng259471d2007-10-05 17:59:57 +0000453let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000455def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
458
Evan Chengb783fa32007-07-19 01:14:50 +0000459def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000460 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
462
Evan Chengb783fa32007-07-19 01:14:50 +0000463def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000464 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000466def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
467 "sbb{q}\t{$src2, $dst|$dst, $src2}",
468 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469} // isTwoAddress
470
Evan Chengb783fa32007-07-19 01:14:50 +0000471def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000472 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000474def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000475 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000477def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
478 "sbb{q}\t{$src2, $dst|$dst, $src2}",
479 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000480} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000481} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482
483// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000484let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000485def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000486 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000487let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000488def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000489 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490
491// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000492def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000493 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000494let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000495def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000496 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
497}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
Evan Cheng55687072007-09-14 21:48:26 +0000499let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000500let isTwoAddress = 1 in {
501let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000502// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000503def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
504 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000506 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
507 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508
Bill Wendlingf5399032008-12-12 21:15:41 +0000509// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000510def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
511 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000512 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000513 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
514 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515} // isTwoAddress
516
517// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000518
Bill Wendlingf5399032008-12-12 21:15:41 +0000519// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000521 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000522 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000523 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
524 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000525def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
526 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
527 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
528 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
529 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000530
Bill Wendlingf5399032008-12-12 21:15:41 +0000531// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000533 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000534 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000535 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000536 i64immSExt8:$src2)),
537 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000538def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
539 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
540 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
541 [(set GR64:$dst, (mul (load addr:$src1),
542 i64immSExt32:$src2)),
543 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000544} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545
546// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000547let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000548def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000549 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000551def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000552 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000553let mayLoad = 1 in {
554def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
555 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000556def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000557 "idiv{q}\t$src", []>;
558}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000559}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000560
561// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000562let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000564def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000565 [(set GR64:$dst, (ineg GR64:$src)),
566 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000567def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000568 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
569 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
571let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000572def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000573 [(set GR64:$dst, (add GR64:$src, 1)),
574 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000575def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000576 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
577 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578
579let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000580def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000581 [(set GR64:$dst, (add GR64:$src, -1)),
582 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000583def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000584 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
585 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586
587// In 64-bit mode, single byte INC and DEC cannot be encoded.
588let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
589// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000590def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000591 [(set GR16:$dst, (add GR16:$src, 1)),
592 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000594def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000595 [(set GR32:$dst, (add GR32:$src, 1)),
596 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000598def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000599 [(set GR16:$dst, (add GR16:$src, -1)),
600 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000602def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000603 [(set GR32:$dst, (add GR32:$src, -1)),
604 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605 Requires<[In64BitMode]>;
606} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000607
608// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
609// how to unfold them.
610let isTwoAddress = 0, CodeSize = 2 in {
611 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000612 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
613 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000614 OpSize, Requires<[In64BitMode]>;
615 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000616 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
617 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000618 Requires<[In64BitMode]>;
619 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000620 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
621 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000622 OpSize, Requires<[In64BitMode]>;
623 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000624 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
625 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000626 Requires<[In64BitMode]>;
627}
Evan Cheng55687072007-09-14 21:48:26 +0000628} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629
630
Evan Cheng55687072007-09-14 21:48:26 +0000631let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632// Shift instructions
633let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000634let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000635def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000636 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000637 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000638let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000639def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000640 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000642// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
643// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000644} // isTwoAddress
645
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000646let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000647def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000648 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000649 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000650def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000651 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000652 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000653def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000654 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
656
657let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000658let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000659def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000660 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000661 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000662def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000663 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000665def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000666 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
668} // isTwoAddress
669
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000670let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000671def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000672 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000673 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000674def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000675 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000677def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000678 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000679 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
680
681let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000682let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000683def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000685 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000686def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000687 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000689def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000690 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
692} // isTwoAddress
693
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000694let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000695def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000697 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000698def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000699 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000701def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000702 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000703 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
704
705// Rotate instructions
706let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000707let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000708def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000709 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000710 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000711def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000712 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000714def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000715 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
717} // isTwoAddress
718
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000719let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000720def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000721 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000722 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000726def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000727 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
729
730let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000731let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000732def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000733 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000734 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000735def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000736 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000738def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000739 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000740 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
741} // isTwoAddress
742
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000743let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000744def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000745 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000746 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000747def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000748 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000750def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000751 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
753
754// Double shift instructions (generalizations of rotate)
755let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000756let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000757def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000758 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
759 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000760def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000761 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
762 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000763}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764
765let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
766def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000767 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000768 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
769 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
770 (i8 imm:$src3)))]>,
771 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000773 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000774 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
775 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
776 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 TB;
778} // isCommutable
779} // isTwoAddress
780
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000781let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000782def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000783 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
784 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
785 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000786def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000787 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
788 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
789 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000790}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000792 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000793 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
794 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
795 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 TB;
797def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000798 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000799 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
800 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
801 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000802 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000803} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000804
805//===----------------------------------------------------------------------===//
806// Logical Instructions...
807//
808
Evan Cheng5b51c242009-01-21 19:45:31 +0000809let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000810def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000812def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
814
Evan Cheng55687072007-09-14 21:48:26 +0000815let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816let isTwoAddress = 1 in {
817let isCommutable = 1 in
818def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000819 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000820 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000821 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
822 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000824 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000825 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000826 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
827 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000829 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000830 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000831 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
832 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000833def AND64ri32 : RIi32<0x81, MRM4r,
834 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
835 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000836 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
837 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838} // isTwoAddress
839
840def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000841 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000842 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000843 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
844 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000846 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000847 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000848 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
849 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000850def AND64mi32 : RIi32<0x81, MRM4m,
851 (outs), (ins i64mem:$dst, i64i32imm:$src),
852 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000853 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
854 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855
856let isTwoAddress = 1 in {
857let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000858def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000859 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000860 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
861 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000862def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000863 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000864 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
865 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000866def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000867 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000868 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
869 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000870def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
871 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000872 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
873 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874} // isTwoAddress
875
Evan Chengb783fa32007-07-19 01:14:50 +0000876def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000877 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
879 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000880def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000881 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000882 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
883 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000884def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
885 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000886 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
887 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888
889let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000890let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000891def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000892 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000893 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
894 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000895def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000896 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000897 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
898 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000899def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
900 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000901 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
902 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000904 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000906 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
907 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908} // isTwoAddress
909
Evan Chengb783fa32007-07-19 01:14:50 +0000910def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000911 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000912 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
913 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000914def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000915 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000916 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
917 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000918def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
919 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000920 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
921 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000922} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923
924//===----------------------------------------------------------------------===//
925// Comparison Instructions...
926//
927
928// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000929let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000931def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000932 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000933 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
934 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000935def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000937 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
938 (implicit EFLAGS)]>;
939def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
940 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000941 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000942 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
943 (implicit EFLAGS)]>;
944def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
945 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000947 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
948 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949
Evan Chengb783fa32007-07-19 01:14:50 +0000950def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000951 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000952 [(X86cmp GR64:$src1, GR64:$src2),
953 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000954def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000956 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
957 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000958def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000960 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
961 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000962def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
963 "cmp{q}\t{$src2, $src1|$src1, $src2}",
964 [(X86cmp GR64:$src1, i64immSExt8:$src2),
965 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000966def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000967 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000968 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000969 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000970def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000971 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000972 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000973 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000974def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
975 (ins i64mem:$src1, i64i32imm:$src2),
976 "cmp{q}\t{$src2, $src1|$src1, $src2}",
977 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
978 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000979} // Defs = [EFLAGS]
980
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000981// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000982// TODO: BTC, BTR, and BTS
983let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000984def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000985 "bt{q}\t{$src2, $src1|$src1, $src2}",
986 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +0000987 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +0000988
989// Unlike with the register+register form, the memory+register form of the
990// bt instruction does not ignore the high bits of the index. From ISel's
991// perspective, this is pretty bizarre. Disable these instructions for now.
992//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
993// "bt{q}\t{$src2, $src1|$src1, $src2}",
994// [(X86bt (loadi64 addr:$src1), GR64:$src2),
995// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +0000996
997def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
998 "bt{q}\t{$src2, $src1|$src1, $src2}",
999 [(X86bt GR64:$src1, i64immSExt8:$src2),
1000 (implicit EFLAGS)]>, TB;
1001// Note that these instructions don't need FastBTMem because that
1002// only applies when the other operand is in a register. When it's
1003// an immediate, bt is still fast.
1004def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1005 "bt{q}\t{$src2, $src1|$src1, $src2}",
1006 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1007 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001008} // Defs = [EFLAGS]
1009
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001010// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001011let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001012let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001014 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001015 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001016 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001017 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001019 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001020 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001021 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001022 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001024 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001025 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001027 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001029 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001030 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001032 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001034 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001035 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001037 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001039 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001042 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001044 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001045 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001047 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001049 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001050 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001052 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001054 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001055 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001057 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001059 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001060 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001062 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001064 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001065 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001067 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001068def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001069 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001070 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001072 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001074 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001075 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001077 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001079 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001080 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001082 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001083def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1084 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1085 "cmovo\t{$src2, $dst|$dst, $src2}",
1086 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1087 X86_COND_O, EFLAGS))]>, TB;
1088def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1089 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1090 "cmovno\t{$src2, $dst|$dst, $src2}",
1091 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1092 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001093} // isCommutable = 1
1094
1095def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1096 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1097 "cmovb\t{$src2, $dst|$dst, $src2}",
1098 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1099 X86_COND_B, EFLAGS))]>, TB;
1100def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1101 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1102 "cmovae\t{$src2, $dst|$dst, $src2}",
1103 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1104 X86_COND_AE, EFLAGS))]>, TB;
1105def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1106 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1107 "cmove\t{$src2, $dst|$dst, $src2}",
1108 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1109 X86_COND_E, EFLAGS))]>, TB;
1110def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1111 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1112 "cmovne\t{$src2, $dst|$dst, $src2}",
1113 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1114 X86_COND_NE, EFLAGS))]>, TB;
1115def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1116 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1117 "cmovbe\t{$src2, $dst|$dst, $src2}",
1118 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1119 X86_COND_BE, EFLAGS))]>, TB;
1120def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1121 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1122 "cmova\t{$src2, $dst|$dst, $src2}",
1123 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1124 X86_COND_A, EFLAGS))]>, TB;
1125def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1126 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1127 "cmovl\t{$src2, $dst|$dst, $src2}",
1128 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1129 X86_COND_L, EFLAGS))]>, TB;
1130def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1131 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1132 "cmovge\t{$src2, $dst|$dst, $src2}",
1133 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1134 X86_COND_GE, EFLAGS))]>, TB;
1135def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1136 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1137 "cmovle\t{$src2, $dst|$dst, $src2}",
1138 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1139 X86_COND_LE, EFLAGS))]>, TB;
1140def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1141 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1142 "cmovg\t{$src2, $dst|$dst, $src2}",
1143 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1144 X86_COND_G, EFLAGS))]>, TB;
1145def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1146 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1147 "cmovs\t{$src2, $dst|$dst, $src2}",
1148 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1149 X86_COND_S, EFLAGS))]>, TB;
1150def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1151 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1152 "cmovns\t{$src2, $dst|$dst, $src2}",
1153 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1154 X86_COND_NS, EFLAGS))]>, TB;
1155def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1156 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1157 "cmovp\t{$src2, $dst|$dst, $src2}",
1158 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1159 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001160def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001161 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001163 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001164 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001165def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1166 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1167 "cmovo\t{$src2, $dst|$dst, $src2}",
1168 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1169 X86_COND_O, EFLAGS))]>, TB;
1170def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1171 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1172 "cmovno\t{$src2, $dst|$dst, $src2}",
1173 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1174 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001175} // isTwoAddress
1176
1177//===----------------------------------------------------------------------===//
1178// Conversion Instructions...
1179//
1180
1181// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001182def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001183 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001184 [(set GR64:$dst,
1185 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001186def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001187 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001188 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1189 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001190def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001191 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001193def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001194 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001196def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001197 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001198 [(set GR64:$dst,
1199 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001200def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001202 [(set GR64:$dst,
1203 (int_x86_sse2_cvttsd2si64
1204 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205
1206// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001207def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001208 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001210def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001213
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001214let isTwoAddress = 1 in {
1215def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001216 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001217 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001218 [(set VR128:$dst,
1219 (int_x86_sse2_cvtsi642sd VR128:$src1,
1220 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001221def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001222 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001223 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001224 [(set VR128:$dst,
1225 (int_x86_sse2_cvtsi642sd VR128:$src1,
1226 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227} // isTwoAddress
1228
1229// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001230def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001231 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001232 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001233def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001236
1237let isTwoAddress = 1 in {
1238 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1239 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1240 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1241 [(set VR128:$dst,
1242 (int_x86_sse_cvtsi642ss VR128:$src1,
1243 GR64:$src2))]>;
1244 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1245 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1246 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1247 [(set VR128:$dst,
1248 (int_x86_sse_cvtsi642ss VR128:$src1,
1249 (loadi64 addr:$src2)))]>;
1250}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001251
1252// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001253def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001255 [(set GR64:$dst,
1256 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001257def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001258 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001259 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1260 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001261def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001262 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001263 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001264def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001265 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001267def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001269 [(set GR64:$dst,
1270 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001271def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001272 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001273 [(set GR64:$dst,
1274 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1275
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001276//===----------------------------------------------------------------------===//
1277// Alias Instructions
1278//===----------------------------------------------------------------------===//
1279
Dan Gohman027cd112007-09-17 14:55:08 +00001280// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1281// equivalent due to implicit zero-extending, and it sometimes has a smaller
1282// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1284// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1285// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001286let Defs = [EFLAGS], AddedComplexity = 1,
1287 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001288def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1289 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1290 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001291
1292// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001293let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001294def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001295 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001296 [(set GR64:$dst, i64immZExt32:$src)]>;
1297
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001298//===----------------------------------------------------------------------===//
1299// Thread Local Storage Instructions
1300//===----------------------------------------------------------------------===//
1301
1302def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001303 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001304 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001305
sampo9cc09a32009-01-26 01:24:32 +00001306let AddedComplexity = 5 in
1307def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1308 "movq\t%gs:$src, $dst",
1309 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1310
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001311//===----------------------------------------------------------------------===//
1312// Atomic Instructions
1313//===----------------------------------------------------------------------===//
1314
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001315let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001316def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001317 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001318 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1319}
1320
Dan Gohmana41a1c092008-08-06 15:52:50 +00001321let Constraints = "$val = $dst" in {
1322let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001323def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001324 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001325 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001326 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001327def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001328 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001329 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001330}
1331
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001332// Atomic exchange, and, or, xor
1333let Constraints = "$val = $dst", Defs = [EFLAGS],
1334 usesCustomDAGSchedInserter = 1 in {
1335def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001336 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001337 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001338def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001339 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001340 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001341def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001342 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001343 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001344def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001345 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001346 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001347def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001348 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001349 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001350def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001351 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001352 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001353def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001354 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001355 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001356def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001357 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001358 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001359}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001360
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001361//===----------------------------------------------------------------------===//
1362// Non-Instruction Patterns
1363//===----------------------------------------------------------------------===//
1364
Bill Wendlingfef06052008-09-16 21:48:12 +00001365// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001366def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1367 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1368def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1369 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1370def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1371 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1372def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1373 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1374
1375def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1376 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001377 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001378def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1379 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001380 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001381def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1382 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001383 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001384def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1385 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001386 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001387
1388// Calls
1389// Direct PC relative function call for small code model. 32-bit displacement
1390// sign extended to 64-bit.
1391def : Pat<(X86call (i64 tglobaladdr:$dst)),
1392 (CALL64pcrel32 tglobaladdr:$dst)>;
1393def : Pat<(X86call (i64 texternalsym:$dst)),
1394 (CALL64pcrel32 texternalsym:$dst)>;
1395
1396def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1397 (CALL64pcrel32 tglobaladdr:$dst)>;
1398def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1399 (CALL64pcrel32 texternalsym:$dst)>;
1400
1401def : Pat<(X86tailcall GR64:$dst),
1402 (CALL64r GR64:$dst)>;
1403
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001404
1405// tailcall stuff
1406def : Pat<(X86tailcall GR32:$dst),
1407 (TAILCALL)>;
1408def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1409 (TAILCALL)>;
1410def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1411 (TAILCALL)>;
1412
1413def : Pat<(X86tcret GR64:$dst, imm:$off),
1414 (TCRETURNri64 GR64:$dst, imm:$off)>;
1415
1416def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1417 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1418
1419def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1420 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1421
Dan Gohmanec596042007-09-17 14:35:24 +00001422// Comparisons.
1423
1424// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001425def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001426 (TEST64rr GR64:$src1, GR64:$src1)>;
1427
Dan Gohman0a3c5222009-01-07 01:00:24 +00001428// Conditional moves with folded loads with operands swapped and conditions
1429// inverted.
1430def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1431 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1432def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1433 (CMOVB64rm GR64:$src2, addr:$src1)>;
1434def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1435 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1436def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1437 (CMOVE64rm GR64:$src2, addr:$src1)>;
1438def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1439 (CMOVA64rm GR64:$src2, addr:$src1)>;
1440def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1441 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1442def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1443 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1444def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1445 (CMOVL64rm GR64:$src2, addr:$src1)>;
1446def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1447 (CMOVG64rm GR64:$src2, addr:$src1)>;
1448def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1449 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1450def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1451 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1452def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1453 (CMOVP64rm GR64:$src2, addr:$src1)>;
1454def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1455 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1456def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1457 (CMOVS64rm GR64:$src2, addr:$src1)>;
1458def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1459 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1460def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1461 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001462
Duncan Sands082524c2008-01-23 20:39:46 +00001463// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001464def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1465
1466// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001467// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1468// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1469// partial-register updates.
1470def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1471def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1472def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1473// For other extloads, use subregs, since the high contents of the register are
1474// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001475def : Pat<(extloadi64i32 addr:$src),
1476 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1477 x86_subreg_32bit)>;
1478def : Pat<(extloadi16i1 addr:$src),
1479 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1480 x86_subreg_8bit)>,
1481 Requires<[In64BitMode]>;
1482def : Pat<(extloadi16i8 addr:$src),
1483 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1484 x86_subreg_8bit)>,
1485 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486
Dan Gohmandd612bb2008-08-20 21:27:32 +00001487// anyext
1488def : Pat<(i64 (anyext GR8:$src)),
1489 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1490def : Pat<(i64 (anyext GR16:$src)),
1491 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001492def : Pat<(i64 (anyext GR32:$src)),
1493 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001494def : Pat<(i16 (anyext GR8:$src)),
1495 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1496 Requires<[In64BitMode]>;
1497def : Pat<(i32 (anyext GR8:$src)),
1498 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1499 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001500
1501//===----------------------------------------------------------------------===//
1502// Some peepholes
1503//===----------------------------------------------------------------------===//
1504
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001505// Odd encoding trick: -128 fits into an 8-bit immediate field while
1506// +128 doesn't, so in this special case use a sub instead of an add.
1507def : Pat<(add GR64:$src1, 128),
1508 (SUB64ri8 GR64:$src1, -128)>;
1509def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1510 (SUB64mi8 addr:$dst, -128)>;
1511
1512// The same trick applies for 32-bit immediate fields in 64-bit
1513// instructions.
1514def : Pat<(add GR64:$src1, 0x0000000080000000),
1515 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1516def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1517 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1518
Dan Gohman47a419d2008-08-07 02:54:50 +00001519// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001520def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001521 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001522// r & (2^16-1) ==> movz
1523def : Pat<(and GR64:$src, 0xffff),
1524 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1525// r & (2^8-1) ==> movz
1526def : Pat<(and GR64:$src, 0xff),
1527 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001528// r & (2^8-1) ==> movz
1529def : Pat<(and GR32:$src1, 0xff),
1530 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1531 Requires<[In64BitMode]>;
1532// r & (2^8-1) ==> movz
1533def : Pat<(and GR16:$src1, 0xff),
1534 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1535 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001536
Dan Gohmandd612bb2008-08-20 21:27:32 +00001537// sext_inreg patterns
1538def : Pat<(sext_inreg GR64:$src, i32),
1539 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1540def : Pat<(sext_inreg GR64:$src, i16),
1541 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1542def : Pat<(sext_inreg GR64:$src, i8),
1543 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1544def : Pat<(sext_inreg GR32:$src, i8),
1545 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1546 Requires<[In64BitMode]>;
1547def : Pat<(sext_inreg GR16:$src, i8),
1548 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1549 Requires<[In64BitMode]>;
1550
1551// trunc patterns
1552def : Pat<(i32 (trunc GR64:$src)),
1553 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1554def : Pat<(i16 (trunc GR64:$src)),
1555 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1556def : Pat<(i8 (trunc GR64:$src)),
1557 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1558def : Pat<(i8 (trunc GR32:$src)),
1559 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1560 Requires<[In64BitMode]>;
1561def : Pat<(i8 (trunc GR16:$src)),
1562 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1563 Requires<[In64BitMode]>;
1564
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001565// (shl x, 1) ==> (add x, x)
1566def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1567
Evan Cheng76a64c72008-08-30 02:03:58 +00001568// (shl x (and y, 63)) ==> (shl x, y)
1569def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1570 (SHL64rCL GR64:$src1)>;
1571def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1572 (SHL64mCL addr:$dst)>;
1573
1574def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1575 (SHR64rCL GR64:$src1)>;
1576def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1577 (SHR64mCL addr:$dst)>;
1578
1579def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1580 (SAR64rCL GR64:$src1)>;
1581def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1582 (SAR64mCL addr:$dst)>;
1583
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001584// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1585def : Pat<(or (srl GR64:$src1, CL:$amt),
1586 (shl GR64:$src2, (sub 64, CL:$amt))),
1587 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1588
1589def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1590 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1591 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1592
Dan Gohman921581d2008-10-17 01:23:35 +00001593def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1594 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1595 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1596
1597def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1598 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1599 addr:$dst),
1600 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1601
1602def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1603 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1604
1605def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1606 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1607 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1608
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001609// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1610def : Pat<(or (shl GR64:$src1, CL:$amt),
1611 (srl GR64:$src2, (sub 64, CL:$amt))),
1612 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1613
1614def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1615 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1616 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1617
Dan Gohman921581d2008-10-17 01:23:35 +00001618def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1619 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1620 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1621
1622def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1623 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1624 addr:$dst),
1625 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1626
1627def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1628 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1629
1630def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1631 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1632 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1633
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001634// X86 specific add which produces a flag.
1635def : Pat<(addc GR64:$src1, GR64:$src2),
1636 (ADD64rr GR64:$src1, GR64:$src2)>;
1637def : Pat<(addc GR64:$src1, (load addr:$src2)),
1638 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001639def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1640 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001641def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1642 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001643
1644def : Pat<(subc GR64:$src1, GR64:$src2),
1645 (SUB64rr GR64:$src1, GR64:$src2)>;
1646def : Pat<(subc GR64:$src1, (load addr:$src2)),
1647 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001648def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1649 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001650def : Pat<(subc GR64:$src1, imm:$src2),
1651 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001652
Bill Wendlingf5399032008-12-12 21:15:41 +00001653//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001654// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001655//===----------------------------------------------------------------------===//
1656
Dan Gohman99a12192009-03-04 19:44:21 +00001657// Register-Register Addition with EFLAGS result
1658def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001659 (implicit EFLAGS)),
1660 (ADD64rr GR64:$src1, GR64:$src2)>;
1661
Dan Gohman99a12192009-03-04 19:44:21 +00001662// Register-Integer Addition with EFLAGS result
1663def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001664 (implicit EFLAGS)),
1665 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001666def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001667 (implicit EFLAGS)),
1668 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001669
Dan Gohman99a12192009-03-04 19:44:21 +00001670// Register-Memory Addition with EFLAGS result
1671def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001672 (implicit EFLAGS)),
1673 (ADD64rm GR64:$src1, addr:$src2)>;
1674
Dan Gohman99a12192009-03-04 19:44:21 +00001675// Memory-Register Addition with EFLAGS result
1676def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001677 addr:$dst),
1678 (implicit EFLAGS)),
1679 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001680def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001681 addr:$dst),
1682 (implicit EFLAGS)),
1683 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001684def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001685 addr:$dst),
1686 (implicit EFLAGS)),
1687 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001688
Dan Gohman99a12192009-03-04 19:44:21 +00001689// Register-Register Subtraction with EFLAGS result
1690def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001691 (implicit EFLAGS)),
1692 (SUB64rr GR64:$src1, GR64:$src2)>;
1693
Dan Gohman99a12192009-03-04 19:44:21 +00001694// Register-Memory Subtraction with EFLAGS result
1695def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001696 (implicit EFLAGS)),
1697 (SUB64rm GR64:$src1, addr:$src2)>;
1698
Dan Gohman99a12192009-03-04 19:44:21 +00001699// Register-Integer Subtraction with EFLAGS result
1700def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001701 (implicit EFLAGS)),
1702 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001703def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001704 (implicit EFLAGS)),
1705 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001706
Dan Gohman99a12192009-03-04 19:44:21 +00001707// Memory-Register Subtraction with EFLAGS result
1708def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001709 addr:$dst),
1710 (implicit EFLAGS)),
1711 (SUB64mr addr:$dst, GR64:$src2)>;
1712
Dan Gohman99a12192009-03-04 19:44:21 +00001713// Memory-Integer Subtraction with EFLAGS result
1714def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001715 addr:$dst),
1716 (implicit EFLAGS)),
1717 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001718def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001719 addr:$dst),
1720 (implicit EFLAGS)),
1721 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001722
Dan Gohman99a12192009-03-04 19:44:21 +00001723// Register-Register Signed Integer Multiplication with EFLAGS result
1724def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001725 (implicit EFLAGS)),
1726 (IMUL64rr GR64:$src1, GR64:$src2)>;
1727
Dan Gohman99a12192009-03-04 19:44:21 +00001728// Register-Memory Signed Integer Multiplication with EFLAGS result
1729def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001730 (implicit EFLAGS)),
1731 (IMUL64rm GR64:$src1, addr:$src2)>;
1732
Dan Gohman99a12192009-03-04 19:44:21 +00001733// Register-Integer Signed Integer Multiplication with EFLAGS result
1734def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001735 (implicit EFLAGS)),
1736 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001737def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001738 (implicit EFLAGS)),
1739 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001740
Dan Gohman99a12192009-03-04 19:44:21 +00001741// Memory-Integer Signed Integer Multiplication with EFLAGS result
1742def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001743 (implicit EFLAGS)),
1744 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001745def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001746 (implicit EFLAGS)),
1747 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001748
Dan Gohman99a12192009-03-04 19:44:21 +00001749// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001750def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1751 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1752def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1753 (implicit EFLAGS)),
1754 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1755def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1756 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1757def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1758 (implicit EFLAGS)),
1759 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1760
1761def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1762 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1763def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1764 (implicit EFLAGS)),
1765 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1766def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1767 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1768def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1769 (implicit EFLAGS)),
1770 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1771
Dan Gohman99a12192009-03-04 19:44:21 +00001772def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1773 (INC64r GR64:$src)>;
1774def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1775 (implicit EFLAGS)),
1776 (INC64m addr:$dst)>;
1777def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1778 (DEC64r GR64:$src)>;
1779def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1780 (implicit EFLAGS)),
1781 (DEC64m addr:$dst)>;
1782
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001783//===----------------------------------------------------------------------===//
1784// X86-64 SSE Instructions
1785//===----------------------------------------------------------------------===//
1786
1787// Move instructions...
1788
Evan Chengb783fa32007-07-19 01:14:50 +00001789def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001790 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001791 [(set VR128:$dst,
1792 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001793def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001794 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001795 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1796 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001797
Evan Chengb783fa32007-07-19 01:14:50 +00001798def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001799 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001800 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001801def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001802 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001803 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1804
Evan Chengb783fa32007-07-19 01:14:50 +00001805def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001806 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001807 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001808def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001809 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001810 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001811
1812//===----------------------------------------------------------------------===//
1813// X86-64 SSE4.1 Instructions
1814//===----------------------------------------------------------------------===//
1815
Nate Begeman4294c1f2008-02-12 22:51:28 +00001816/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1817multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001818 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001819 (ins VR128:$src1, i32i8imm:$src2),
1820 !strconcat(OpcodeStr,
1821 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1822 [(set GR64:$dst,
1823 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001824 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001825 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1826 !strconcat(OpcodeStr,
1827 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1828 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1829 addr:$dst)]>, OpSize, REX_W;
1830}
1831
1832defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1833
1834let isTwoAddress = 1 in {
1835 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001836 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001837 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1838 !strconcat(OpcodeStr,
1839 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1840 [(set VR128:$dst,
1841 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1842 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001843 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001844 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1845 !strconcat(OpcodeStr,
1846 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1847 [(set VR128:$dst,
1848 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1849 imm:$src3)))]>, OpSize, REX_W;
1850 }
1851}
1852
1853defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;