blob: ef52785d5d0eff5f0bd96971d50886f8c5ddf9cd [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
Chris Lattner357a0ca2009-06-20 19:34:09 +000022
23// 64-bits but only 32 bits are significant, and those bits are treated as being
24// pc relative.
25def i64i32imm_pcrel : Operand<i64> {
26 let PrintMethod = "print_pcrel_imm";
27}
28
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// 64-bits but only 8 bits are significant.
31def i64i8imm : Operand<i64>;
32
33def lea64mem : Operand<i64> {
Rafael Espindolabca99f72009-04-08 21:14:34 +000034 let PrintMethod = "printlea64mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000035 let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000036 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037}
38
39def lea64_32mem : Operand<i32> {
40 let PrintMethod = "printlea64_32mem";
Chris Lattnerf5da5902009-06-20 07:03:18 +000041 let AsmOperandLowerMethod = "lower_lea64_32mem";
Dan Gohmanefbd3bc2009-08-05 17:40:24 +000042 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000043 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044}
45
46//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000047// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048//
49def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
Dan Gohman0c0d7412009-08-02 16:09:17 +000050 [add, sub, mul, X86mul_imm, shl, or, frameindex,
Chris Lattnerc04cd042009-07-11 23:17:29 +000051 X86WrapperRIP], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052
Chris Lattnerf1940742009-06-20 20:38:48 +000053def tls64addr : ComplexPattern<i64, 4, "SelectTLSADDRAddr",
54 [tglobaltlsaddr], []>;
55
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000057// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058//
59
Dan Gohmand16fdc02008-12-19 18:25:21 +000060def i64immSExt8 : PatLeaf<(i64 imm), [{
61 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
62 // sign extended field.
63 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
64}]>;
65
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066def i64immSExt32 : PatLeaf<(i64 imm), [{
67 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
68 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000069 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070}]>;
71
72def i64immZExt32 : PatLeaf<(i64 imm), [{
73 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
74 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000075 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076}]>;
77
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
79def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
80def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
81
82def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
83def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
84def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
85def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
86
87def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
88def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
89def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
90def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
91
92//===----------------------------------------------------------------------===//
93// Instruction list...
94//
95
Dan Gohman01c9f772008-10-01 18:28:06 +000096// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
97// a stack adjustment and the codegen must know that they may modify the stack
98// pointer before prolog-epilog rewriting occurs.
99// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
100// sub / add which can clobber EFLAGS.
101let Defs = [RSP, EFLAGS], Uses = [RSP] in {
102def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
103 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000104 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000105 Requires<[In64BitMode]>;
106def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
107 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000108 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +0000109 Requires<[In64BitMode]>;
110}
111
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112//===----------------------------------------------------------------------===//
113// Call Instructions...
114//
Evan Cheng37e7c752007-07-21 00:34:19 +0000115let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000116 // All calls clobber the non-callee saved registers. RSP is marked as
117 // a use to prevent stack-pointer assignments that appear immediately
118 // before calls from potentially appearing dead. Uses for argument
119 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000120 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000121 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
123 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000124 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
125 Uses = [RSP] in {
Chris Lattner79552392009-03-18 00:43:52 +0000126
127 // NOTE: this pattern doesn't match "X86call imm", because we do not know
128 // that the offset between an arbitrary immediate and the call will fit in
129 // the 32-bit pcrel field that we have.
Evan Chengfa4b3bd2009-06-16 19:44:27 +0000130 def CALL64pcrel32 : Ii32<0xE8, RawFrm,
Chris Lattner357a0ca2009-06-20 19:34:09 +0000131 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
132 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000133 Requires<[In64BitMode, NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000134 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000135 "call\t{*}$dst", [(X86call GR64:$dst)]>,
136 Requires<[NotWin64]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000137 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000138 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
139 Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 }
141
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000142 // FIXME: We need to teach codegen about single list of call-clobbered registers.
143let isCall = 1 in
144 // All calls clobber the non-callee saved registers. RSP is marked as
145 // a use to prevent stack-pointer assignments that appear immediately
146 // before calls from potentially appearing dead. Uses for argument
147 // registers are added manually.
148 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
149 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
150 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
151 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
152 Uses = [RSP] in {
153 def WINCALL64pcrel32 : I<0xE8, RawFrm,
Anton Korobeynikov1c95afc2009-08-07 23:59:21 +0000154 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
155 "call\t$dst", []>,
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +0000156 Requires<[IsWin64]>;
157 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
158 "call\t{*}$dst",
159 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
160 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
161 "call\t{*}$dst",
162 [(X86call (loadi64 addr:$dst))]>, Requires<[IsWin64]>;
163 }
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000164
165
166let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000167def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
168 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000169 "#TC_RETURN $dst $offset",
170 []>;
171
172let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000173def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
174 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000175 "#TC_RETURN $dst $offset",
176 []>;
177
178
179let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000180 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
181 "jmp{q}\t{*}$dst # TAILCALL",
182 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000183
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000185let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000186 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000188 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 [(brind (loadi64 addr:$dst))]>;
190}
191
192//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000193// EH Pseudo Instructions
194//
195let isTerminator = 1, isReturn = 1, isBarrier = 1,
196 hasCtrlDep = 1 in {
197def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
198 "ret\t#eh_return, addr: $addr",
199 [(X86ehret GR64:$addr)]>;
200
201}
202
203//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204// Miscellaneous Instructions...
205//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000206let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000208 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000209let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
210let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000212 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000213let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000215 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
216}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
Bill Wendling4c2638c2009-06-15 19:39:04 +0000218let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
219def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i8imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000220 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000221def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000222 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000223def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Bill Wendling0b0437f2009-06-15 20:59:31 +0000224 "push{q}\t$imm", []>;
Bill Wendling4c2638c2009-06-15 19:39:04 +0000225}
226
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000227let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000228def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000229let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000230def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000231
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000233 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000234 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
236
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000237let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000238def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000239 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240 [(set GR64:$dst, lea64addr:$src)]>;
241
242let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000243def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000244 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000246
Evan Cheng48679f42007-12-14 02:13:44 +0000247// Bit scan instructions.
248let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000249def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000250 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000251 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000252def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000253 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000254 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
255 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000256
Evan Cheng4e33de92007-12-14 18:49:43 +0000257def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000258 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000259 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000260def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000261 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000262 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
263 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000264} // Defs = [EFLAGS]
265
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000267let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000268def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000269 [(X86rep_movs i64)]>, REP;
270let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000271def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000272 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273
Bill Wendlinga7431ad2009-07-21 01:07:24 +0000274// Fast system-call instructions
275def SYSCALL : I<0x05, RawFrm,
276 (outs), (ins), "syscall", []>, TB;
277def SYSENTER : I<0x34, RawFrm,
278 (outs), (ins), "sysenter", []>, TB;
279def SYSEXIT : I<0x35, RawFrm,
280 (outs), (ins), "sysexit", []>, TB;
281def SYSEXIT64 : RI<0x35, RawFrm,
282 (outs), (ins), "sysexit", []>, TB;
283def SYSRET : I<0x07, RawFrm,
284 (outs), (ins), "sysret", []>, TB;
285
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286//===----------------------------------------------------------------------===//
287// Move Instructions...
288//
289
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000290let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000291def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000292 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293
Evan Chengd2b9d302008-06-25 01:16:38 +0000294let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000295def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000296 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000298def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000301}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302
Dan Gohman5574cc72008-12-03 18:15:48 +0000303let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000304def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000305 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 [(set GR64:$dst, (load addr:$src))]>;
307
Evan Chengb783fa32007-07-19 01:14:50 +0000308def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000309 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000311def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000312 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313 [(store i64immSExt32:$src, addr:$dst)]>;
314
315// Sign/Zero extenders
316
Dan Gohmanedde1992009-04-13 15:13:28 +0000317// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
318// operand, which makes it a rare instruction with an 8-bit register
319// operand that can never access an h register. If support for h registers
320// were generalized, this would require a special register class.
Evan Chengb783fa32007-07-19 01:14:50 +0000321def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000322 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000324def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000325 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000327def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000328 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000330def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000331 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000333def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000334 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000336def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000337 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
339
Dan Gohman9203ab42008-07-30 18:09:17 +0000340// Use movzbl instead of movzbq when the destination is a register; it's
341// equivalent due to implicit zero-extending, and it has a smaller encoding.
342def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
343 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
344 [(set GR64:$dst, (zext GR8:$src))]>, TB;
345def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
346 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
347 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
348// Use movzwl instead of movzwq when the destination is a register; it's
349// equivalent due to implicit zero-extending, and it has a smaller encoding.
350def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
351 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
352 [(set GR64:$dst, (zext GR16:$src))]>, TB;
353def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
354 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
355 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356
Dan Gohman47a419d2008-08-07 02:54:50 +0000357// There's no movzlq instruction, but movl can be used for this purpose, using
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000358// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
359// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
360// zero-extension, however this isn't possible when the 32-bit value is
361// defined by a truncate or is copied from something where the high bits aren't
362// necessarily all zero. In such cases, we fall back to these explicit zext
363// instructions.
Dan Gohman47a419d2008-08-07 02:54:50 +0000364def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
365 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
366 [(set GR64:$dst, (zext GR32:$src))]>;
367def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
368 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
369 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
370
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000371// Any instruction that defines a 32-bit result leaves the high half of the
372// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
373// be copying from a truncate, but any other 32-bit operation will zero-extend
374// up to 64 bits.
375def def32 : PatLeaf<(i32 GR32:$src), [{
376 return N->getOpcode() != ISD::TRUNCATE &&
377 N->getOpcode() != TargetInstrInfo::EXTRACT_SUBREG &&
378 N->getOpcode() != ISD::CopyFromReg;
379}]>;
380
381// In the case of a 32-bit def that is known to implicitly zero-extend,
382// we can use a SUBREG_TO_REG.
383def : Pat<(i64 (zext def32:$src)),
384 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
385
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000386let neverHasSideEffects = 1 in {
387 let Defs = [RAX], Uses = [EAX] in
388 def CDQE : RI<0x98, RawFrm, (outs), (ins),
389 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000391 let Defs = [RAX,RDX], Uses = [RAX] in
392 def CQO : RI<0x99, RawFrm, (outs), (ins),
393 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
394}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
396//===----------------------------------------------------------------------===//
397// Arithmetic Instructions...
398//
399
Evan Cheng55687072007-09-14 21:48:26 +0000400let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401let isTwoAddress = 1 in {
402let isConvertibleToThreeAddress = 1 in {
403let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000404// Register-Register Addition
405def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
406 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000407 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000408 (implicit EFLAGS)]>;
409
410// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000411def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
412 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000413 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
414 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000415def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
416 "add{q}\t{$src2, $dst|$dst, $src2}",
417 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
418 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419} // isConvertibleToThreeAddress
420
Bill Wendlingae034ed2008-12-12 00:56:36 +0000421// Register-Memory Addition
422def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
423 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000424 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000425 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426} // isTwoAddress
427
Bill Wendlingae034ed2008-12-12 00:56:36 +0000428// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000429def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000431 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
432 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000433def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000434 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000435 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
436 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000437def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
438 "add{q}\t{$src2, $dst|$dst, $src2}",
439 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
440 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441
Evan Cheng259471d2007-10-05 17:59:57 +0000442let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000443let isTwoAddress = 1 in {
444let isCommutable = 1 in
Dale Johannesen747fe522009-06-02 03:12:52 +0000445def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000447 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448
Dale Johannesen747fe522009-06-02 03:12:52 +0000449def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000450 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000451 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452
Dale Johannesen747fe522009-06-02 03:12:52 +0000453def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000454 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000455 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
456def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000457 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000458 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459} // isTwoAddress
460
Evan Chengb783fa32007-07-19 01:14:50 +0000461def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000462 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000463 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000464def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000465 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000466 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000467def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
468 "adc{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000469 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000470} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471
472let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000473// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000474def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000475 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000476 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
477 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000478
479// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000480def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000481 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000482 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
483 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000484
485// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000486def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
487 (ins GR64:$src1, i64i8imm:$src2),
488 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000489 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
490 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000491def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
492 (ins GR64:$src1, i64i32imm:$src2),
493 "sub{q}\t{$src2, $dst|$dst, $src2}",
494 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
495 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496} // isTwoAddress
497
Bill Wendlingae034ed2008-12-12 00:56:36 +0000498// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000499def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000501 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
502 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000503
504// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000505def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000506 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000507 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000508 addr:$dst),
509 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000510def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
511 "sub{q}\t{$src2, $dst|$dst, $src2}",
512 [(store (sub (load addr:$dst), i64immSExt32:$src2),
513 addr:$dst),
514 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515
Evan Cheng259471d2007-10-05 17:59:57 +0000516let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517let isTwoAddress = 1 in {
Dale Johannesen747fe522009-06-02 03:12:52 +0000518def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000519 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000520 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521
Dale Johannesen747fe522009-06-02 03:12:52 +0000522def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000523 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000524 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525
Dale Johannesen747fe522009-06-02 03:12:52 +0000526def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000527 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000528 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
529def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +0000530 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000531 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532} // isTwoAddress
533
Evan Chengb783fa32007-07-19 01:14:50 +0000534def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000535 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000536 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000537def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000538 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000539 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000540def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
541 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dale Johannesen747fe522009-06-02 03:12:52 +0000542 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000543} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000544} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545
546// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000547let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000548def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000549 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000550let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000551def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000552 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553
554// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000555def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000556 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000557let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000558def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000559 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
560}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561
Evan Cheng55687072007-09-14 21:48:26 +0000562let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563let isTwoAddress = 1 in {
564let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000565// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000566def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
567 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000568 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000569 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
570 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571
Bill Wendlingf5399032008-12-12 21:15:41 +0000572// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000573def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
574 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000575 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000576 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
577 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578} // isTwoAddress
579
580// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000581
Bill Wendlingf5399032008-12-12 21:15:41 +0000582// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000584 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000585 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000586 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
587 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000588def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
589 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
590 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
591 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
592 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000593
Bill Wendlingf5399032008-12-12 21:15:41 +0000594// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000595def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000596 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000597 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000598 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000599 i64immSExt8:$src2)),
600 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000601def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
602 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
603 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
604 [(set GR64:$dst, (mul (load addr:$src1),
605 i64immSExt32:$src2)),
606 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000607} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608
609// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000610let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000611def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000612 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000614def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000615 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000616let mayLoad = 1 in {
617def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
618 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000619def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000620 "idiv{q}\t$src", []>;
621}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000622}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623
624// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000625let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000627def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000628 [(set GR64:$dst, (ineg GR64:$src)),
629 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000630def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000631 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
632 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633
634let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000635def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000636 [(set GR64:$dst, (add GR64:$src, 1)),
637 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000638def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000639 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
640 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641
642let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000643def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000644 [(set GR64:$dst, (add GR64:$src, -1)),
645 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000646def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000647 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
648 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649
650// In 64-bit mode, single byte INC and DEC cannot be encoded.
651let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
652// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000653def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000654 [(set GR16:$dst, (add GR16:$src, 1)),
655 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000657def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000658 [(set GR32:$dst, (add GR32:$src, 1)),
659 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000661def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000662 [(set GR16:$dst, (add GR16:$src, -1)),
663 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000665def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000666 [(set GR32:$dst, (add GR32:$src, -1)),
667 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 Requires<[In64BitMode]>;
669} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000670
671// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
672// how to unfold them.
673let isTwoAddress = 0, CodeSize = 2 in {
674 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000675 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
676 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000677 OpSize, Requires<[In64BitMode]>;
678 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000679 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
680 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000681 Requires<[In64BitMode]>;
682 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000683 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
684 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000685 OpSize, Requires<[In64BitMode]>;
686 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000687 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
688 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000689 Requires<[In64BitMode]>;
690}
Evan Cheng55687072007-09-14 21:48:26 +0000691} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692
693
Evan Cheng55687072007-09-14 21:48:26 +0000694let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000695// Shift instructions
696let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000697let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000698def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000699 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000700 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000701let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000702def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000703 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000705// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
706// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707} // isTwoAddress
708
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000709let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000710def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000712 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000713def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000714 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000716def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000717 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
719
720let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000721let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000722def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000724 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000725def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000726 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000728def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
731} // isTwoAddress
732
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000733let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000736 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000737def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000738 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000740def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000741 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000742 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
743
744let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000745let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000747 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000748 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000749def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000750 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000752def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000753 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
755} // isTwoAddress
756
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000757let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000758def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000760 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000761def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000763 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000764def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000765 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000766 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
767
768// Rotate instructions
769let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000770let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000771def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000772 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000773 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000774def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000775 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000777def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000778 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
780} // isTwoAddress
781
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000782let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000783def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000785 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000786def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000787 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000788 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000789def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
792
793let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000794let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000795def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000797 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000798def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000799 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000801def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
804} // isTwoAddress
805
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000806let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000807def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000809 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000810def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000811 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000813def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000814 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000815 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
816
817// Double shift instructions (generalizations of rotate)
818let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000819let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000820def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000821 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
822 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000823def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000824 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
825 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000826}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827
828let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
829def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000830 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000831 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
832 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
833 (i8 imm:$src3)))]>,
834 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000836 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000837 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
838 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
839 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840 TB;
841} // isCommutable
842} // isTwoAddress
843
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000844let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000845def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000846 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
847 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
848 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000849def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000850 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
851 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
852 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000853}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000856 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
857 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
858 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 TB;
860def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000861 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000862 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
863 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
864 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000866} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867
868//===----------------------------------------------------------------------===//
869// Logical Instructions...
870//
871
Evan Cheng5b51c242009-01-21 19:45:31 +0000872let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000873def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000875def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000876 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
877
Evan Cheng55687072007-09-14 21:48:26 +0000878let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879let isTwoAddress = 1 in {
880let isCommutable = 1 in
881def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000882 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000883 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000884 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
885 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000887 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000889 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
890 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000892 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000893 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000894 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
895 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000896def AND64ri32 : RIi32<0x81, MRM4r,
897 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
898 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000899 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
900 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000901} // isTwoAddress
902
903def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000904 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000906 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
907 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000909 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000910 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000911 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
912 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000913def AND64mi32 : RIi32<0x81, MRM4m,
914 (outs), (ins i64mem:$dst, i64i32imm:$src),
915 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000916 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
917 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000918
919let isTwoAddress = 1 in {
920let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000921def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000922 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000923 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
924 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000925def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000926 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000927 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
928 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000929def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000930 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000931 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
932 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000933def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
934 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000935 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
936 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937} // isTwoAddress
938
Evan Chengb783fa32007-07-19 01:14:50 +0000939def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000941 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
942 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000943def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000944 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000945 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
946 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000947def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
948 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000949 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
950 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000951
952let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000953let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000954def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000956 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
957 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000958def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000960 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
961 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000962def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
963 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000964 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
965 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000967 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000969 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
970 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971} // isTwoAddress
972
Evan Chengb783fa32007-07-19 01:14:50 +0000973def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000975 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
976 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000977def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000978 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000979 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
980 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000981def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
982 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000983 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
984 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000985} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986
987//===----------------------------------------------------------------------===//
988// Comparison Instructions...
989//
990
991// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000992let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000993let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000994def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000995 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000996 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
997 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000998def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000999 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001000 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
1001 (implicit EFLAGS)]>;
1002def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
1003 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001005 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
1006 (implicit EFLAGS)]>;
1007def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
1008 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001009 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001010 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
1011 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001012
Evan Chengb783fa32007-07-19 01:14:50 +00001013def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001014 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001015 [(X86cmp GR64:$src1, GR64:$src2),
1016 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001017def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001018 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001019 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
1020 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001021def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001022 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001023 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
1024 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001025def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1026 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1027 [(X86cmp GR64:$src1, i64immSExt8:$src2),
1028 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001029def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001030 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001031 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001032 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +00001033def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001034 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001035 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001036 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001037def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
1038 (ins i64mem:$src1, i64i32imm:$src2),
1039 "cmp{q}\t{$src2, $src1|$src1, $src2}",
1040 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
1041 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +00001042} // Defs = [EFLAGS]
1043
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001044// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001045// TODO: BTC, BTR, and BTS
1046let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +00001047def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001048 "bt{q}\t{$src2, $src1|$src1, $src2}",
1049 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +00001050 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +00001051
1052// Unlike with the register+register form, the memory+register form of the
1053// bt instruction does not ignore the high bits of the index. From ISel's
1054// perspective, this is pretty bizarre. Disable these instructions for now.
1055//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1056// "bt{q}\t{$src2, $src1|$src1, $src2}",
1057// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1058// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +00001059
1060def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1061 "bt{q}\t{$src2, $src1|$src1, $src2}",
1062 [(X86bt GR64:$src1, i64immSExt8:$src2),
1063 (implicit EFLAGS)]>, TB;
1064// Note that these instructions don't need FastBTMem because that
1065// only applies when the other operand is in a register. When it's
1066// an immediate, bt is still fast.
1067def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1068 "bt{q}\t{$src2, $src1|$src1, $src2}",
1069 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
1070 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +00001071} // Defs = [EFLAGS]
1072
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +00001074let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +00001075let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001077 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001078 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001080 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001082 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001083 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001085 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001087 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001088 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001090 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001092 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001093 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001095 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001097 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001100 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001102 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001103 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001105 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001107 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001108 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001109 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001110 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001112 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001113 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001115 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001117 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001118 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001120 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001122 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001123 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001124 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001125 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001127 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001128 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001130 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001132 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001133 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001135 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001137 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001138 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001140 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001142 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001143 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001144 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001145 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001146def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1147 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1148 "cmovo\t{$src2, $dst|$dst, $src2}",
1149 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1150 X86_COND_O, EFLAGS))]>, TB;
1151def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1152 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1153 "cmovno\t{$src2, $dst|$dst, $src2}",
1154 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1155 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001156} // isCommutable = 1
1157
1158def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1159 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1160 "cmovb\t{$src2, $dst|$dst, $src2}",
1161 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1162 X86_COND_B, EFLAGS))]>, TB;
1163def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1164 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1165 "cmovae\t{$src2, $dst|$dst, $src2}",
1166 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1167 X86_COND_AE, EFLAGS))]>, TB;
1168def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1169 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1170 "cmove\t{$src2, $dst|$dst, $src2}",
1171 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1172 X86_COND_E, EFLAGS))]>, TB;
1173def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1174 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1175 "cmovne\t{$src2, $dst|$dst, $src2}",
1176 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1177 X86_COND_NE, EFLAGS))]>, TB;
1178def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1179 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1180 "cmovbe\t{$src2, $dst|$dst, $src2}",
1181 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1182 X86_COND_BE, EFLAGS))]>, TB;
1183def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1184 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1185 "cmova\t{$src2, $dst|$dst, $src2}",
1186 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1187 X86_COND_A, EFLAGS))]>, TB;
1188def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1189 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1190 "cmovl\t{$src2, $dst|$dst, $src2}",
1191 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1192 X86_COND_L, EFLAGS))]>, TB;
1193def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1194 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1195 "cmovge\t{$src2, $dst|$dst, $src2}",
1196 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1197 X86_COND_GE, EFLAGS))]>, TB;
1198def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1199 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1200 "cmovle\t{$src2, $dst|$dst, $src2}",
1201 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1202 X86_COND_LE, EFLAGS))]>, TB;
1203def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1204 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1205 "cmovg\t{$src2, $dst|$dst, $src2}",
1206 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1207 X86_COND_G, EFLAGS))]>, TB;
1208def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1209 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1210 "cmovs\t{$src2, $dst|$dst, $src2}",
1211 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1212 X86_COND_S, EFLAGS))]>, TB;
1213def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1214 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1215 "cmovns\t{$src2, $dst|$dst, $src2}",
1216 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1217 X86_COND_NS, EFLAGS))]>, TB;
1218def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1219 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1220 "cmovp\t{$src2, $dst|$dst, $src2}",
1221 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1222 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001223def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001224 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001225 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001226 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001227 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001228def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1229 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1230 "cmovo\t{$src2, $dst|$dst, $src2}",
1231 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1232 X86_COND_O, EFLAGS))]>, TB;
1233def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1234 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1235 "cmovno\t{$src2, $dst|$dst, $src2}",
1236 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1237 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238} // isTwoAddress
1239
1240//===----------------------------------------------------------------------===//
1241// Conversion Instructions...
1242//
1243
1244// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001245def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001246 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001247 [(set GR64:$dst,
1248 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001249def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001250 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001251 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1252 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001253def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001255 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001256def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001259def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001261 [(set GR64:$dst,
1262 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001263def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001264 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001265 [(set GR64:$dst,
1266 (int_x86_sse2_cvttsd2si64
1267 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001268
1269// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001270def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001273def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001274 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001275 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001276
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277let isTwoAddress = 1 in {
1278def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001279 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001281 [(set VR128:$dst,
1282 (int_x86_sse2_cvtsi642sd VR128:$src1,
1283 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001284def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001285 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001286 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001287 [(set VR128:$dst,
1288 (int_x86_sse2_cvtsi642sd VR128:$src1,
1289 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001290} // isTwoAddress
1291
1292// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001293def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001294 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001295 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001296def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001299
1300let isTwoAddress = 1 in {
1301 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1302 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1303 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1304 [(set VR128:$dst,
1305 (int_x86_sse_cvtsi642ss VR128:$src1,
1306 GR64:$src2))]>;
1307 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1308 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1309 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1310 [(set VR128:$dst,
1311 (int_x86_sse_cvtsi642ss VR128:$src1,
1312 (loadi64 addr:$src2)))]>;
1313}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001314
1315// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001316def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001317 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001318 [(set GR64:$dst,
1319 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001320def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001322 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1323 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001324def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001325 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001326 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001327def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001328 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001330def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001331 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001332 [(set GR64:$dst,
1333 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001334def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001335 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001336 [(set GR64:$dst,
1337 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1338
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001339//===----------------------------------------------------------------------===//
1340// Alias Instructions
1341//===----------------------------------------------------------------------===//
1342
Dan Gohman027cd112007-09-17 14:55:08 +00001343// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1344// equivalent due to implicit zero-extending, and it sometimes has a smaller
1345// encoding.
Chris Lattner17f62252009-07-14 20:19:57 +00001346// FIXME: AddedComplexity gives this a higher priority than MOV64ri32. Remove
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001347// when we have a better way to specify isel priority.
Chris Lattner17f62252009-07-14 20:19:57 +00001348let AddedComplexity = 1 in
1349def : Pat<(i64 0),
Chris Lattner3e6fe062009-07-16 06:31:37 +00001350 (SUBREG_TO_REG (i64 0), (MOV32r0), x86_subreg_32bit)>;
Chris Lattner17f62252009-07-14 20:19:57 +00001351
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001352
1353// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001354let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001355def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001356 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001357 [(set GR64:$dst, i64immZExt32:$src)]>;
1358
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001359//===----------------------------------------------------------------------===//
1360// Thread Local Storage Instructions
1361//===----------------------------------------------------------------------===//
1362
Rafael Espindola7fc4b8d2009-04-24 12:59:40 +00001363// All calls clobber the non-callee saved registers. RSP is marked as
1364// a use to prevent stack-pointer assignments that appear immediately
1365// before calls from potentially appearing dead.
1366let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
1367 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
1368 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
1369 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
1370 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
1371 Uses = [RSP] in
Chris Lattnerf1940742009-06-20 20:38:48 +00001372def TLS_addr64 : I<0, Pseudo, (outs), (ins lea64mem:$sym),
Dan Gohman70a8a112009-04-27 15:13:28 +00001373 ".byte\t0x66; "
Chris Lattnerf1940742009-06-20 20:38:48 +00001374 "leaq\t$sym(%rip), %rdi; "
Dan Gohman70a8a112009-04-27 15:13:28 +00001375 ".word\t0x6666; "
1376 "rex64; "
1377 "call\t__tls_get_addr@PLT",
Chris Lattnerf1940742009-06-20 20:38:48 +00001378 [(X86tlsaddr tls64addr:$sym)]>,
Rafael Espindolaaf759ab2009-04-17 14:35:58 +00001379 Requires<[In64BitMode]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001380
sampo9cc09a32009-01-26 01:24:32 +00001381let AddedComplexity = 5 in
1382def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1383 "movq\t%gs:$src, $dst",
1384 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1385
Chris Lattnera7c2d8a2009-05-05 18:52:19 +00001386let AddedComplexity = 5 in
1387def MOV64FSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1388 "movq\t%fs:$src, $dst",
1389 [(set GR64:$dst, (fsload addr:$src))]>, SegFS;
1390
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001391//===----------------------------------------------------------------------===//
1392// Atomic Instructions
1393//===----------------------------------------------------------------------===//
1394
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001395let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001396def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Dan Gohman70a8a112009-04-27 15:13:28 +00001397 "lock\n\t"
1398 "cmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001399 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1400}
1401
Dan Gohmana41a1c092008-08-06 15:52:50 +00001402let Constraints = "$val = $dst" in {
1403let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001404def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Dan Gohman70a8a112009-04-27 15:13:28 +00001405 "lock\n\t"
1406 "xadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001407 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001408 TB, LOCK;
Evan Chengb723fb52009-07-30 08:33:02 +00001409
Evan Chenga1e80602008-04-19 02:05:42 +00001410def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001411 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001412 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001413}
1414
Evan Chengb723fb52009-07-30 08:33:02 +00001415// Optimized codegen when the non-memory output is not used.
1416// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
1417def LOCK_ADD64mr : RI<0x03, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1418 "lock\n\t"
1419 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1420def LOCK_ADD64mi8 : RIi8<0x83, MRM0m, (outs),
1421 (ins i64mem:$dst, i64i8imm :$src2),
1422 "lock\n\t"
1423 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1424def LOCK_ADD64mi32 : RIi32<0x81, MRM0m, (outs),
1425 (ins i64mem:$dst, i64i32imm :$src2),
1426 "lock\n\t"
1427 "add{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1428def LOCK_SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
1429 "lock\n\t"
1430 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1431def LOCK_SUB64mi8 : RIi8<0x83, MRM5m, (outs),
1432 (ins i64mem:$dst, i64i8imm :$src2),
1433 "lock\n\t"
1434 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1435def LOCK_SUB64mi32 : RIi32<0x81, MRM5m, (outs),
1436 (ins i64mem:$dst, i64i32imm:$src2),
1437 "lock\n\t"
1438 "sub{q}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
1439def LOCK_INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst),
1440 "lock\n\t"
1441 "inc{q}\t$dst", []>, LOCK;
1442def LOCK_DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst),
1443 "lock\n\t"
1444 "dec{q}\t$dst", []>, LOCK;
1445
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001446// Atomic exchange, and, or, xor
1447let Constraints = "$val = $dst", Defs = [EFLAGS],
1448 usesCustomDAGSchedInserter = 1 in {
1449def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001450 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001451 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001452def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001453 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001454 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001455def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001456 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001457 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001458def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001459 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001460 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001461def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001462 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001463 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001464def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001465 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001466 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001467def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001468 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001469 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001470def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001471 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001472 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001473}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001474
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001475//===----------------------------------------------------------------------===//
1476// Non-Instruction Patterns
1477//===----------------------------------------------------------------------===//
1478
Chris Lattner0d2dad62009-07-11 22:50:33 +00001479// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable when not in small
1480// code model mode, should use 'movabs'. FIXME: This is really a hack, the
1481// 'movabs' predicate should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001483 (MOV64ri tconstpool :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001484def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001485 (MOV64ri tjumptable :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001487 (MOV64ri tglobaladdr :$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001488def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001489 (MOV64ri texternalsym:$dst)>, Requires<[FarData]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490
Chris Lattnerc04cd042009-07-11 23:17:29 +00001491// In static codegen with small code model, we can get the address of a label
1492// into a register with 'movl'. FIXME: This is a hack, the 'imm' predicate of
1493// the MOV64ri64i32 should accept these.
1494def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1495 (MOV64ri64i32 tconstpool :$dst)>, Requires<[SmallCode]>;
1496def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1497 (MOV64ri64i32 tjumptable :$dst)>, Requires<[SmallCode]>;
1498def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1499 (MOV64ri64i32 tglobaladdr :$dst)>, Requires<[SmallCode]>;
1500def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1501 (MOV64ri64i32 texternalsym:$dst)>, Requires<[SmallCode]>;
1502
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001503// In kernel code model, we can get the address of a label
1504// into a register with 'movq'. FIXME: This is a hack, the 'imm' predicate of
1505// the MOV64ri32 should accept these.
1506def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1507 (MOV64ri32 tconstpool :$dst)>, Requires<[KernelCode]>;
1508def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1509 (MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
1510def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1511 (MOV64ri32 tglobaladdr :$dst)>, Requires<[KernelCode]>;
1512def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1513 (MOV64ri32 texternalsym:$dst)>, Requires<[KernelCode]>;
Chris Lattnerc04cd042009-07-11 23:17:29 +00001514
Chris Lattnerdc6fc472009-06-27 04:16:01 +00001515// If we have small model and -static mode, it is safe to store global addresses
1516// directly as immediates. FIXME: This is really a hack, the 'imm' predicate
Chris Lattner0d2dad62009-07-11 22:50:33 +00001517// for MOV64mi32 should handle this sort of thing.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1519 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001520 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001521def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1522 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001523 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001524def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1525 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001526 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1528 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Anton Korobeynikov68d4eca2009-08-06 11:23:24 +00001529 Requires<[NearData, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001530
1531// Calls
1532// Direct PC relative function call for small code model. 32-bit displacement
1533// sign extended to 64-bit.
1534def : Pat<(X86call (i64 tglobaladdr:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001535 (CALL64pcrel32 tglobaladdr:$dst)>, Requires<[NotWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001536def : Pat<(X86call (i64 texternalsym:$dst)),
Anton Korobeynikov2cbcdb72009-08-03 08:12:53 +00001537 (CALL64pcrel32 texternalsym:$dst)>, Requires<[NotWin64]>;
1538
1539def : Pat<(X86call (i64 tglobaladdr:$dst)),
1540 (WINCALL64pcrel32 tglobaladdr:$dst)>, Requires<[IsWin64]>;
1541def : Pat<(X86call (i64 texternalsym:$dst)),
1542 (WINCALL64pcrel32 texternalsym:$dst)>, Requires<[IsWin64]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001543
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001544// tailcall stuff
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001545def : Pat<(X86tcret GR64:$dst, imm:$off),
1546 (TCRETURNri64 GR64:$dst, imm:$off)>;
1547
1548def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1549 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1550
1551def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1552 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1553
Dan Gohmanec596042007-09-17 14:35:24 +00001554// Comparisons.
1555
1556// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001557def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001558 (TEST64rr GR64:$src1, GR64:$src1)>;
1559
Dan Gohman0a3c5222009-01-07 01:00:24 +00001560// Conditional moves with folded loads with operands swapped and conditions
1561// inverted.
1562def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1563 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1564def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1565 (CMOVB64rm GR64:$src2, addr:$src1)>;
1566def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1567 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1568def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1569 (CMOVE64rm GR64:$src2, addr:$src1)>;
1570def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1571 (CMOVA64rm GR64:$src2, addr:$src1)>;
1572def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1573 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1574def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1575 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1576def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1577 (CMOVL64rm GR64:$src2, addr:$src1)>;
1578def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1579 (CMOVG64rm GR64:$src2, addr:$src1)>;
1580def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1581 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1582def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1583 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1584def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1585 (CMOVP64rm GR64:$src2, addr:$src1)>;
1586def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1587 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1588def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1589 (CMOVS64rm GR64:$src2, addr:$src1)>;
1590def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1591 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1592def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1593 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001594
Duncan Sands082524c2008-01-23 20:39:46 +00001595// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001596def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1597
1598// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001599// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1600// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1601// partial-register updates.
1602def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1603def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1604def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1605// For other extloads, use subregs, since the high contents of the register are
1606// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001607def : Pat<(extloadi64i32 addr:$src),
1608 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1609 x86_subreg_32bit)>;
1610def : Pat<(extloadi16i1 addr:$src),
1611 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1612 x86_subreg_8bit)>,
1613 Requires<[In64BitMode]>;
1614def : Pat<(extloadi16i8 addr:$src),
1615 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1616 x86_subreg_8bit)>,
1617 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001618
Dan Gohmandd612bb2008-08-20 21:27:32 +00001619// anyext
1620def : Pat<(i64 (anyext GR8:$src)),
1621 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1622def : Pat<(i64 (anyext GR16:$src)),
1623 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001624def : Pat<(i64 (anyext GR32:$src)),
1625 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001626def : Pat<(i16 (anyext GR8:$src)),
1627 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1628 Requires<[In64BitMode]>;
1629def : Pat<(i32 (anyext GR8:$src)),
1630 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1631 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632
1633//===----------------------------------------------------------------------===//
1634// Some peepholes
1635//===----------------------------------------------------------------------===//
1636
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001637// Odd encoding trick: -128 fits into an 8-bit immediate field while
1638// +128 doesn't, so in this special case use a sub instead of an add.
1639def : Pat<(add GR64:$src1, 128),
1640 (SUB64ri8 GR64:$src1, -128)>;
1641def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1642 (SUB64mi8 addr:$dst, -128)>;
1643
1644// The same trick applies for 32-bit immediate fields in 64-bit
1645// instructions.
1646def : Pat<(add GR64:$src1, 0x0000000080000000),
1647 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1648def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1649 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1650
Dan Gohman47a419d2008-08-07 02:54:50 +00001651// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001652def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman744d4622009-04-13 16:09:41 +00001653 (MOVZX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001654// r & (2^16-1) ==> movz
1655def : Pat<(and GR64:$src, 0xffff),
1656 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1657// r & (2^8-1) ==> movz
1658def : Pat<(and GR64:$src, 0xff),
1659 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001660// r & (2^8-1) ==> movz
1661def : Pat<(and GR32:$src1, 0xff),
Dan Gohman744d4622009-04-13 16:09:41 +00001662 (MOVZX32rr8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit))>,
Dan Gohman9203ab42008-07-30 18:09:17 +00001663 Requires<[In64BitMode]>;
1664// r & (2^8-1) ==> movz
1665def : Pat<(and GR16:$src1, 0xff),
1666 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1667 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001668
Dan Gohmandd612bb2008-08-20 21:27:32 +00001669// sext_inreg patterns
1670def : Pat<(sext_inreg GR64:$src, i32),
Dan Gohman744d4622009-04-13 16:09:41 +00001671 (MOVSX64rr32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001672def : Pat<(sext_inreg GR64:$src, i16),
Dan Gohman744d4622009-04-13 16:09:41 +00001673 (MOVSX64rr16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001674def : Pat<(sext_inreg GR64:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001675 (MOVSX64rr8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001676def : Pat<(sext_inreg GR32:$src, i8),
Dan Gohman744d4622009-04-13 16:09:41 +00001677 (MOVSX32rr8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001678 Requires<[In64BitMode]>;
1679def : Pat<(sext_inreg GR16:$src, i8),
1680 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1681 Requires<[In64BitMode]>;
1682
1683// trunc patterns
1684def : Pat<(i32 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001685 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001686def : Pat<(i16 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001687 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001688def : Pat<(i8 (trunc GR64:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001689 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001690def : Pat<(i8 (trunc GR32:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001691 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001692 Requires<[In64BitMode]>;
1693def : Pat<(i8 (trunc GR16:$src)),
Dan Gohman744d4622009-04-13 16:09:41 +00001694 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)>,
1695 Requires<[In64BitMode]>;
1696
1697// h-register tricks.
Dan Gohman3aa0b182009-05-31 17:52:18 +00001698// For now, be conservative on x86-64 and use an h-register extract only if the
1699// value is immediately zero-extended or stored, which are somewhat common
1700// cases. This uses a bunch of code to prevent a register requiring a REX prefix
1701// from being allocated in the same instruction as the h register, as there's
1702// currently no way to describe this requirement to the register allocator.
Dan Gohman744d4622009-04-13 16:09:41 +00001703
1704// h-register extract and zero-extend.
1705def : Pat<(and (srl_su GR64:$src, (i8 8)), (i64 255)),
1706 (SUBREG_TO_REG
1707 (i64 0),
1708 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001709 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001710 x86_subreg_8bit_hi)),
1711 x86_subreg_32bit)>;
1712def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
1713 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001714 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001715 x86_subreg_8bit_hi))>,
1716 Requires<[In64BitMode]>;
1717def : Pat<(srl_su GR16:$src, (i8 8)),
1718 (EXTRACT_SUBREG
1719 (MOVZX32_NOREXrr8
Dan Gohman6e438702009-04-27 16:33:14 +00001720 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001721 x86_subreg_8bit_hi)),
1722 x86_subreg_16bit)>,
1723 Requires<[In64BitMode]>;
Evan Cheng957ca282009-05-29 01:44:43 +00001724def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
1725 (MOVZX32_NOREXrr8
1726 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1727 x86_subreg_8bit_hi))>,
1728 Requires<[In64BitMode]>;
1729def : Pat<(i64 (zext (srl_su GR16:$src, (i8 8)))),
1730 (SUBREG_TO_REG
1731 (i64 0),
1732 (MOVZX32_NOREXrr8
1733 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
1734 x86_subreg_8bit_hi)),
1735 x86_subreg_32bit)>;
Dan Gohman744d4622009-04-13 16:09:41 +00001736
1737// h-register extract and store.
1738def : Pat<(store (i8 (trunc_su (srl_su GR64:$src, (i8 8)))), addr:$dst),
1739 (MOV8mr_NOREX
1740 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001741 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR64:$src, GR64_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001742 x86_subreg_8bit_hi))>;
1743def : Pat<(store (i8 (trunc_su (srl_su GR32:$src, (i8 8)))), addr:$dst),
1744 (MOV8mr_NOREX
1745 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001746 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR32:$src, GR32_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001747 x86_subreg_8bit_hi))>,
1748 Requires<[In64BitMode]>;
1749def : Pat<(store (i8 (trunc_su (srl_su GR16:$src, (i8 8)))), addr:$dst),
1750 (MOV8mr_NOREX
1751 addr:$dst,
Dan Gohman6e438702009-04-27 16:33:14 +00001752 (EXTRACT_SUBREG (COPY_TO_REGCLASS GR16:$src, GR16_ABCD),
Dan Gohman744d4622009-04-13 16:09:41 +00001753 x86_subreg_8bit_hi))>,
Dan Gohmandd612bb2008-08-20 21:27:32 +00001754 Requires<[In64BitMode]>;
1755
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001756// (shl x, 1) ==> (add x, x)
1757def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1758
Evan Cheng76a64c72008-08-30 02:03:58 +00001759// (shl x (and y, 63)) ==> (shl x, y)
1760def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1761 (SHL64rCL GR64:$src1)>;
1762def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1763 (SHL64mCL addr:$dst)>;
1764
1765def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1766 (SHR64rCL GR64:$src1)>;
1767def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1768 (SHR64mCL addr:$dst)>;
1769
1770def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1771 (SAR64rCL GR64:$src1)>;
1772def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1773 (SAR64mCL addr:$dst)>;
1774
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001775// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1776def : Pat<(or (srl GR64:$src1, CL:$amt),
1777 (shl GR64:$src2, (sub 64, CL:$amt))),
1778 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1779
1780def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1781 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1782 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1783
Dan Gohman921581d2008-10-17 01:23:35 +00001784def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1785 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1786 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1787
1788def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1789 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1790 addr:$dst),
1791 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1792
1793def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1794 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1795
1796def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1797 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1798 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1799
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001800// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1801def : Pat<(or (shl GR64:$src1, CL:$amt),
1802 (srl GR64:$src2, (sub 64, CL:$amt))),
1803 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1804
1805def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1806 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1807 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1808
Dan Gohman921581d2008-10-17 01:23:35 +00001809def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1810 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1811 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1812
1813def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1814 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1815 addr:$dst),
1816 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1817
1818def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1819 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1820
1821def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1822 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1823 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1824
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001825// X86 specific add which produces a flag.
1826def : Pat<(addc GR64:$src1, GR64:$src2),
1827 (ADD64rr GR64:$src1, GR64:$src2)>;
1828def : Pat<(addc GR64:$src1, (load addr:$src2)),
1829 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001830def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1831 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001832def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1833 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001834
1835def : Pat<(subc GR64:$src1, GR64:$src2),
1836 (SUB64rr GR64:$src1, GR64:$src2)>;
1837def : Pat<(subc GR64:$src1, (load addr:$src2)),
1838 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001839def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1840 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001841def : Pat<(subc GR64:$src1, imm:$src2),
1842 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001843
Bill Wendlingf5399032008-12-12 21:15:41 +00001844//===----------------------------------------------------------------------===//
Dan Gohman99a12192009-03-04 19:44:21 +00001845// EFLAGS-defining Patterns
Bill Wendlingf5399032008-12-12 21:15:41 +00001846//===----------------------------------------------------------------------===//
1847
Dan Gohman99a12192009-03-04 19:44:21 +00001848// Register-Register Addition with EFLAGS result
1849def : Pat<(parallel (X86add_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001850 (implicit EFLAGS)),
1851 (ADD64rr GR64:$src1, GR64:$src2)>;
1852
Dan Gohman99a12192009-03-04 19:44:21 +00001853// Register-Integer Addition with EFLAGS result
1854def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001855 (implicit EFLAGS)),
1856 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001857def : Pat<(parallel (X86add_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001858 (implicit EFLAGS)),
1859 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001860
Dan Gohman99a12192009-03-04 19:44:21 +00001861// Register-Memory Addition with EFLAGS result
1862def : Pat<(parallel (X86add_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001863 (implicit EFLAGS)),
1864 (ADD64rm GR64:$src1, addr:$src2)>;
1865
Dan Gohman99a12192009-03-04 19:44:21 +00001866// Memory-Register Addition with EFLAGS result
1867def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001868 addr:$dst),
1869 (implicit EFLAGS)),
1870 (ADD64mr addr:$dst, GR64:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001871def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001872 addr:$dst),
1873 (implicit EFLAGS)),
1874 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001875def : Pat<(parallel (store (X86add_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001876 addr:$dst),
1877 (implicit EFLAGS)),
1878 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001879
Dan Gohman99a12192009-03-04 19:44:21 +00001880// Register-Register Subtraction with EFLAGS result
1881def : Pat<(parallel (X86sub_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001882 (implicit EFLAGS)),
1883 (SUB64rr GR64:$src1, GR64:$src2)>;
1884
Dan Gohman99a12192009-03-04 19:44:21 +00001885// Register-Memory Subtraction with EFLAGS result
1886def : Pat<(parallel (X86sub_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001887 (implicit EFLAGS)),
1888 (SUB64rm GR64:$src1, addr:$src2)>;
1889
Dan Gohman99a12192009-03-04 19:44:21 +00001890// Register-Integer Subtraction with EFLAGS result
1891def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001892 (implicit EFLAGS)),
1893 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001894def : Pat<(parallel (X86sub_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001895 (implicit EFLAGS)),
1896 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001897
Dan Gohman99a12192009-03-04 19:44:21 +00001898// Memory-Register Subtraction with EFLAGS result
1899def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001900 addr:$dst),
1901 (implicit EFLAGS)),
1902 (SUB64mr addr:$dst, GR64:$src2)>;
1903
Dan Gohman99a12192009-03-04 19:44:21 +00001904// Memory-Integer Subtraction with EFLAGS result
1905def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001906 addr:$dst),
1907 (implicit EFLAGS)),
1908 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001909def : Pat<(parallel (store (X86sub_flag (loadi64 addr:$dst), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001910 addr:$dst),
1911 (implicit EFLAGS)),
1912 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001913
Dan Gohman99a12192009-03-04 19:44:21 +00001914// Register-Register Signed Integer Multiplication with EFLAGS result
1915def : Pat<(parallel (X86smul_flag GR64:$src1, GR64:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001916 (implicit EFLAGS)),
1917 (IMUL64rr GR64:$src1, GR64:$src2)>;
1918
Dan Gohman99a12192009-03-04 19:44:21 +00001919// Register-Memory Signed Integer Multiplication with EFLAGS result
1920def : Pat<(parallel (X86smul_flag GR64:$src1, (loadi64 addr:$src2)),
Bill Wendlingf5399032008-12-12 21:15:41 +00001921 (implicit EFLAGS)),
1922 (IMUL64rm GR64:$src1, addr:$src2)>;
1923
Dan Gohman99a12192009-03-04 19:44:21 +00001924// Register-Integer Signed Integer Multiplication with EFLAGS result
1925def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001926 (implicit EFLAGS)),
1927 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001928def : Pat<(parallel (X86smul_flag GR64:$src1, i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001929 (implicit EFLAGS)),
1930 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001931
Dan Gohman99a12192009-03-04 19:44:21 +00001932// Memory-Integer Signed Integer Multiplication with EFLAGS result
1933def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +00001934 (implicit EFLAGS)),
1935 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohman99a12192009-03-04 19:44:21 +00001936def : Pat<(parallel (X86smul_flag (loadi64 addr:$src1), i64immSExt32:$src2),
Dan Gohmand16fdc02008-12-19 18:25:21 +00001937 (implicit EFLAGS)),
1938 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001939
Dan Gohman99a12192009-03-04 19:44:21 +00001940// INC and DEC with EFLAGS result. Note that these do not set CF.
Dan Gohmaneebcac72009-03-05 21:32:23 +00001941def : Pat<(parallel (X86inc_flag GR16:$src), (implicit EFLAGS)),
1942 (INC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1943def : Pat<(parallel (store (i16 (X86inc_flag (loadi16 addr:$dst))), addr:$dst),
1944 (implicit EFLAGS)),
1945 (INC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1946def : Pat<(parallel (X86dec_flag GR16:$src), (implicit EFLAGS)),
1947 (DEC64_16r GR16:$src)>, Requires<[In64BitMode]>;
1948def : Pat<(parallel (store (i16 (X86dec_flag (loadi16 addr:$dst))), addr:$dst),
1949 (implicit EFLAGS)),
1950 (DEC64_16m addr:$dst)>, Requires<[In64BitMode]>;
1951
1952def : Pat<(parallel (X86inc_flag GR32:$src), (implicit EFLAGS)),
1953 (INC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1954def : Pat<(parallel (store (i32 (X86inc_flag (loadi32 addr:$dst))), addr:$dst),
1955 (implicit EFLAGS)),
1956 (INC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1957def : Pat<(parallel (X86dec_flag GR32:$src), (implicit EFLAGS)),
1958 (DEC64_32r GR32:$src)>, Requires<[In64BitMode]>;
1959def : Pat<(parallel (store (i32 (X86dec_flag (loadi32 addr:$dst))), addr:$dst),
1960 (implicit EFLAGS)),
1961 (DEC64_32m addr:$dst)>, Requires<[In64BitMode]>;
1962
Dan Gohman99a12192009-03-04 19:44:21 +00001963def : Pat<(parallel (X86inc_flag GR64:$src), (implicit EFLAGS)),
1964 (INC64r GR64:$src)>;
1965def : Pat<(parallel (store (i64 (X86inc_flag (loadi64 addr:$dst))), addr:$dst),
1966 (implicit EFLAGS)),
1967 (INC64m addr:$dst)>;
1968def : Pat<(parallel (X86dec_flag GR64:$src), (implicit EFLAGS)),
1969 (DEC64r GR64:$src)>;
1970def : Pat<(parallel (store (i64 (X86dec_flag (loadi64 addr:$dst))), addr:$dst),
1971 (implicit EFLAGS)),
1972 (DEC64m addr:$dst)>;
1973
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001974//===----------------------------------------------------------------------===//
1975// X86-64 SSE Instructions
1976//===----------------------------------------------------------------------===//
1977
1978// Move instructions...
1979
Evan Chengb783fa32007-07-19 01:14:50 +00001980def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001981 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001982 [(set VR128:$dst,
1983 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001984def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001985 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001986 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1987 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001988
Evan Chengb783fa32007-07-19 01:14:50 +00001989def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001990 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001991 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001992def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001993 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001994 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1995
Evan Chengb783fa32007-07-19 01:14:50 +00001996def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001997 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001998 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001999def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00002000 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002001 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00002002
2003//===----------------------------------------------------------------------===//
2004// X86-64 SSE4.1 Instructions
2005//===----------------------------------------------------------------------===//
2006
Nate Begeman4294c1f2008-02-12 22:51:28 +00002007/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
2008multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00002009 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002010 (ins VR128:$src1, i32i8imm:$src2),
2011 !strconcat(OpcodeStr,
2012 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2013 [(set GR64:$dst,
2014 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002015 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002016 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
2017 !strconcat(OpcodeStr,
2018 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
2019 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
2020 addr:$dst)]>, OpSize, REX_W;
2021}
2022
2023defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
2024
2025let isTwoAddress = 1 in {
2026 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00002027 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002028 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
2029 !strconcat(OpcodeStr,
2030 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2031 [(set VR128:$dst,
2032 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
2033 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00002034 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00002035 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
2036 !strconcat(OpcodeStr,
2037 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
2038 [(set VR128:$dst,
2039 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
2040 imm:$src3)))]>, OpSize, REX_W;
2041 }
2042}
2043
2044defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;