~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Target/X86/X86InstrInfo.td

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===----------------------------------------------------------------------===//
 
2
// 
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
// 
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file describes the X86 instruction set, defining the instructions, and
 
11
// properties of the instructions which are needed for code generation, machine
 
12
// code emission, and analysis.
 
13
//
 
14
//===----------------------------------------------------------------------===//
 
15
 
 
16
//===----------------------------------------------------------------------===//
 
17
// X86 specific DAG Nodes.
 
18
//
 
19
 
 
20
def SDTIntShiftDOp: SDTypeProfile<1, 3,
 
21
                                  [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
 
22
                                   SDTCisInt<0>, SDTCisInt<3>]>;
 
23
 
 
24
def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
 
25
 
 
26
def SDTX86Cmov    : SDTypeProfile<1, 4,
 
27
                                  [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
 
28
                                   SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
 
29
 
 
30
// Unary and binary operator instructions that set EFLAGS as a side-effect.
 
31
def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
 
32
                                           [SDTCisInt<0>, SDTCisVT<1, i32>]>;
 
33
 
 
34
def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
 
35
                                            [SDTCisSameAs<0, 2>,
 
36
                                             SDTCisSameAs<0, 3>,
 
37
                                             SDTCisInt<0>, SDTCisVT<1, i32>]>;
 
38
def SDTX86BrCond  : SDTypeProfile<0, 3,
 
39
                                  [SDTCisVT<0, OtherVT>,
 
40
                                   SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
 
41
 
 
42
def SDTX86SetCC   : SDTypeProfile<1, 2,
 
43
                                  [SDTCisVT<0, i8>,
 
44
                                   SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
 
45
def SDTX86SetCC_C : SDTypeProfile<1, 2,
 
46
                                  [SDTCisInt<0>,
 
47
                                   SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
 
48
 
 
49
def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 
 
50
                                     SDTCisVT<2, i8>]>;
 
51
def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
 
52
 
 
53
def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
 
54
                                SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
 
55
def SDTX86Ret     : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
 
56
 
 
57
def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
 
58
def SDT_X86CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>,
 
59
                                        SDTCisVT<1, i32>]>;
 
60
 
 
61
def SDT_X86Call   : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
 
62
 
 
63
def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
 
64
                                                         SDTCisVT<1, iPTR>,
 
65
                                                         SDTCisVT<2, iPTR>]>;
 
66
 
 
67
def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
 
68
 
 
69
def SDTX86Void    : SDTypeProfile<0, 0, []>;
 
70
 
 
71
def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
 
72
 
 
73
def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
 
74
 
 
75
def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
 
76
 
 
77
def SDT_X86SegmentBaseAddress : SDTypeProfile<1, 1, [SDTCisPtrTy<0>]>;
 
78
 
 
79
def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
 
80
 
 
81
def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
 
82
 
 
83
def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>;
 
84
def SDT_X86MEMBARRIERNoSSE : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
 
85
 
 
86
def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER,
 
87
                            [SDNPHasChain]>;
 
88
def X86MemBarrierNoSSE : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIERNoSSE,
 
89
                                [SDNPHasChain]>;
 
90
def X86MFence : SDNode<"X86ISD::MFENCE", SDT_X86MEMBARRIER,
 
91
                        [SDNPHasChain]>;
 
92
def X86SFence : SDNode<"X86ISD::SFENCE", SDT_X86MEMBARRIER,
 
93
                        [SDNPHasChain]>;
 
94
def X86LFence : SDNode<"X86ISD::LFENCE", SDT_X86MEMBARRIER,
 
95
                        [SDNPHasChain]>;
 
96
 
 
97
 
 
98
def X86bsf     : SDNode<"X86ISD::BSF",      SDTUnaryArithWithFlags>;
 
99
def X86bsr     : SDNode<"X86ISD::BSR",      SDTUnaryArithWithFlags>;
 
100
def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
 
101
def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
 
102
 
 
103
def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
 
104
def X86bt      : SDNode<"X86ISD::BT",       SDTX86CmpTest>;
 
105
 
 
106
def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
 
107
def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
 
108
                        [SDNPHasChain]>;
 
109
def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
 
110
def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
 
111
 
 
112
def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
 
113
                        [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
 
114
                         SDNPMayLoad]>;
 
115
def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
 
116
                        [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
 
117
                         SDNPMayLoad]>;
 
118
def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
 
119
                        [SDNPHasChain, SDNPMayStore, 
 
120
                         SDNPMayLoad, SDNPMemOperand]>;
 
121
def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
 
122
                        [SDNPHasChain, SDNPMayStore, 
 
123
                         SDNPMayLoad, SDNPMemOperand]>;
 
124
def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
 
125
                        [SDNPHasChain, SDNPMayStore, 
 
126
                         SDNPMayLoad, SDNPMemOperand]>;
 
127
def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
 
128
                        [SDNPHasChain, SDNPMayStore, 
 
129
                         SDNPMayLoad, SDNPMemOperand]>;
 
130
def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
 
131
                        [SDNPHasChain, SDNPMayStore, 
 
132
                         SDNPMayLoad, SDNPMemOperand]>;
 
133
def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
 
134
                        [SDNPHasChain, SDNPMayStore, 
 
135
                         SDNPMayLoad, SDNPMemOperand]>;
 
136
def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
 
137
                        [SDNPHasChain, SDNPMayStore, 
 
138
                         SDNPMayLoad, SDNPMemOperand]>;
 
139
def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
 
140
                        [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
 
141
 
 
142
def X86vastart_save_xmm_regs :
 
143
                 SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
 
144
                        SDT_X86VASTART_SAVE_XMM_REGS,
 
145
                        [SDNPHasChain, SDNPVariadic]>;
 
146
 
 
147
def X86callseq_start :
 
148
                 SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
 
149
                        [SDNPHasChain, SDNPOutFlag]>;
 
150
def X86callseq_end :
 
151
                 SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
 
152
                        [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
 
153
 
 
154
def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
 
155
                        [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
 
156
                         SDNPVariadic]>;
 
157
 
 
158
def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
 
159
                        [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
 
160
def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
 
161
                        [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
 
162
                         SDNPMayLoad]>;
 
163
 
 
164
def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
 
165
                        [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
 
166
 
 
167
def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
 
168
def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
 
169
 
 
170
def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
 
171
                        [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
 
172
def X86SegmentBaseAddress : SDNode<"X86ISD::SegmentBaseAddress",
 
173
                                 SDT_X86SegmentBaseAddress, []>;
 
174
 
 
175
def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
 
176
                        [SDNPHasChain]>;
 
177
 
 
178
def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
 
179
                        [SDNPHasChain,  SDNPOptInFlag, SDNPVariadic]>;
 
180
 
 
181
def X86add_flag  : SDNode<"X86ISD::ADD",  SDTBinaryArithWithFlags,
 
182
                          [SDNPCommutative]>;
 
183
def X86sub_flag  : SDNode<"X86ISD::SUB",  SDTBinaryArithWithFlags>;
 
184
def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
 
185
                          [SDNPCommutative]>;
 
186
def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
 
187
                          [SDNPCommutative]>;
 
188
                          
 
189
def X86inc_flag  : SDNode<"X86ISD::INC",  SDTUnaryArithWithFlags>;
 
190
def X86dec_flag  : SDNode<"X86ISD::DEC",  SDTUnaryArithWithFlags>;
 
191
def X86or_flag   : SDNode<"X86ISD::OR",   SDTBinaryArithWithFlags,
 
192
                          [SDNPCommutative]>;
 
193
def X86xor_flag  : SDNode<"X86ISD::XOR",  SDTBinaryArithWithFlags,
 
194
                          [SDNPCommutative]>;
 
195
def X86and_flag  : SDNode<"X86ISD::AND",  SDTBinaryArithWithFlags,
 
196
                          [SDNPCommutative]>;
 
197
 
 
198
def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
 
199
 
 
200
def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
 
201
                            [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
 
202
                            
 
203
def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
 
204
                        []>;
 
205
 
 
206
//===----------------------------------------------------------------------===//
 
207
// X86 Operand Definitions.
 
208
//
 
209
 
 
210
// A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
 
211
// the index operand of an address, to conform to x86 encoding restrictions.
 
212
def ptr_rc_nosp : PointerLikeRegClass<1>;
 
213
 
 
214
// *mem - Operand definitions for the funky X86 addressing mode operands.
 
215
//
 
216
def X86MemAsmOperand : AsmOperandClass {
 
217
  let Name = "Mem";
 
218
  let SuperClasses = [];
 
219
}
 
220
def X86AbsMemAsmOperand : AsmOperandClass {
 
221
  let Name = "AbsMem";
 
222
  let SuperClasses = [X86MemAsmOperand];
 
223
}
 
224
class X86MemOperand<string printMethod> : Operand<iPTR> {
 
225
  let PrintMethod = printMethod;
 
226
  let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
 
227
  let ParserMatchClass = X86MemAsmOperand;
 
228
}
 
229
 
 
230
def opaque32mem : X86MemOperand<"printopaquemem">;
 
231
def opaque48mem : X86MemOperand<"printopaquemem">;
 
232
def opaque80mem : X86MemOperand<"printopaquemem">;
 
233
def opaque512mem : X86MemOperand<"printopaquemem">;
 
234
 
 
235
def i8mem   : X86MemOperand<"printi8mem">;
 
236
def i16mem  : X86MemOperand<"printi16mem">;
 
237
def i32mem  : X86MemOperand<"printi32mem">;
 
238
def i64mem  : X86MemOperand<"printi64mem">;
 
239
def i128mem : X86MemOperand<"printi128mem">;
 
240
def i256mem : X86MemOperand<"printi256mem">;
 
241
def f32mem  : X86MemOperand<"printf32mem">;
 
242
def f64mem  : X86MemOperand<"printf64mem">;
 
243
def f80mem  : X86MemOperand<"printf80mem">;
 
244
def f128mem : X86MemOperand<"printf128mem">;
 
245
def f256mem : X86MemOperand<"printf256mem">;
 
246
 
 
247
// A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
 
248
// plain GR64, so that it doesn't potentially require a REX prefix.
 
249
def i8mem_NOREX : Operand<i64> {
 
250
  let PrintMethod = "printi8mem";
 
251
  let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
 
252
  let ParserMatchClass = X86MemAsmOperand;
 
253
}
 
254
 
 
255
// Special i32mem for addresses of load folding tail calls. These are not
 
256
// allowed to use callee-saved registers since they must be scheduled
 
257
// after callee-saved register are popped.
 
258
def i32mem_TC : Operand<i32> {
 
259
  let PrintMethod = "printi32mem";
 
260
  let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
 
261
  let ParserMatchClass = X86MemAsmOperand;
 
262
}
 
263
 
 
264
 
 
265
let ParserMatchClass = X86AbsMemAsmOperand,
 
266
    PrintMethod = "print_pcrel_imm" in {
 
267
def i32imm_pcrel : Operand<i32>;
 
268
def i16imm_pcrel : Operand<i16>;
 
269
 
 
270
def offset8 : Operand<i64>;
 
271
def offset16 : Operand<i64>;
 
272
def offset32 : Operand<i64>;
 
273
def offset64 : Operand<i64>;
 
274
 
 
275
// Branch targets have OtherVT type and print as pc-relative values.
 
276
def brtarget : Operand<OtherVT>;
 
277
def brtarget8 : Operand<OtherVT>;
 
278
 
 
279
}
 
280
 
 
281
def SSECC : Operand<i8> {
 
282
  let PrintMethod = "printSSECC";
 
283
}
 
284
 
 
285
class ImmSExtAsmOperandClass : AsmOperandClass {
 
286
  let SuperClasses = [ImmAsmOperand];
 
287
  let RenderMethod = "addImmOperands";
 
288
}
 
289
 
 
290
// Sign-extended immediate classes. We don't need to define the full lattice
 
291
// here because there is no instruction with an ambiguity between ImmSExti64i32
 
292
// and ImmSExti32i8.
 
293
//
 
294
// The strange ranges come from the fact that the assembler always works with
 
295
// 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
 
296
// (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
 
297
 
 
298
// [0, 0x7FFFFFFF]                                            |
 
299
//   [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
 
300
def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
 
301
  let Name = "ImmSExti64i32";
 
302
}
 
303
 
 
304
// [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
 
305
//   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
 
306
def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
 
307
  let Name = "ImmSExti16i8";
 
308
  let SuperClasses = [ImmSExti64i32AsmOperand];
 
309
}
 
310
 
 
311
// [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
 
312
//   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
 
313
def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
 
314
  let Name = "ImmSExti32i8";
 
315
}
 
316
 
 
317
// [0, 0x0000007F]                                            |
 
318
//   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
 
319
def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
 
320
  let Name = "ImmSExti64i8";
 
321
  let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
 
322
                      ImmSExti64i32AsmOperand];
 
323
}
 
324
 
 
325
// A couple of more descriptive operand definitions.
 
326
// 16-bits but only 8 bits are significant.
 
327
def i16i8imm  : Operand<i16> {
 
328
  let ParserMatchClass = ImmSExti16i8AsmOperand;
 
329
}
 
330
// 32-bits but only 8 bits are significant.
 
331
def i32i8imm  : Operand<i32> {
 
332
  let ParserMatchClass = ImmSExti32i8AsmOperand;
 
333
}
 
334
 
 
335
//===----------------------------------------------------------------------===//
 
336
// X86 Complex Pattern Definitions.
 
337
//
 
338
 
 
339
// Define X86 specific addressing mode.
 
340
def addr      : ComplexPattern<iPTR, 5, "SelectAddr", [], []>;
 
341
def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
 
342
                               [add, sub, mul, X86mul_imm, shl, or, frameindex],
 
343
                               []>;
 
344
def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
 
345
                               [tglobaltlsaddr], []>;
 
346
 
 
347
//===----------------------------------------------------------------------===//
 
348
// X86 Instruction Predicate Definitions.
 
349
def HasCMov      : Predicate<"Subtarget->hasCMov()">;
 
350
def NoCMov       : Predicate<"!Subtarget->hasCMov()">;
 
351
 
 
352
def HasMMX       : Predicate<"Subtarget->hasMMX() && !Subtarget->hasAVX()">;
 
353
def HasSSE1      : Predicate<"Subtarget->hasSSE1()">;
 
354
def HasSSE2      : Predicate<"Subtarget->hasSSE2()">;
 
355
def HasSSE3      : Predicate<"Subtarget->hasSSE3()">;
 
356
def HasSSSE3     : Predicate<"Subtarget->hasSSSE3()">;
 
357
def HasSSE41     : Predicate<"Subtarget->hasSSE41()">;
 
358
def HasSSE42     : Predicate<"Subtarget->hasSSE42()">;
 
359
def HasSSE4A     : Predicate<"Subtarget->hasSSE4A()">;
 
360
 
 
361
def HasAVX       : Predicate<"Subtarget->hasAVX()">;
 
362
def HasCLMUL     : Predicate<"Subtarget->hasCLMUL()">;
 
363
def HasFMA3      : Predicate<"Subtarget->hasFMA3()">;
 
364
def HasFMA4      : Predicate<"Subtarget->hasFMA4()">;
 
365
def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
 
366
def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
 
367
def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
 
368
def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
 
369
def IsWin64      : Predicate<"Subtarget->isTargetWin64()">;
 
370
def NotWin64     : Predicate<"!Subtarget->isTargetWin64()">;
 
371
def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
 
372
def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
 
373
def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
 
374
                             "TM.getCodeModel() != CodeModel::Kernel">;
 
375
def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
 
376
                             "TM.getCodeModel() == CodeModel::Kernel">;
 
377
def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
 
378
def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
 
379
def OptForSize   : Predicate<"OptForSize">;
 
380
def OptForSpeed  : Predicate<"!OptForSize">;
 
381
def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
 
382
def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
 
383
def HasAES       : Predicate<"Subtarget->hasAES()">;
 
384
 
 
385
//===----------------------------------------------------------------------===//
 
386
// X86 Instruction Format Definitions.
 
387
//
 
388
 
 
389
include "X86InstrFormats.td"
 
390
 
 
391
//===----------------------------------------------------------------------===//
 
392
// Pattern fragments...
 
393
//
 
394
 
 
395
// X86 specific condition code. These correspond to CondCode in
 
396
// X86InstrInfo.h. They must be kept in synch.
 
397
def X86_COND_A   : PatLeaf<(i8 0)>;  // alt. COND_NBE
 
398
def X86_COND_AE  : PatLeaf<(i8 1)>;  // alt. COND_NC
 
399
def X86_COND_B   : PatLeaf<(i8 2)>;  // alt. COND_C
 
400
def X86_COND_BE  : PatLeaf<(i8 3)>;  // alt. COND_NA
 
401
def X86_COND_E   : PatLeaf<(i8 4)>;  // alt. COND_Z
 
402
def X86_COND_G   : PatLeaf<(i8 5)>;  // alt. COND_NLE
 
403
def X86_COND_GE  : PatLeaf<(i8 6)>;  // alt. COND_NL
 
404
def X86_COND_L   : PatLeaf<(i8 7)>;  // alt. COND_NGE
 
405
def X86_COND_LE  : PatLeaf<(i8 8)>;  // alt. COND_NG
 
406
def X86_COND_NE  : PatLeaf<(i8 9)>;  // alt. COND_NZ
 
407
def X86_COND_NO  : PatLeaf<(i8 10)>;
 
408
def X86_COND_NP  : PatLeaf<(i8 11)>; // alt. COND_PO
 
409
def X86_COND_NS  : PatLeaf<(i8 12)>;
 
410
def X86_COND_O   : PatLeaf<(i8 13)>;
 
411
def X86_COND_P   : PatLeaf<(i8 14)>; // alt. COND_PE
 
412
def X86_COND_S   : PatLeaf<(i8 15)>;
 
413
 
 
414
def immSext8 : PatLeaf<(imm), [{ return immSext8(N); }]>;
 
415
 
 
416
def i16immSExt8  : PatLeaf<(i16 immSext8)>;
 
417
def i32immSExt8  : PatLeaf<(i32 immSext8)>;
 
418
 
 
419
/// Load patterns: these constraint the match to the right address space.
 
420
def dsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
 
421
  if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
 
422
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
423
      if (PT->getAddressSpace() > 255)
 
424
        return false;
 
425
  return true;
 
426
}]>;
 
427
 
 
428
def gsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
 
429
  if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
 
430
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
431
      return PT->getAddressSpace() == 256;
 
432
  return false;
 
433
}]>;
 
434
 
 
435
def fsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
 
436
  if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
 
437
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
438
      return PT->getAddressSpace() == 257;
 
439
  return false;
 
440
}]>;
 
441
 
 
442
 
 
443
// Helper fragments for loads.
 
444
// It's always safe to treat a anyext i16 load as a i32 load if the i16 is
 
445
// known to be 32-bit aligned or better. Ditto for i8 to i16.
 
446
def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
 
447
  LoadSDNode *LD = cast<LoadSDNode>(N);
 
448
  if (const Value *Src = LD->getSrcValue())
 
449
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
450
      if (PT->getAddressSpace() > 255)
 
451
        return false;
 
452
  ISD::LoadExtType ExtType = LD->getExtensionType();
 
453
  if (ExtType == ISD::NON_EXTLOAD)
 
454
    return true;
 
455
  if (ExtType == ISD::EXTLOAD)
 
456
    return LD->getAlignment() >= 2 && !LD->isVolatile();
 
457
  return false;
 
458
}]>;
 
459
 
 
460
def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
 
461
  LoadSDNode *LD = cast<LoadSDNode>(N);
 
462
  if (const Value *Src = LD->getSrcValue())
 
463
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
464
      if (PT->getAddressSpace() > 255)
 
465
        return false;
 
466
  ISD::LoadExtType ExtType = LD->getExtensionType();
 
467
  if (ExtType == ISD::EXTLOAD)
 
468
    return LD->getAlignment() >= 2 && !LD->isVolatile();
 
469
  return false;
 
470
}]>;
 
471
 
 
472
def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
 
473
  LoadSDNode *LD = cast<LoadSDNode>(N);
 
474
  if (const Value *Src = LD->getSrcValue())
 
475
    if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
 
476
      if (PT->getAddressSpace() > 255)
 
477
        return false;
 
478
  ISD::LoadExtType ExtType = LD->getExtensionType();
 
479
  if (ExtType == ISD::NON_EXTLOAD)
 
480
    return true;
 
481
  if (ExtType == ISD::EXTLOAD)
 
482
    return LD->getAlignment() >= 4 && !LD->isVolatile();
 
483
  return false;
 
484
}]>;
 
485
 
 
486
def loadi8  : PatFrag<(ops node:$ptr), (i8  (dsload node:$ptr))>;
 
487
def loadi64 : PatFrag<(ops node:$ptr), (i64 (dsload node:$ptr))>;
 
488
def loadf32 : PatFrag<(ops node:$ptr), (f32 (dsload node:$ptr))>;
 
489
def loadf64 : PatFrag<(ops node:$ptr), (f64 (dsload node:$ptr))>;
 
490
def loadf80 : PatFrag<(ops node:$ptr), (f80 (dsload node:$ptr))>;
 
491
 
 
492
def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
 
493
def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
 
494
def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
 
495
 
 
496
def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
 
497
def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
 
498
def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
 
499
def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
 
500
def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
 
501
def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
 
502
 
 
503
def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
 
504
def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
 
505
def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
 
506
def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
 
507
def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
 
508
def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
 
509
 
 
510
 
 
511
// An 'and' node with a single use.
 
512
def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
 
513
  return N->hasOneUse();
 
514
}]>;
 
515
// An 'srl' node with a single use.
 
516
def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
 
517
  return N->hasOneUse();
 
518
}]>;
 
519
// An 'trunc' node with a single use.
 
520
def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
 
521
  return N->hasOneUse();
 
522
}]>;
 
523
 
 
524
// Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
 
525
def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
 
526
  if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
 
527
    return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
 
528
 
 
529
  unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
 
530
  APInt Mask = APInt::getAllOnesValue(BitWidth);
 
531
  APInt KnownZero0, KnownOne0;
 
532
  CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
 
533
  APInt KnownZero1, KnownOne1;
 
534
  CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
 
535
  return (~KnownZero0 & ~KnownZero1) == 0;
 
536
}]>;
 
537
 
 
538
//===----------------------------------------------------------------------===//
 
539
// Instruction list...
 
540
//
 
541
 
 
542
// ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
 
543
// a stack adjustment and the codegen must know that they may modify the stack
 
544
// pointer before prolog-epilog rewriting occurs.
 
545
// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
 
546
// sub / add which can clobber EFLAGS.
 
547
let Defs = [ESP, EFLAGS], Uses = [ESP] in {
 
548
def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt),
 
549
                           "#ADJCALLSTACKDOWN",
 
550
                           [(X86callseq_start timm:$amt)]>,
 
551
                          Requires<[In32BitMode]>;
 
552
def ADJCALLSTACKUP32   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
 
553
                           "#ADJCALLSTACKUP",
 
554
                           [(X86callseq_end timm:$amt1, timm:$amt2)]>,
 
555
                          Requires<[In32BitMode]>;
 
556
}
 
557
 
 
558
// x86-64 va_start lowering magic.
 
559
let usesCustomInserter = 1 in {
 
560
def VASTART_SAVE_XMM_REGS : I<0, Pseudo,
 
561
                              (outs),
 
562
                              (ins GR8:$al,
 
563
                                   i64imm:$regsavefi, i64imm:$offset,
 
564
                                   variable_ops),
 
565
                              "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset",
 
566
                              [(X86vastart_save_xmm_regs GR8:$al,
 
567
                                                         imm:$regsavefi,
 
568
                                                         imm:$offset)]>;
 
569
 
 
570
// Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets.  Calls
 
571
// to _alloca is needed to probe the stack when allocating more than 4k bytes in
 
572
// one go. Touching the stack at 4K increments is necessary to ensure that the
 
573
// guard pages used by the OS virtual memory manager are allocated in correct
 
574
// sequence.
 
575
// The main point of having separate instruction are extra unmodelled effects
 
576
// (compared to ordinary calls) like stack pointer change.
 
577
 
 
578
let Defs = [EAX, ESP, EFLAGS], Uses = [ESP] in
 
579
  def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins),
 
580
                       "# dynamic stack allocation",
 
581
                       [(X86MingwAlloca)]>;
 
582
}
 
583
 
 
584
// Nop
 
585
let neverHasSideEffects = 1 in {
 
586
  def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
 
587
  def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
 
588
                "nop{w}\t$zero", []>, TB, OpSize;
 
589
  def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
 
590
                "nop{l}\t$zero", []>, TB;
 
591
}
 
592
 
 
593
// Trap
 
594
let Uses = [EFLAGS] in {
 
595
  def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>;
 
596
}
 
597
def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3",
 
598
              [(int_x86_int (i8 3))]>;
 
599
// FIXME: need to make sure that "int $3" matches int3
 
600
def INT : Ii8<0xcd, RawFrm, (outs), (ins i8imm:$trap), "int\t$trap",
 
601
              [(int_x86_int imm:$trap)]>;
 
602
def IRET16 : I<0xcf, RawFrm, (outs), (ins), "iret{w}", []>, OpSize;
 
603
def IRET32 : I<0xcf, RawFrm, (outs), (ins), "iret{l}", []>;
 
604
 
 
605
// PIC base construction.  This expands to code that looks like this:
 
606
//     call  $next_inst
 
607
//     popl %destreg"
 
608
let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in
 
609
  def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label),
 
610
                      "", []>;
 
611
 
 
612
//===----------------------------------------------------------------------===//
 
613
//  Control Flow Instructions.
 
614
//
 
615
 
 
616
// Return instructions.
 
617
let isTerminator = 1, isReturn = 1, isBarrier = 1,
 
618
    hasCtrlDep = 1, FPForm = SpecialFP in {
 
619
  def RET    : I   <0xC3, RawFrm, (outs), (ins variable_ops),
 
620
                    "ret",
 
621
                    [(X86retflag 0)]>;
 
622
  def RETI   : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
 
623
                    "ret\t$amt",
 
624
                    [(X86retflag timm:$amt)]>;
 
625
  def LRET   : I   <0xCB, RawFrm, (outs), (ins),
 
626
                    "lret", []>;
 
627
  def LRETI  : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
 
628
                    "lret\t$amt", []>;
 
629
}
 
630
 
 
631
// Unconditional branches.
 
632
let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
 
633
  def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
 
634
                        "jmp\t$dst", [(br bb:$dst)]>;
 
635
  def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
 
636
                       "jmp\t$dst", []>;
 
637
}
 
638
 
 
639
// Conditional Branches.
 
640
let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
 
641
  multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
 
642
    def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, []>;
 
643
    def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
 
644
                       [(X86brcond bb:$dst, Cond, EFLAGS)]>, TB;
 
645
  }
 
646
}
 
647
 
 
648
defm JO  : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
 
649
defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
 
650
defm JB  : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
 
651
defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
 
652
defm JE  : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
 
653
defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
 
654
defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
 
655
defm JA  : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
 
656
defm JS  : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
 
657
defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
 
658
defm JP  : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
 
659
defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
 
660
defm JL  : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
 
661
defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
 
662
defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
 
663
defm JG  : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
 
664
 
 
665
// FIXME: What about the CX/RCX versions of this instruction?
 
666
let Uses = [ECX], isBranch = 1, isTerminator = 1 in
 
667
  def JCXZ8 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
 
668
                       "jcxz\t$dst", []>;
 
669
 
 
670
 
 
671
// Indirect branches
 
672
let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
 
673
  def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
 
674
                     [(brind GR32:$dst)]>, Requires<[In32BitMode]>;
 
675
  def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
 
676
                     [(brind (loadi32 addr:$dst))]>, Requires<[In32BitMode]>;
 
677
                     
 
678
  def FARJMP16i  : Iseg16<0xEA, RawFrmImm16, (outs), 
 
679
                          (ins i16imm:$off, i16imm:$seg),
 
680
                          "ljmp{w}\t{$seg, $off|$off, $seg}", []>, OpSize;
 
681
  def FARJMP32i  : Iseg32<0xEA, RawFrmImm16, (outs),
 
682
                          (ins i32imm:$off, i16imm:$seg),
 
683
                          "ljmp{l}\t{$seg, $off|$off, $seg}", []>;                     
 
684
 
 
685
  def FARJMP16m  : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst), 
 
686
                     "ljmp{w}\t{*}$dst", []>, OpSize;
 
687
  def FARJMP32m  : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
 
688
                     "ljmp{l}\t{*}$dst", []>;
 
689
}
 
690
 
 
691
 
 
692
// Loop instructions
 
693
 
 
694
def LOOP   : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
 
695
def LOOPE  : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
 
696
def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
 
697
 
 
698
//===----------------------------------------------------------------------===//
 
699
//  Call Instructions...
 
700
//
 
701
let isCall = 1 in
 
702
  // All calls clobber the non-callee saved registers. ESP is marked as
 
703
  // a use to prevent stack-pointer assignments that appear immediately
 
704
  // before calls from potentially appearing dead. Uses for argument
 
705
  // registers are added manually.
 
706
  let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
 
707
              MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
 
708
              XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
 
709
              XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
 
710
      Uses = [ESP] in {
 
711
    def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
 
712
                           (outs), (ins i32imm_pcrel:$dst,variable_ops),
 
713
                           "call\t$dst", []>;
 
714
    def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
 
715
                        "call\t{*}$dst", [(X86call GR32:$dst)]>;
 
716
    def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
 
717
                        "call\t{*}$dst", [(X86call (loadi32 addr:$dst))]>;
 
718
  
 
719
    def FARCALL16i  : Iseg16<0x9A, RawFrmImm16, (outs), 
 
720
                             (ins i16imm:$off, i16imm:$seg),
 
721
                             "lcall{w}\t{$seg, $off|$off, $seg}", []>, OpSize;
 
722
    def FARCALL32i  : Iseg32<0x9A, RawFrmImm16, (outs),
 
723
                             (ins i32imm:$off, i16imm:$seg),
 
724
                             "lcall{l}\t{$seg, $off|$off, $seg}", []>;
 
725
                             
 
726
    def FARCALL16m  : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
 
727
                        "lcall{w}\t{*}$dst", []>, OpSize;
 
728
    def FARCALL32m  : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
 
729
                        "lcall{l}\t{*}$dst", []>;
 
730
 
 
731
    // callw for 16 bit code for the assembler.
 
732
    let isAsmParserOnly = 1 in
 
733
      def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
 
734
                       (outs), (ins i16imm_pcrel:$dst, variable_ops),
 
735
                       "callw\t$dst", []>, OpSize;
 
736
  }
 
737
 
 
738
// Constructing a stack frame.
 
739
 
 
740
def ENTER : I<0xC8, RawFrm, (outs), (ins i16imm:$len, i8imm:$lvl),
 
741
              "enter\t$len, $lvl", []>;
 
742
 
 
743
// Tail call stuff.
 
744
 
 
745
let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
 
746
    isCodeGenOnly = 1 in
 
747
  let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
 
748
              MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
 
749
              XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
 
750
              XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
 
751
      Uses = [ESP] in {
 
752
  def TCRETURNdi : I<0, Pseudo, (outs), 
 
753
                     (ins i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
 
754
                   "#TC_RETURN $dst $offset", []>;
 
755
  def TCRETURNri : I<0, Pseudo, (outs), 
 
756
                     (ins GR32_TC:$dst, i32imm:$offset, variable_ops),
 
757
                     "#TC_RETURN $dst $offset", []>;
 
758
  let mayLoad = 1 in
 
759
  def TCRETURNmi : I<0, Pseudo, (outs), 
 
760
                     (ins i32mem_TC:$dst, i32imm:$offset, variable_ops),
 
761
                     "#TC_RETURN $dst $offset", []>;
 
762
 
 
763
  // FIXME: The should be pseudo instructions that are lowered when going to
 
764
  // mcinst.
 
765
  def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
 
766
                           (ins i32imm_pcrel:$dst, variable_ops),
 
767
                 "jmp\t$dst  # TAILCALL",
 
768
                 []>;
 
769
  def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32_TC:$dst, variable_ops), 
 
770
                   "", []>;  // FIXME: Remove encoding when JIT is dead.
 
771
  let mayLoad = 1 in
 
772
  def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst, variable_ops),
 
773
                   "jmp{l}\t{*}$dst  # TAILCALL", []>;
 
774
}
 
775
 
 
776
//===----------------------------------------------------------------------===//
 
777
//  Miscellaneous Instructions...
 
778
//
 
779
let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
 
780
def LEAVE    : I<0xC9, RawFrm,
 
781
                 (outs), (ins), "leave", []>, Requires<[In32BitMode]>;
 
782
 
 
783
def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
784
                   "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
 
785
let mayLoad = 1 in
 
786
def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
 
787
                   "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
 
788
def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
789
                   "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
 
790
let mayLoad = 1 in
 
791
def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
792
                   "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
 
793
 
 
794
let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
 
795
let mayLoad = 1 in {
 
796
def POP16r  : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
 
797
  OpSize;
 
798
def POP32r  : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
 
799
def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
 
800
  OpSize;
 
801
def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
 
802
  OpSize;
 
803
def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
 
804
def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
 
805
}
 
806
 
 
807
let mayStore = 1 in {
 
808
def PUSH16r  : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
 
809
  OpSize;
 
810
def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
 
811
def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
 
812
  OpSize;
 
813
def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
 
814
  OpSize;
 
815
def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
 
816
def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
 
817
}
 
818
}
 
819
 
 
820
let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
 
821
def PUSHi8   : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 
 
822
                      "push{l}\t$imm", []>;
 
823
def PUSHi16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
 
824
                      "push{w}\t$imm", []>, OpSize;
 
825
def PUSHi32  : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 
 
826
                      "push{l}\t$imm", []>;
 
827
}
 
828
 
 
829
let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
 
830
def POPF16   : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
 
831
def POPF32   : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
 
832
               Requires<[In32BitMode]>;
 
833
}
 
834
let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
 
835
def PUSHF16  : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
 
836
def PUSHF32  : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
 
837
               Requires<[In32BitMode]>;
 
838
}
 
839
 
 
840
let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
 
841
    mayLoad=1, neverHasSideEffects=1 in {
 
842
def POPA32   : I<0x61, RawFrm, (outs), (ins), "popa{l}", []>,
 
843
               Requires<[In32BitMode]>;
 
844
}
 
845
let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
 
846
    mayStore=1, neverHasSideEffects=1 in {
 
847
def PUSHA32  : I<0x60, RawFrm, (outs), (ins), "pusha{l}", []>,
 
848
               Requires<[In32BitMode]>;
 
849
}
 
850
 
 
851
let Uses = [EFLAGS], Constraints = "$src = $dst" in     // GR32 = bswap GR32
 
852
  def BSWAP32r : I<0xC8, AddRegFrm,
 
853
                   (outs GR32:$dst), (ins GR32:$src),
 
854
                   "bswap{l}\t$dst", 
 
855
                   [(set GR32:$dst, (bswap GR32:$src))]>, TB;
 
856
 
 
857
 
 
858
// Bit scan instructions.
 
859
let Defs = [EFLAGS] in {
 
860
def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
861
                 "bsf{w}\t{$src, $dst|$dst, $src}",
 
862
                 [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
 
863
def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
 
864
                 "bsf{w}\t{$src, $dst|$dst, $src}",
 
865
                 [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
 
866
                 OpSize;
 
867
def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
868
                 "bsf{l}\t{$src, $dst|$dst, $src}",
 
869
                 [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
 
870
def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
871
                 "bsf{l}\t{$src, $dst|$dst, $src}",
 
872
                 [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
 
873
 
 
874
def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
875
                 "bsr{w}\t{$src, $dst|$dst, $src}",
 
876
                 [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
 
877
def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
 
878
                 "bsr{w}\t{$src, $dst|$dst, $src}",
 
879
                 [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
 
880
                 OpSize;
 
881
def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
882
                 "bsr{l}\t{$src, $dst|$dst, $src}",
 
883
                 [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
 
884
def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
885
                 "bsr{l}\t{$src, $dst|$dst, $src}",
 
886
                 [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
 
887
} // Defs = [EFLAGS]
 
888
 
 
889
let neverHasSideEffects = 1 in
 
890
def LEA16r   : I<0x8D, MRMSrcMem,
 
891
                 (outs GR16:$dst), (ins i32mem:$src),
 
892
                 "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
 
893
let isReMaterializable = 1 in
 
894
def LEA32r   : I<0x8D, MRMSrcMem,
 
895
                 (outs GR32:$dst), (ins i32mem:$src),
 
896
                 "lea{l}\t{$src|$dst}, {$dst|$src}",
 
897
                 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
 
898
 
 
899
let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in {
 
900
def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
 
901
                  [(X86rep_movs i8)]>, REP;
 
902
def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
 
903
                  [(X86rep_movs i16)]>, REP, OpSize;
 
904
def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
 
905
                  [(X86rep_movs i32)]>, REP;
 
906
}
 
907
 
 
908
// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
 
909
let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
 
910
def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
 
911
def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
 
912
def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
 
913
}
 
914
 
 
915
let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in
 
916
def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
 
917
                  [(X86rep_stos i8)]>, REP;
 
918
let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in
 
919
def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
 
920
                  [(X86rep_stos i16)]>, REP, OpSize;
 
921
let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in
 
922
def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
 
923
                  [(X86rep_stos i32)]>, REP;
 
924
 
 
925
// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
 
926
let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
 
927
def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
 
928
let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
 
929
def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
 
930
let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
 
931
def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
 
932
 
 
933
def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
 
934
def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
 
935
def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
 
936
 
 
937
def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
 
938
def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
 
939
def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
 
940
 
 
941
let Defs = [RAX, RDX] in
 
942
def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>,
 
943
            TB;
 
944
 
 
945
let Defs = [RAX, RCX, RDX] in
 
946
def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", []>, TB;
 
947
 
 
948
let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
 
949
def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
 
950
}
 
951
 
 
952
def SYSCALL  : I<0x05, RawFrm,
 
953
                 (outs), (ins), "syscall", []>, TB;
 
954
def SYSRET   : I<0x07, RawFrm,
 
955
                 (outs), (ins), "sysret", []>, TB;
 
956
def SYSENTER : I<0x34, RawFrm,
 
957
                 (outs), (ins), "sysenter", []>, TB;
 
958
def SYSEXIT  : I<0x35, RawFrm,
 
959
                 (outs), (ins), "sysexit", []>, TB, Requires<[In32BitMode]>;
 
960
 
 
961
def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
 
962
 
 
963
 
 
964
//===----------------------------------------------------------------------===//
 
965
//  Input/Output Instructions...
 
966
//
 
967
let Defs = [AL], Uses = [DX] in
 
968
def IN8rr  : I<0xEC, RawFrm, (outs), (ins),
 
969
               "in{b}\t{%dx, %al|%AL, %DX}", []>;
 
970
let Defs = [AX], Uses = [DX] in
 
971
def IN16rr : I<0xED, RawFrm, (outs), (ins),
 
972
               "in{w}\t{%dx, %ax|%AX, %DX}", []>,  OpSize;
 
973
let Defs = [EAX], Uses = [DX] in
 
974
def IN32rr : I<0xED, RawFrm, (outs), (ins),
 
975
               "in{l}\t{%dx, %eax|%EAX, %DX}", []>;
 
976
 
 
977
let Defs = [AL] in
 
978
def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins i16i8imm:$port),
 
979
                  "in{b}\t{$port, %al|%AL, $port}", []>;
 
980
let Defs = [AX] in
 
981
def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
 
982
                  "in{w}\t{$port, %ax|%AX, $port}", []>, OpSize;
 
983
let Defs = [EAX] in
 
984
def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
 
985
                  "in{l}\t{$port, %eax|%EAX, $port}", []>;
 
986
 
 
987
let Uses = [DX, AL] in
 
988
def OUT8rr  : I<0xEE, RawFrm, (outs), (ins),
 
989
                "out{b}\t{%al, %dx|%DX, %AL}", []>;
 
990
let Uses = [DX, AX] in
 
991
def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
 
992
                "out{w}\t{%ax, %dx|%DX, %AX}", []>, OpSize;
 
993
let Uses = [DX, EAX] in
 
994
def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
 
995
                "out{l}\t{%eax, %dx|%DX, %EAX}", []>;
 
996
 
 
997
let Uses = [AL] in
 
998
def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins i16i8imm:$port),
 
999
                   "out{b}\t{%al, $port|$port, %AL}", []>;
 
1000
let Uses = [AX] in
 
1001
def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
 
1002
                   "out{w}\t{%ax, $port|$port, %AX}", []>, OpSize;
 
1003
let Uses = [EAX] in
 
1004
def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
 
1005
                   "out{l}\t{%eax, $port|$port, %EAX}", []>;
 
1006
 
 
1007
def IN8  : I<0x6C, RawFrm, (outs), (ins),
 
1008
             "ins{b}", []>;
 
1009
def IN16 : I<0x6D, RawFrm, (outs), (ins),
 
1010
             "ins{w}", []>,  OpSize;
 
1011
def IN32 : I<0x6D, RawFrm, (outs), (ins),
 
1012
             "ins{l}", []>;
 
1013
 
 
1014
//===----------------------------------------------------------------------===//
 
1015
//  Move Instructions...
 
1016
//
 
1017
let neverHasSideEffects = 1 in {
 
1018
def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
 
1019
                "mov{b}\t{$src, $dst|$dst, $src}", []>;
 
1020
def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
 
1021
                "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1022
def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
 
1023
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1024
}
 
1025
let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
 
1026
def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
 
1027
                   "mov{b}\t{$src, $dst|$dst, $src}",
 
1028
                   [(set GR8:$dst, imm:$src)]>;
 
1029
def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
 
1030
                   "mov{w}\t{$src, $dst|$dst, $src}",
 
1031
                   [(set GR16:$dst, imm:$src)]>, OpSize;
 
1032
def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
 
1033
                   "mov{l}\t{$src, $dst|$dst, $src}",
 
1034
                   [(set GR32:$dst, imm:$src)]>;
 
1035
}
 
1036
 
 
1037
def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
 
1038
                   "mov{b}\t{$src, $dst|$dst, $src}",
 
1039
                   [(store (i8 imm:$src), addr:$dst)]>;
 
1040
def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
 
1041
                   "mov{w}\t{$src, $dst|$dst, $src}",
 
1042
                   [(store (i16 imm:$src), addr:$dst)]>, OpSize;
 
1043
def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
 
1044
                   "mov{l}\t{$src, $dst|$dst, $src}",
 
1045
                   [(store (i32 imm:$src), addr:$dst)]>;
 
1046
 
 
1047
/// moffs8, moffs16 and moffs32 versions of moves.  The immediate is a
 
1048
/// 32-bit offset from the PC.  These are only valid in x86-32 mode.
 
1049
def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
 
1050
                   "mov{b}\t{$src, %al|%al, $src}", []>,
 
1051
                   Requires<[In32BitMode]>;
 
1052
def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
 
1053
                      "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize,
 
1054
                     Requires<[In32BitMode]>;
 
1055
def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
 
1056
                      "mov{l}\t{$src, %eax|%eax, $src}", []>,
 
1057
                     Requires<[In32BitMode]>;
 
1058
def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
 
1059
                   "mov{b}\t{%al, $dst|$dst, %al}", []>,
 
1060
                  Requires<[In32BitMode]>;
 
1061
def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
 
1062
                      "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize,
 
1063
                     Requires<[In32BitMode]>;
 
1064
def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
 
1065
                      "mov{l}\t{%eax, $dst|$dst, %eax}", []>,
 
1066
                     Requires<[In32BitMode]>;
 
1067
                      
 
1068
// Moves to and from segment registers
 
1069
def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
 
1070
                "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1071
def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
 
1072
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1073
def MOV16ms : I<0x8C, MRMDestMem, (outs i16mem:$dst), (ins SEGMENT_REG:$src),
 
1074
                "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1075
def MOV32ms : I<0x8C, MRMDestMem, (outs i32mem:$dst), (ins SEGMENT_REG:$src),
 
1076
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1077
def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
 
1078
                "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1079
def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
 
1080
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1081
def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
 
1082
                "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1083
def MOV32sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i32mem:$src),
 
1084
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1085
 
 
1086
let isCodeGenOnly = 1 in {
 
1087
def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
 
1088
                   "mov{b}\t{$src, $dst|$dst, $src}", []>;
 
1089
def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
1090
                    "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
1091
def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
1092
                    "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1093
}
 
1094
 
 
1095
let canFoldAsLoad = 1, isReMaterializable = 1 in {
 
1096
def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
 
1097
                "mov{b}\t{$src, $dst|$dst, $src}",
 
1098
                [(set GR8:$dst, (loadi8 addr:$src))]>;
 
1099
def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
 
1100
                "mov{w}\t{$src, $dst|$dst, $src}",
 
1101
                [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
 
1102
def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
1103
                "mov{l}\t{$src, $dst|$dst, $src}",
 
1104
                [(set GR32:$dst, (loadi32 addr:$src))]>;
 
1105
}
 
1106
 
 
1107
def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
 
1108
                "mov{b}\t{$src, $dst|$dst, $src}",
 
1109
                [(store GR8:$src, addr:$dst)]>;
 
1110
def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
 
1111
                "mov{w}\t{$src, $dst|$dst, $src}",
 
1112
                [(store GR16:$src, addr:$dst)]>, OpSize;
 
1113
def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
 
1114
                "mov{l}\t{$src, $dst|$dst, $src}",
 
1115
                [(store GR32:$src, addr:$dst)]>;
 
1116
 
 
1117
/// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
 
1118
let isCodeGenOnly = 1 in {
 
1119
let neverHasSideEffects = 1 in
 
1120
def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
 
1121
                "mov{l}\t{$src, $dst|$dst, $src}", []>;
 
1122
 
 
1123
let mayLoad = 1,
 
1124
    canFoldAsLoad = 1, isReMaterializable = 1 in
 
1125
def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
 
1126
                "mov{l}\t{$src, $dst|$dst, $src}",
 
1127
                []>;
 
1128
 
 
1129
let mayStore = 1 in
 
1130
def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
 
1131
                "mov{l}\t{$src, $dst|$dst, $src}",
 
1132
                []>;
 
1133
}
 
1134
 
 
1135
// Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
 
1136
// that they can be used for copying and storing h registers, which can't be
 
1137
// encoded when a REX prefix is present.
 
1138
let isCodeGenOnly = 1 in {
 
1139
let neverHasSideEffects = 1 in
 
1140
def MOV8rr_NOREX : I<0x88, MRMDestReg,
 
1141
                     (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
 
1142
                     "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
 
1143
let mayStore = 1 in
 
1144
def MOV8mr_NOREX : I<0x88, MRMDestMem,
 
1145
                     (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
 
1146
                     "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
 
1147
let mayLoad = 1,
 
1148
    canFoldAsLoad = 1, isReMaterializable = 1 in
 
1149
def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
 
1150
                     (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
 
1151
                     "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
 
1152
}
 
1153
 
 
1154
// Moves to and from debug registers
 
1155
def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
 
1156
                "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
1157
def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
 
1158
                "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
1159
                
 
1160
// Moves to and from control registers
 
1161
def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
 
1162
                "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
1163
def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
 
1164
                "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
1165
 
 
1166
//===----------------------------------------------------------------------===//
 
1167
//  Fixed-Register Multiplication and Division Instructions...
 
1168
//
 
1169
 
 
1170
// Extra precision multiplication
 
1171
 
 
1172
// AL is really implied by AX, but the registers in Defs must match the
 
1173
// SDNode results (i8, i32).
 
1174
let Defs = [AL,EFLAGS,AX], Uses = [AL] in
 
1175
def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
 
1176
               // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
 
1177
               // This probably ought to be moved to a def : Pat<> if the
 
1178
               // syntax can be accepted.
 
1179
               [(set AL, (mul AL, GR8:$src)),
 
1180
                (implicit EFLAGS)]>;     // AL,AH = AL*GR8
 
1181
 
 
1182
let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
 
1183
def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src),
 
1184
               "mul{w}\t$src", 
 
1185
               []>, OpSize;    // AX,DX = AX*GR16
 
1186
 
 
1187
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
 
1188
def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src),
 
1189
               "mul{l}\t$src",
 
1190
               []>; // EAX,EDX = EAX*GR32
 
1191
 
 
1192
let Defs = [AL,EFLAGS,AX], Uses = [AL] in
 
1193
def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
 
1194
               "mul{b}\t$src",
 
1195
               // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
 
1196
               // This probably ought to be moved to a def : Pat<> if the
 
1197
               // syntax can be accepted.
 
1198
               [(set AL, (mul AL, (loadi8 addr:$src))),
 
1199
                (implicit EFLAGS)]>;   // AL,AH = AL*[mem8]
 
1200
 
 
1201
let mayLoad = 1, neverHasSideEffects = 1 in {
 
1202
let Defs = [AX,DX,EFLAGS], Uses = [AX] in
 
1203
def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
 
1204
               "mul{w}\t$src",
 
1205
               []>, OpSize; // AX,DX = AX*[mem16]
 
1206
 
 
1207
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
 
1208
def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
 
1209
              "mul{l}\t$src",
 
1210
              []>;          // EAX,EDX = EAX*[mem32]
 
1211
}
 
1212
 
 
1213
let neverHasSideEffects = 1 in {
 
1214
let Defs = [AL,EFLAGS,AX], Uses = [AL] in
 
1215
def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
 
1216
              // AL,AH = AL*GR8
 
1217
let Defs = [AX,DX,EFLAGS], Uses = [AX] in
 
1218
def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
 
1219
              OpSize;    // AX,DX = AX*GR16
 
1220
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
 
1221
def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
 
1222
              // EAX,EDX = EAX*GR32
 
1223
let mayLoad = 1 in {
 
1224
let Defs = [AL,EFLAGS,AX], Uses = [AL] in
 
1225
def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
 
1226
                "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
 
1227
let Defs = [AX,DX,EFLAGS], Uses = [AX] in
 
1228
def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
 
1229
                "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
 
1230
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
 
1231
def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
 
1232
                "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
 
1233
}
 
1234
} // neverHasSideEffects
 
1235
 
 
1236
// unsigned division/remainder
 
1237
let Defs = [AL,EFLAGS,AX], Uses = [AX] in
 
1238
def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
 
1239
               "div{b}\t$src", []>;
 
1240
let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
 
1241
def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
 
1242
               "div{w}\t$src", []>, OpSize;
 
1243
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
 
1244
def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
 
1245
               "div{l}\t$src", []>;
 
1246
let mayLoad = 1 in {
 
1247
let Defs = [AL,EFLAGS,AX], Uses = [AX] in
 
1248
def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
 
1249
               "div{b}\t$src", []>;
 
1250
let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
 
1251
def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
 
1252
               "div{w}\t$src", []>, OpSize;
 
1253
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
 
1254
                                                    // EDX:EAX/[mem32] = EAX,EDX
 
1255
def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
 
1256
               "div{l}\t$src", []>;
 
1257
}
 
1258
 
 
1259
// Signed division/remainder.
 
1260
let Defs = [AL,EFLAGS,AX], Uses = [AX] in
 
1261
def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
 
1262
               "idiv{b}\t$src", []>;
 
1263
let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
 
1264
def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
 
1265
               "idiv{w}\t$src", []>, OpSize;
 
1266
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
 
1267
def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
 
1268
               "idiv{l}\t$src", []>;
 
1269
let mayLoad = 1, mayLoad = 1 in {
 
1270
let Defs = [AL,EFLAGS,AX], Uses = [AX] in
 
1271
def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
 
1272
               "idiv{b}\t$src", []>;
 
1273
let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
 
1274
def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
 
1275
               "idiv{w}\t$src", []>, OpSize;
 
1276
let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
 
1277
def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src), 
 
1278
                                                    // EDX:EAX/[mem32] = EAX,EDX
 
1279
               "idiv{l}\t$src", []>;
 
1280
}
 
1281
 
 
1282
//===----------------------------------------------------------------------===//
 
1283
//  Two address Instructions.
 
1284
//
 
1285
let Constraints = "$src1 = $dst" in {
 
1286
 
 
1287
// Conditional moves
 
1288
let Uses = [EFLAGS] in {
 
1289
 
 
1290
let Predicates = [HasCMov] in {
 
1291
let isCommutable = 1 in {
 
1292
def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, GR16 = GR16
 
1293
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1294
                  "cmovb{w}\t{$src2, $dst|$dst, $src2}",
 
1295
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1296
                                   X86_COND_B, EFLAGS))]>,
 
1297
                  TB, OpSize;
 
1298
def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, GR32 = GR32
 
1299
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1300
                  "cmovb{l}\t{$src2, $dst|$dst, $src2}",
 
1301
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1302
                                   X86_COND_B, EFLAGS))]>,
 
1303
                   TB;
 
1304
def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, GR16 = GR16
 
1305
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1306
                  "cmovae{w}\t{$src2, $dst|$dst, $src2}",
 
1307
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1308
                                   X86_COND_AE, EFLAGS))]>,
 
1309
                   TB, OpSize;
 
1310
def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, GR32 = GR32
 
1311
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1312
                  "cmovae{l}\t{$src2, $dst|$dst, $src2}",
 
1313
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1314
                                   X86_COND_AE, EFLAGS))]>,
 
1315
                   TB;
 
1316
def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, GR16 = GR16
 
1317
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1318
                  "cmove{w}\t{$src2, $dst|$dst, $src2}",
 
1319
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1320
                                   X86_COND_E, EFLAGS))]>,
 
1321
                   TB, OpSize;
 
1322
def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, GR32 = GR32
 
1323
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1324
                  "cmove{l}\t{$src2, $dst|$dst, $src2}",
 
1325
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1326
                                   X86_COND_E, EFLAGS))]>,
 
1327
                   TB;
 
1328
def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, GR16 = GR16
 
1329
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1330
                  "cmovne{w}\t{$src2, $dst|$dst, $src2}",
 
1331
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1332
                                   X86_COND_NE, EFLAGS))]>,
 
1333
                   TB, OpSize;
 
1334
def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, GR32 = GR32
 
1335
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1336
                  "cmovne{l}\t{$src2, $dst|$dst, $src2}",
 
1337
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1338
                                   X86_COND_NE, EFLAGS))]>,
 
1339
                   TB;
 
1340
def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, GR16 = GR16
 
1341
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1342
                  "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
 
1343
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1344
                                   X86_COND_BE, EFLAGS))]>,
 
1345
                   TB, OpSize;
 
1346
def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, GR32 = GR32
 
1347
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1348
                  "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
 
1349
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1350
                                   X86_COND_BE, EFLAGS))]>,
 
1351
                   TB;
 
1352
def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, GR16 = GR16
 
1353
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1354
                  "cmova{w}\t{$src2, $dst|$dst, $src2}",
 
1355
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1356
                                   X86_COND_A, EFLAGS))]>,
 
1357
                   TB, OpSize;
 
1358
def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, GR32 = GR32
 
1359
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1360
                  "cmova{l}\t{$src2, $dst|$dst, $src2}",
 
1361
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1362
                                   X86_COND_A, EFLAGS))]>,
 
1363
                   TB;
 
1364
def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, GR16 = GR16
 
1365
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1366
                  "cmovl{w}\t{$src2, $dst|$dst, $src2}",
 
1367
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1368
                                   X86_COND_L, EFLAGS))]>,
 
1369
                   TB, OpSize;
 
1370
def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, GR32 = GR32
 
1371
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1372
                  "cmovl{l}\t{$src2, $dst|$dst, $src2}",
 
1373
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1374
                                   X86_COND_L, EFLAGS))]>,
 
1375
                   TB;
 
1376
def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, GR16 = GR16
 
1377
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1378
                  "cmovge{w}\t{$src2, $dst|$dst, $src2}",
 
1379
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1380
                                   X86_COND_GE, EFLAGS))]>,
 
1381
                   TB, OpSize;
 
1382
def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, GR32 = GR32
 
1383
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1384
                  "cmovge{l}\t{$src2, $dst|$dst, $src2}",
 
1385
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1386
                                   X86_COND_GE, EFLAGS))]>,
 
1387
                   TB;
 
1388
def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, GR16 = GR16
 
1389
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1390
                  "cmovle{w}\t{$src2, $dst|$dst, $src2}",
 
1391
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1392
                                   X86_COND_LE, EFLAGS))]>,
 
1393
                   TB, OpSize;
 
1394
def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, GR32 = GR32
 
1395
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1396
                  "cmovle{l}\t{$src2, $dst|$dst, $src2}",
 
1397
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1398
                                   X86_COND_LE, EFLAGS))]>,
 
1399
                   TB;
 
1400
def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, GR16 = GR16
 
1401
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1402
                  "cmovg{w}\t{$src2, $dst|$dst, $src2}",
 
1403
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1404
                                   X86_COND_G, EFLAGS))]>,
 
1405
                   TB, OpSize;
 
1406
def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, GR32 = GR32
 
1407
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1408
                  "cmovg{l}\t{$src2, $dst|$dst, $src2}",
 
1409
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1410
                                   X86_COND_G, EFLAGS))]>,
 
1411
                   TB;
 
1412
def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, GR16 = GR16
 
1413
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1414
                  "cmovs{w}\t{$src2, $dst|$dst, $src2}",
 
1415
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1416
                                   X86_COND_S, EFLAGS))]>,
 
1417
                  TB, OpSize;
 
1418
def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, GR32 = GR32
 
1419
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1420
                  "cmovs{l}\t{$src2, $dst|$dst, $src2}",
 
1421
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1422
                                   X86_COND_S, EFLAGS))]>,
 
1423
                  TB;
 
1424
def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, GR16 = GR16
 
1425
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1426
                  "cmovns{w}\t{$src2, $dst|$dst, $src2}",
 
1427
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1428
                                   X86_COND_NS, EFLAGS))]>,
 
1429
                  TB, OpSize;
 
1430
def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, GR32 = GR32
 
1431
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1432
                  "cmovns{l}\t{$src2, $dst|$dst, $src2}",
 
1433
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1434
                                   X86_COND_NS, EFLAGS))]>,
 
1435
                  TB;
 
1436
def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, GR16 = GR16
 
1437
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1438
                  "cmovp{w}\t{$src2, $dst|$dst, $src2}",
 
1439
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1440
                                   X86_COND_P, EFLAGS))]>,
 
1441
                  TB, OpSize;
 
1442
def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, GR32 = GR32
 
1443
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1444
                  "cmovp{l}\t{$src2, $dst|$dst, $src2}",
 
1445
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1446
                                   X86_COND_P, EFLAGS))]>,
 
1447
                  TB;
 
1448
def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, GR16 = GR16
 
1449
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1450
                  "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
 
1451
                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1452
                                    X86_COND_NP, EFLAGS))]>,
 
1453
                  TB, OpSize;
 
1454
def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, GR32 = GR32
 
1455
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1456
                  "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
 
1457
                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1458
                                    X86_COND_NP, EFLAGS))]>,
 
1459
                  TB;
 
1460
def CMOVO16rr : I<0x40, MRMSrcReg,       // if overflow, GR16 = GR16
 
1461
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1462
                  "cmovo{w}\t{$src2, $dst|$dst, $src2}",
 
1463
                  [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1464
                                   X86_COND_O, EFLAGS))]>,
 
1465
                  TB, OpSize;
 
1466
def CMOVO32rr : I<0x40, MRMSrcReg,       // if overflow, GR32 = GR32
 
1467
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1468
                  "cmovo{l}\t{$src2, $dst|$dst, $src2}",
 
1469
                  [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1470
                                   X86_COND_O, EFLAGS))]>,
 
1471
                  TB;
 
1472
def CMOVNO16rr : I<0x41, MRMSrcReg,       // if !overflow, GR16 = GR16
 
1473
                  (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1474
                  "cmovno{w}\t{$src2, $dst|$dst, $src2}",
 
1475
                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
 
1476
                                    X86_COND_NO, EFLAGS))]>,
 
1477
                  TB, OpSize;
 
1478
def CMOVNO32rr : I<0x41, MRMSrcReg,       // if !overflow, GR32 = GR32
 
1479
                  (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1480
                  "cmovno{l}\t{$src2, $dst|$dst, $src2}",
 
1481
                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
 
1482
                                    X86_COND_NO, EFLAGS))]>,
 
1483
                  TB;
 
1484
} // isCommutable = 1
 
1485
 
 
1486
def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, GR16 = [mem16]
 
1487
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1488
                  "cmovb{w}\t{$src2, $dst|$dst, $src2}",
 
1489
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1490
                                   X86_COND_B, EFLAGS))]>,
 
1491
                  TB, OpSize;
 
1492
def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, GR32 = [mem32]
 
1493
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1494
                  "cmovb{l}\t{$src2, $dst|$dst, $src2}",
 
1495
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1496
                                   X86_COND_B, EFLAGS))]>,
 
1497
                   TB;
 
1498
def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, GR16 = [mem16]
 
1499
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1500
                  "cmovae{w}\t{$src2, $dst|$dst, $src2}",
 
1501
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1502
                                   X86_COND_AE, EFLAGS))]>,
 
1503
                   TB, OpSize;
 
1504
def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, GR32 = [mem32]
 
1505
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1506
                  "cmovae{l}\t{$src2, $dst|$dst, $src2}",
 
1507
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1508
                                   X86_COND_AE, EFLAGS))]>,
 
1509
                   TB;
 
1510
def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, GR16 = [mem16]
 
1511
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1512
                  "cmove{w}\t{$src2, $dst|$dst, $src2}",
 
1513
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1514
                                   X86_COND_E, EFLAGS))]>,
 
1515
                   TB, OpSize;
 
1516
def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, GR32 = [mem32]
 
1517
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1518
                  "cmove{l}\t{$src2, $dst|$dst, $src2}",
 
1519
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1520
                                   X86_COND_E, EFLAGS))]>,
 
1521
                   TB;
 
1522
def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, GR16 = [mem16]
 
1523
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1524
                  "cmovne{w}\t{$src2, $dst|$dst, $src2}",
 
1525
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1526
                                   X86_COND_NE, EFLAGS))]>,
 
1527
                   TB, OpSize;
 
1528
def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, GR32 = [mem32]
 
1529
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1530
                  "cmovne{l}\t{$src2, $dst|$dst, $src2}",
 
1531
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1532
                                   X86_COND_NE, EFLAGS))]>,
 
1533
                   TB;
 
1534
def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, GR16 = [mem16]
 
1535
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1536
                  "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
 
1537
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1538
                                   X86_COND_BE, EFLAGS))]>,
 
1539
                   TB, OpSize;
 
1540
def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, GR32 = [mem32]
 
1541
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1542
                  "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
 
1543
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1544
                                   X86_COND_BE, EFLAGS))]>,
 
1545
                   TB;
 
1546
def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, GR16 = [mem16]
 
1547
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1548
                  "cmova{w}\t{$src2, $dst|$dst, $src2}",
 
1549
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1550
                                   X86_COND_A, EFLAGS))]>,
 
1551
                   TB, OpSize;
 
1552
def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, GR32 = [mem32]
 
1553
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1554
                  "cmova{l}\t{$src2, $dst|$dst, $src2}",
 
1555
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1556
                                   X86_COND_A, EFLAGS))]>,
 
1557
                   TB;
 
1558
def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, GR16 = [mem16]
 
1559
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1560
                  "cmovl{w}\t{$src2, $dst|$dst, $src2}",
 
1561
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1562
                                   X86_COND_L, EFLAGS))]>,
 
1563
                   TB, OpSize;
 
1564
def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, GR32 = [mem32]
 
1565
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1566
                  "cmovl{l}\t{$src2, $dst|$dst, $src2}",
 
1567
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1568
                                   X86_COND_L, EFLAGS))]>,
 
1569
                   TB;
 
1570
def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, GR16 = [mem16]
 
1571
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1572
                  "cmovge{w}\t{$src2, $dst|$dst, $src2}",
 
1573
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1574
                                   X86_COND_GE, EFLAGS))]>,
 
1575
                   TB, OpSize;
 
1576
def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, GR32 = [mem32]
 
1577
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1578
                  "cmovge{l}\t{$src2, $dst|$dst, $src2}",
 
1579
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1580
                                   X86_COND_GE, EFLAGS))]>,
 
1581
                   TB;
 
1582
def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, GR16 = [mem16]
 
1583
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1584
                  "cmovle{w}\t{$src2, $dst|$dst, $src2}",
 
1585
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1586
                                   X86_COND_LE, EFLAGS))]>,
 
1587
                   TB, OpSize;
 
1588
def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, GR32 = [mem32]
 
1589
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1590
                  "cmovle{l}\t{$src2, $dst|$dst, $src2}",
 
1591
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1592
                                   X86_COND_LE, EFLAGS))]>,
 
1593
                   TB;
 
1594
def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, GR16 = [mem16]
 
1595
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1596
                  "cmovg{w}\t{$src2, $dst|$dst, $src2}",
 
1597
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1598
                                   X86_COND_G, EFLAGS))]>,
 
1599
                   TB, OpSize;
 
1600
def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, GR32 = [mem32]
 
1601
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1602
                  "cmovg{l}\t{$src2, $dst|$dst, $src2}",
 
1603
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1604
                                   X86_COND_G, EFLAGS))]>,
 
1605
                   TB;
 
1606
def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, GR16 = [mem16]
 
1607
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1608
                  "cmovs{w}\t{$src2, $dst|$dst, $src2}",
 
1609
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1610
                                   X86_COND_S, EFLAGS))]>,
 
1611
                  TB, OpSize;
 
1612
def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, GR32 = [mem32]
 
1613
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1614
                  "cmovs{l}\t{$src2, $dst|$dst, $src2}",
 
1615
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1616
                                   X86_COND_S, EFLAGS))]>,
 
1617
                  TB;
 
1618
def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, GR16 = [mem16]
 
1619
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1620
                  "cmovns{w}\t{$src2, $dst|$dst, $src2}",
 
1621
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1622
                                   X86_COND_NS, EFLAGS))]>,
 
1623
                  TB, OpSize;
 
1624
def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, GR32 = [mem32]
 
1625
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1626
                  "cmovns{l}\t{$src2, $dst|$dst, $src2}",
 
1627
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1628
                                   X86_COND_NS, EFLAGS))]>,
 
1629
                  TB;
 
1630
def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, GR16 = [mem16]
 
1631
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1632
                  "cmovp{w}\t{$src2, $dst|$dst, $src2}",
 
1633
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1634
                                   X86_COND_P, EFLAGS))]>,
 
1635
                  TB, OpSize;
 
1636
def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, GR32 = [mem32]
 
1637
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1638
                  "cmovp{l}\t{$src2, $dst|$dst, $src2}",
 
1639
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1640
                                   X86_COND_P, EFLAGS))]>,
 
1641
                  TB;
 
1642
def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, GR16 = [mem16]
 
1643
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1644
                  "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
 
1645
                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1646
                                    X86_COND_NP, EFLAGS))]>,
 
1647
                  TB, OpSize;
 
1648
def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, GR32 = [mem32]
 
1649
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1650
                  "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
 
1651
                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1652
                                    X86_COND_NP, EFLAGS))]>,
 
1653
                  TB;
 
1654
def CMOVO16rm : I<0x40, MRMSrcMem,       // if overflow, GR16 = [mem16]
 
1655
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1656
                  "cmovo{w}\t{$src2, $dst|$dst, $src2}",
 
1657
                  [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1658
                                   X86_COND_O, EFLAGS))]>,
 
1659
                  TB, OpSize;
 
1660
def CMOVO32rm : I<0x40, MRMSrcMem,       // if overflow, GR32 = [mem32]
 
1661
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1662
                  "cmovo{l}\t{$src2, $dst|$dst, $src2}",
 
1663
                  [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1664
                                   X86_COND_O, EFLAGS))]>,
 
1665
                  TB;
 
1666
def CMOVNO16rm : I<0x41, MRMSrcMem,       // if !overflow, GR16 = [mem16]
 
1667
                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1668
                  "cmovno{w}\t{$src2, $dst|$dst, $src2}",
 
1669
                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
 
1670
                                    X86_COND_NO, EFLAGS))]>,
 
1671
                  TB, OpSize;
 
1672
def CMOVNO32rm : I<0x41, MRMSrcMem,       // if !overflow, GR32 = [mem32]
 
1673
                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1674
                  "cmovno{l}\t{$src2, $dst|$dst, $src2}",
 
1675
                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
 
1676
                                    X86_COND_NO, EFLAGS))]>,
 
1677
                  TB;
 
1678
} // Predicates = [HasCMov]
 
1679
 
 
1680
// X86 doesn't have 8-bit conditional moves. Use a customInserter to
 
1681
// emit control flow. An alternative to this is to mark i8 SELECT as Promote,
 
1682
// however that requires promoting the operands, and can induce additional
 
1683
// i8 register pressure. Note that CMOV_GR8 is conservatively considered to
 
1684
// clobber EFLAGS, because if one of the operands is zero, the expansion
 
1685
// could involve an xor.
 
1686
let usesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] in {
 
1687
def CMOV_GR8 : I<0, Pseudo,
 
1688
                 (outs GR8:$dst), (ins GR8:$src1, GR8:$src2, i8imm:$cond),
 
1689
                 "#CMOV_GR8 PSEUDO!",
 
1690
                 [(set GR8:$dst, (X86cmov GR8:$src1, GR8:$src2,
 
1691
                                          imm:$cond, EFLAGS))]>;
 
1692
 
 
1693
let Predicates = [NoCMov] in {
 
1694
def CMOV_GR32 : I<0, Pseudo,
 
1695
                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$cond),
 
1696
                    "#CMOV_GR32* PSEUDO!",
 
1697
                    [(set GR32:$dst,
 
1698
                      (X86cmov GR32:$src1, GR32:$src2, imm:$cond, EFLAGS))]>;
 
1699
def CMOV_GR16 : I<0, Pseudo,
 
1700
                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cond),
 
1701
                    "#CMOV_GR16* PSEUDO!",
 
1702
                    [(set GR16:$dst,
 
1703
                      (X86cmov GR16:$src1, GR16:$src2, imm:$cond, EFLAGS))]>;
 
1704
def CMOV_RFP32 : I<0, Pseudo,
 
1705
                    (outs RFP32:$dst),
 
1706
                    (ins RFP32:$src1, RFP32:$src2, i8imm:$cond),
 
1707
                    "#CMOV_RFP32 PSEUDO!",
 
1708
                    [(set RFP32:$dst,
 
1709
                      (X86cmov RFP32:$src1, RFP32:$src2, imm:$cond,
 
1710
                                                  EFLAGS))]>;
 
1711
def CMOV_RFP64 : I<0, Pseudo,
 
1712
                    (outs RFP64:$dst),
 
1713
                    (ins RFP64:$src1, RFP64:$src2, i8imm:$cond),
 
1714
                    "#CMOV_RFP64 PSEUDO!",
 
1715
                    [(set RFP64:$dst,
 
1716
                      (X86cmov RFP64:$src1, RFP64:$src2, imm:$cond,
 
1717
                                                  EFLAGS))]>;
 
1718
def CMOV_RFP80 : I<0, Pseudo,
 
1719
                    (outs RFP80:$dst),
 
1720
                    (ins RFP80:$src1, RFP80:$src2, i8imm:$cond),
 
1721
                    "#CMOV_RFP80 PSEUDO!",
 
1722
                    [(set RFP80:$dst,
 
1723
                      (X86cmov RFP80:$src1, RFP80:$src2, imm:$cond,
 
1724
                                                  EFLAGS))]>;
 
1725
} // Predicates = [NoCMov]
 
1726
} // UsesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] 
 
1727
} // Uses = [EFLAGS]
 
1728
 
 
1729
 
 
1730
// unary instructions
 
1731
let CodeSize = 2 in {
 
1732
let Defs = [EFLAGS] in {
 
1733
def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
 
1734
               "neg{b}\t$dst",
 
1735
               [(set GR8:$dst, (ineg GR8:$src1)),
 
1736
                (implicit EFLAGS)]>;
 
1737
def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
 
1738
               "neg{w}\t$dst",
 
1739
               [(set GR16:$dst, (ineg GR16:$src1)),
 
1740
                (implicit EFLAGS)]>, OpSize;
 
1741
def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
 
1742
               "neg{l}\t$dst",
 
1743
               [(set GR32:$dst, (ineg GR32:$src1)),
 
1744
                (implicit EFLAGS)]>;
 
1745
                
 
1746
let Constraints = "" in {
 
1747
  def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
 
1748
                 "neg{b}\t$dst",
 
1749
                 [(store (ineg (loadi8 addr:$dst)), addr:$dst),
 
1750
                  (implicit EFLAGS)]>;
 
1751
  def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
 
1752
                 "neg{w}\t$dst",
 
1753
                 [(store (ineg (loadi16 addr:$dst)), addr:$dst),
 
1754
                  (implicit EFLAGS)]>, OpSize;
 
1755
  def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
 
1756
                 "neg{l}\t$dst",
 
1757
                 [(store (ineg (loadi32 addr:$dst)), addr:$dst),
 
1758
                  (implicit EFLAGS)]>;
 
1759
} // Constraints = ""
 
1760
} // Defs = [EFLAGS]
 
1761
 
 
1762
// Match xor -1 to not. Favors these over a move imm + xor to save code size.
 
1763
let AddedComplexity = 15 in {
 
1764
def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
 
1765
               "not{b}\t$dst",
 
1766
               [(set GR8:$dst, (not GR8:$src1))]>;
 
1767
def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
 
1768
               "not{w}\t$dst",
 
1769
               [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
 
1770
def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
 
1771
               "not{l}\t$dst",
 
1772
               [(set GR32:$dst, (not GR32:$src1))]>;
 
1773
}
 
1774
let Constraints = "" in {
 
1775
  def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
 
1776
                 "not{b}\t$dst",
 
1777
                 [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
 
1778
  def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
 
1779
                 "not{w}\t$dst",
 
1780
                 [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
 
1781
  def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
 
1782
                 "not{l}\t$dst",
 
1783
                 [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
 
1784
} // Constraints = ""
 
1785
} // CodeSize
 
1786
 
 
1787
// TODO: inc/dec is slow for P4, but fast for Pentium-M.
 
1788
let Defs = [EFLAGS] in {
 
1789
let CodeSize = 2 in
 
1790
def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
 
1791
               "inc{b}\t$dst",
 
1792
               [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
 
1793
 
 
1794
let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
 
1795
def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
 
1796
               "inc{w}\t$dst",
 
1797
               [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
 
1798
             OpSize, Requires<[In32BitMode]>;
 
1799
def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
 
1800
               "inc{l}\t$dst",
 
1801
               [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
 
1802
             Requires<[In32BitMode]>;
 
1803
}
 
1804
let Constraints = "", CodeSize = 2 in {
 
1805
  def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
 
1806
               [(store (add (loadi8 addr:$dst), 1), addr:$dst),
 
1807
                (implicit EFLAGS)]>;
 
1808
  def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
 
1809
               [(store (add (loadi16 addr:$dst), 1), addr:$dst),
 
1810
                (implicit EFLAGS)]>,
 
1811
               OpSize, Requires<[In32BitMode]>;
 
1812
  def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
 
1813
               [(store (add (loadi32 addr:$dst), 1), addr:$dst),
 
1814
                (implicit EFLAGS)]>,
 
1815
               Requires<[In32BitMode]>;
 
1816
} // Constraints = "", CodeSize = 2
 
1817
 
 
1818
let CodeSize = 2 in
 
1819
def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
 
1820
               "dec{b}\t$dst",
 
1821
               [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
 
1822
let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
 
1823
def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
 
1824
               "dec{w}\t$dst",
 
1825
               [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
 
1826
             OpSize, Requires<[In32BitMode]>;
 
1827
def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
 
1828
               "dec{l}\t$dst",
 
1829
               [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
 
1830
             Requires<[In32BitMode]>;
 
1831
} // CodeSize = 2
 
1832
 
 
1833
let Constraints = "", CodeSize = 2 in {
 
1834
  def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
 
1835
               [(store (add (loadi8 addr:$dst), -1), addr:$dst),
 
1836
                (implicit EFLAGS)]>;
 
1837
  def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
 
1838
               [(store (add (loadi16 addr:$dst), -1), addr:$dst),
 
1839
                (implicit EFLAGS)]>,
 
1840
               OpSize, Requires<[In32BitMode]>;
 
1841
  def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
 
1842
               [(store (add (loadi32 addr:$dst), -1), addr:$dst),
 
1843
                (implicit EFLAGS)]>,
 
1844
               Requires<[In32BitMode]>;
 
1845
} // Constraints = "", CodeSize = 2
 
1846
} // Defs = [EFLAGS]
 
1847
 
 
1848
// Logical operators...
 
1849
let Defs = [EFLAGS] in {
 
1850
let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
 
1851
def AND8rr  : I<0x20, MRMDestReg,
 
1852
               (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
 
1853
               "and{b}\t{$src2, $dst|$dst, $src2}",
 
1854
               [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
 
1855
def AND16rr : I<0x21, MRMDestReg,
 
1856
                (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
 
1857
                "and{w}\t{$src2, $dst|$dst, $src2}",
 
1858
                [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
 
1859
                                                      GR16:$src2))]>, OpSize;
 
1860
def AND32rr : I<0x21, MRMDestReg, 
 
1861
                (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
 
1862
                "and{l}\t{$src2, $dst|$dst, $src2}",
 
1863
                [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
 
1864
                                                      GR32:$src2))]>;
 
1865
}
 
1866
 
 
1867
// AND instructions with the destination register in REG and the source register
 
1868
//   in R/M.  Included for the disassembler.
 
1869
let isCodeGenOnly = 1 in {
 
1870
def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
1871
                  "and{b}\t{$src2, $dst|$dst, $src2}", []>;
 
1872
def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst), 
 
1873
                    (ins GR16:$src1, GR16:$src2),
 
1874
                   "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
1875
def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst), 
 
1876
                    (ins GR32:$src1, GR32:$src2),
 
1877
                   "and{l}\t{$src2, $dst|$dst, $src2}", []>;
 
1878
}
 
1879
 
 
1880
def AND8rm   : I<0x22, MRMSrcMem, 
 
1881
                 (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
 
1882
                 "and{b}\t{$src2, $dst|$dst, $src2}",
 
1883
                [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
 
1884
                                                     (loadi8 addr:$src2)))]>;
 
1885
def AND16rm  : I<0x23, MRMSrcMem, 
 
1886
                 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
 
1887
                 "and{w}\t{$src2, $dst|$dst, $src2}",
 
1888
                [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
 
1889
                                                      (loadi16 addr:$src2)))]>,
 
1890
               OpSize;
 
1891
def AND32rm  : I<0x23, MRMSrcMem,
 
1892
                 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
 
1893
                 "and{l}\t{$src2, $dst|$dst, $src2}",
 
1894
                [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
 
1895
                                                      (loadi32 addr:$src2)))]>;
 
1896
 
 
1897
def AND8ri   : Ii8<0x80, MRM4r, 
 
1898
                   (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
 
1899
                   "and{b}\t{$src2, $dst|$dst, $src2}",
 
1900
                   [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
 
1901
                                                        imm:$src2))]>;
 
1902
def AND16ri  : Ii16<0x81, MRM4r, 
 
1903
                    (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
 
1904
                    "and{w}\t{$src2, $dst|$dst, $src2}",
 
1905
                    [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
 
1906
                                                          imm:$src2))]>, OpSize;
 
1907
def AND32ri  : Ii32<0x81, MRM4r, 
 
1908
                    (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
 
1909
                    "and{l}\t{$src2, $dst|$dst, $src2}",
 
1910
                    [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
 
1911
                                                          imm:$src2))]>;
 
1912
def AND16ri8 : Ii8<0x83, MRM4r, 
 
1913
                   (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
 
1914
                   "and{w}\t{$src2, $dst|$dst, $src2}",
 
1915
                   [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
 
1916
                                                         i16immSExt8:$src2))]>,
 
1917
                   OpSize;
 
1918
def AND32ri8 : Ii8<0x83, MRM4r, 
 
1919
                   (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
 
1920
                   "and{l}\t{$src2, $dst|$dst, $src2}",
 
1921
                   [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
 
1922
                                                         i32immSExt8:$src2))]>;
 
1923
 
 
1924
let Constraints = "" in {
 
1925
  def AND8mr   : I<0x20, MRMDestMem,
 
1926
                   (outs), (ins i8mem :$dst, GR8 :$src),
 
1927
                   "and{b}\t{$src, $dst|$dst, $src}",
 
1928
                   [(store (and (load addr:$dst), GR8:$src), addr:$dst),
 
1929
                    (implicit EFLAGS)]>;
 
1930
  def AND16mr  : I<0x21, MRMDestMem,
 
1931
                   (outs), (ins i16mem:$dst, GR16:$src),
 
1932
                   "and{w}\t{$src, $dst|$dst, $src}",
 
1933
                   [(store (and (load addr:$dst), GR16:$src), addr:$dst),
 
1934
                    (implicit EFLAGS)]>,
 
1935
                   OpSize;
 
1936
  def AND32mr  : I<0x21, MRMDestMem,
 
1937
                   (outs), (ins i32mem:$dst, GR32:$src),
 
1938
                   "and{l}\t{$src, $dst|$dst, $src}",
 
1939
                   [(store (and (load addr:$dst), GR32:$src), addr:$dst),
 
1940
                    (implicit EFLAGS)]>;
 
1941
  def AND8mi   : Ii8<0x80, MRM4m,
 
1942
                     (outs), (ins i8mem :$dst, i8imm :$src),
 
1943
                     "and{b}\t{$src, $dst|$dst, $src}",
 
1944
                      [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
 
1945
                       (implicit EFLAGS)]>;
 
1946
  def AND16mi  : Ii16<0x81, MRM4m,
 
1947
                      (outs), (ins i16mem:$dst, i16imm:$src),
 
1948
                      "and{w}\t{$src, $dst|$dst, $src}",
 
1949
                      [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
 
1950
                       (implicit EFLAGS)]>,
 
1951
                      OpSize;
 
1952
  def AND32mi  : Ii32<0x81, MRM4m,
 
1953
                      (outs), (ins i32mem:$dst, i32imm:$src),
 
1954
                      "and{l}\t{$src, $dst|$dst, $src}",
 
1955
                      [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
 
1956
                       (implicit EFLAGS)]>;
 
1957
  def AND16mi8 : Ii8<0x83, MRM4m,
 
1958
                     (outs), (ins i16mem:$dst, i16i8imm :$src),
 
1959
                     "and{w}\t{$src, $dst|$dst, $src}",
 
1960
                [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
 
1961
                 (implicit EFLAGS)]>,
 
1962
                     OpSize;
 
1963
  def AND32mi8 : Ii8<0x83, MRM4m,
 
1964
                     (outs), (ins i32mem:$dst, i32i8imm :$src),
 
1965
                     "and{l}\t{$src, $dst|$dst, $src}",
 
1966
                [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
 
1967
                 (implicit EFLAGS)]>;
 
1968
 
 
1969
  def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
 
1970
                   "and{b}\t{$src, %al|%al, $src}", []>;
 
1971
  def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
 
1972
                      "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
1973
  def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
 
1974
                      "and{l}\t{$src, %eax|%eax, $src}", []>;
 
1975
 
 
1976
} // Constraints = ""
 
1977
 
 
1978
 
 
1979
let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
 
1980
def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), 
 
1981
                 (ins GR8 :$src1, GR8 :$src2),
 
1982
                 "or{b}\t{$src2, $dst|$dst, $src2}",
 
1983
                 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
 
1984
def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), 
 
1985
                 (ins GR16:$src1, GR16:$src2),
 
1986
                 "or{w}\t{$src2, $dst|$dst, $src2}",
 
1987
                 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
 
1988
               OpSize;
 
1989
def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), 
 
1990
                 (ins GR32:$src1, GR32:$src2),
 
1991
                 "or{l}\t{$src2, $dst|$dst, $src2}",
 
1992
                 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
 
1993
}
 
1994
 
 
1995
// OR instructions with the destination register in REG and the source register
 
1996
//   in R/M.  Included for the disassembler.
 
1997
let isCodeGenOnly = 1 in {
 
1998
def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
1999
                  "or{b}\t{$src2, $dst|$dst, $src2}", []>;
 
2000
def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
 
2001
                   (ins GR16:$src1, GR16:$src2),
 
2002
                   "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
2003
def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst), 
 
2004
                   (ins GR32:$src1, GR32:$src2),
 
2005
                   "or{l}\t{$src2, $dst|$dst, $src2}", []>;
 
2006
}
 
2007
                  
 
2008
def OR8rm    : I<0x0A, MRMSrcMem, (outs GR8 :$dst), 
 
2009
                 (ins GR8 :$src1, i8mem :$src2),
 
2010
                 "or{b}\t{$src2, $dst|$dst, $src2}",
 
2011
                [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
 
2012
                                                    (load addr:$src2)))]>;
 
2013
def OR16rm   : I<0x0B, MRMSrcMem, (outs GR16:$dst), 
 
2014
                 (ins GR16:$src1, i16mem:$src2),
 
2015
                 "or{w}\t{$src2, $dst|$dst, $src2}",
 
2016
                [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
 
2017
                                                     (load addr:$src2)))]>,
 
2018
               OpSize;
 
2019
def OR32rm   : I<0x0B, MRMSrcMem, (outs GR32:$dst), 
 
2020
                 (ins GR32:$src1, i32mem:$src2),
 
2021
                 "or{l}\t{$src2, $dst|$dst, $src2}",
 
2022
                [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
 
2023
                                                     (load addr:$src2)))]>;
 
2024
 
 
2025
def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), 
 
2026
                    (ins GR8 :$src1, i8imm:$src2),
 
2027
                    "or{b}\t{$src2, $dst|$dst, $src2}",
 
2028
                    [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
 
2029
def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), 
 
2030
                    (ins GR16:$src1, i16imm:$src2),
 
2031
                    "or{w}\t{$src2, $dst|$dst, $src2}", 
 
2032
                    [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
 
2033
                                                        imm:$src2))]>, OpSize;
 
2034
def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), 
 
2035
                    (ins GR32:$src1, i32imm:$src2),
 
2036
                    "or{l}\t{$src2, $dst|$dst, $src2}",
 
2037
                    [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
 
2038
                                                         imm:$src2))]>;
 
2039
 
 
2040
def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), 
 
2041
                   (ins GR16:$src1, i16i8imm:$src2),
 
2042
                   "or{w}\t{$src2, $dst|$dst, $src2}",
 
2043
                   [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
 
2044
                                                i16immSExt8:$src2))]>, OpSize;
 
2045
def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), 
 
2046
                   (ins GR32:$src1, i32i8imm:$src2),
 
2047
                   "or{l}\t{$src2, $dst|$dst, $src2}",
 
2048
                   [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
 
2049
                                                        i32immSExt8:$src2))]>;
 
2050
let Constraints = "" in {
 
2051
  def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
 
2052
                 "or{b}\t{$src, $dst|$dst, $src}",
 
2053
                 [(store (or (load addr:$dst), GR8:$src), addr:$dst),
 
2054
                  (implicit EFLAGS)]>;
 
2055
  def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
 
2056
                 "or{w}\t{$src, $dst|$dst, $src}",
 
2057
                 [(store (or (load addr:$dst), GR16:$src), addr:$dst),
 
2058
                  (implicit EFLAGS)]>, OpSize;
 
2059
  def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
 
2060
                 "or{l}\t{$src, $dst|$dst, $src}",
 
2061
                 [(store (or (load addr:$dst), GR32:$src), addr:$dst),
 
2062
                  (implicit EFLAGS)]>;
 
2063
  def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2064
                 "or{b}\t{$src, $dst|$dst, $src}",
 
2065
                 [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
 
2066
                  (implicit EFLAGS)]>;
 
2067
  def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
 
2068
                 "or{w}\t{$src, $dst|$dst, $src}",
 
2069
                 [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
 
2070
                  (implicit EFLAGS)]>,
 
2071
                 OpSize;
 
2072
  def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
 
2073
                 "or{l}\t{$src, $dst|$dst, $src}",
 
2074
                 [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
 
2075
                  (implicit EFLAGS)]>;
 
2076
  def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
 
2077
                 "or{w}\t{$src, $dst|$dst, $src}",
 
2078
                 [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
 
2079
                  (implicit EFLAGS)]>,
 
2080
                     OpSize;
 
2081
  def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
 
2082
                 "or{l}\t{$src, $dst|$dst, $src}",
 
2083
                 [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
 
2084
                  (implicit EFLAGS)]>;
 
2085
                  
 
2086
  def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
 
2087
                   "or{b}\t{$src, %al|%al, $src}", []>;
 
2088
  def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
 
2089
                      "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
2090
  def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
 
2091
                      "or{l}\t{$src, %eax|%eax, $src}", []>;
 
2092
} // Constraints = ""
 
2093
 
 
2094
 
 
2095
let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
 
2096
  def XOR8rr   : I<0x30, MRMDestReg,
 
2097
                   (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
 
2098
                   "xor{b}\t{$src2, $dst|$dst, $src2}",
 
2099
                   [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
 
2100
                                                        GR8:$src2))]>;
 
2101
  def XOR16rr  : I<0x31, MRMDestReg, 
 
2102
                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
 
2103
                   "xor{w}\t{$src2, $dst|$dst, $src2}",
 
2104
                   [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
 
2105
                                                         GR16:$src2))]>, OpSize;
 
2106
  def XOR32rr  : I<0x31, MRMDestReg, 
 
2107
                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
 
2108
                   "xor{l}\t{$src2, $dst|$dst, $src2}",
 
2109
                   [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
 
2110
                                                         GR32:$src2))]>;
 
2111
} // isCommutable = 1
 
2112
 
 
2113
// XOR instructions with the destination register in REG and the source register
 
2114
//   in R/M.  Included for the disassembler.
 
2115
let isCodeGenOnly = 1 in {
 
2116
def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
2117
                  "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
 
2118
def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst), 
 
2119
                    (ins GR16:$src1, GR16:$src2),
 
2120
                   "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
2121
def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst), 
 
2122
                    (ins GR32:$src1, GR32:$src2),
 
2123
                   "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
 
2124
}
 
2125
 
 
2126
def XOR8rm   : I<0x32, MRMSrcMem, 
 
2127
                 (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
 
2128
                 "xor{b}\t{$src2, $dst|$dst, $src2}",
 
2129
                 [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
 
2130
                                                      (load addr:$src2)))]>;
 
2131
def XOR16rm  : I<0x33, MRMSrcMem, 
 
2132
                 (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
 
2133
                 "xor{w}\t{$src2, $dst|$dst, $src2}",
 
2134
                 [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
 
2135
                                                       (load addr:$src2)))]>,
 
2136
                 OpSize;
 
2137
def XOR32rm  : I<0x33, MRMSrcMem, 
 
2138
                 (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
 
2139
                 "xor{l}\t{$src2, $dst|$dst, $src2}",
 
2140
                 [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
 
2141
                                                       (load addr:$src2)))]>;
 
2142
 
 
2143
def XOR8ri  : Ii8<0x80, MRM6r, 
 
2144
                  (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
 
2145
                  "xor{b}\t{$src2, $dst|$dst, $src2}",
 
2146
                  [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
 
2147
def XOR16ri : Ii16<0x81, MRM6r, 
 
2148
                   (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
 
2149
                   "xor{w}\t{$src2, $dst|$dst, $src2}",
 
2150
                   [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
 
2151
                                                         imm:$src2))]>, OpSize;
 
2152
def XOR32ri  : Ii32<0x81, MRM6r, 
 
2153
                    (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
 
2154
                    "xor{l}\t{$src2, $dst|$dst, $src2}",
 
2155
                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
 
2156
                                                          imm:$src2))]>;
 
2157
def XOR16ri8 : Ii8<0x83, MRM6r, 
 
2158
                   (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
 
2159
                   "xor{w}\t{$src2, $dst|$dst, $src2}",
 
2160
                   [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
 
2161
                                                         i16immSExt8:$src2))]>,
 
2162
                   OpSize;
 
2163
def XOR32ri8 : Ii8<0x83, MRM6r, 
 
2164
                   (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
 
2165
                   "xor{l}\t{$src2, $dst|$dst, $src2}",
 
2166
                   [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
 
2167
                                                         i32immSExt8:$src2))]>;
 
2168
 
 
2169
let Constraints = "" in {
 
2170
  def XOR8mr   : I<0x30, MRMDestMem,
 
2171
                   (outs), (ins i8mem :$dst, GR8 :$src),
 
2172
                   "xor{b}\t{$src, $dst|$dst, $src}",
 
2173
                   [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
 
2174
                    (implicit EFLAGS)]>;
 
2175
  def XOR16mr  : I<0x31, MRMDestMem,
 
2176
                   (outs), (ins i16mem:$dst, GR16:$src),
 
2177
                   "xor{w}\t{$src, $dst|$dst, $src}",
 
2178
                   [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
 
2179
                    (implicit EFLAGS)]>,
 
2180
                   OpSize;
 
2181
  def XOR32mr  : I<0x31, MRMDestMem,
 
2182
                   (outs), (ins i32mem:$dst, GR32:$src),
 
2183
                   "xor{l}\t{$src, $dst|$dst, $src}",
 
2184
                   [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
 
2185
                    (implicit EFLAGS)]>;
 
2186
  def XOR8mi   : Ii8<0x80, MRM6m,
 
2187
                     (outs), (ins i8mem :$dst, i8imm :$src),
 
2188
                     "xor{b}\t{$src, $dst|$dst, $src}",
 
2189
                    [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
 
2190
                     (implicit EFLAGS)]>;
 
2191
  def XOR16mi  : Ii16<0x81, MRM6m,
 
2192
                      (outs), (ins i16mem:$dst, i16imm:$src),
 
2193
                      "xor{w}\t{$src, $dst|$dst, $src}",
 
2194
                   [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
 
2195
                    (implicit EFLAGS)]>,
 
2196
                      OpSize;
 
2197
  def XOR32mi  : Ii32<0x81, MRM6m,
 
2198
                      (outs), (ins i32mem:$dst, i32imm:$src),
 
2199
                      "xor{l}\t{$src, $dst|$dst, $src}",
 
2200
                   [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
 
2201
                    (implicit EFLAGS)]>;
 
2202
  def XOR16mi8 : Ii8<0x83, MRM6m,
 
2203
                     (outs), (ins i16mem:$dst, i16i8imm :$src),
 
2204
                     "xor{w}\t{$src, $dst|$dst, $src}",
 
2205
                 [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
 
2206
                  (implicit EFLAGS)]>,
 
2207
                     OpSize;
 
2208
  def XOR32mi8 : Ii8<0x83, MRM6m,
 
2209
                     (outs), (ins i32mem:$dst, i32i8imm :$src),
 
2210
                     "xor{l}\t{$src, $dst|$dst, $src}",
 
2211
                 [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
 
2212
                  (implicit EFLAGS)]>;
 
2213
                  
 
2214
  def XOR8i8   : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
 
2215
                      "xor{b}\t{$src, %al|%al, $src}", []>;
 
2216
  def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
 
2217
                      "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
2218
  def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
 
2219
                      "xor{l}\t{$src, %eax|%eax, $src}", []>;
 
2220
} // Constraints = ""
 
2221
} // Defs = [EFLAGS]
 
2222
 
 
2223
// Shift instructions
 
2224
let Defs = [EFLAGS] in {
 
2225
let Uses = [CL] in {
 
2226
def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2227
                 "shl{b}\t{%cl, $dst|$dst, CL}",
 
2228
                 [(set GR8:$dst, (shl GR8:$src1, CL))]>;
 
2229
def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
 
2230
                 "shl{w}\t{%cl, $dst|$dst, CL}",
 
2231
                 [(set GR16:$dst, (shl GR16:$src1, CL))]>, OpSize;
 
2232
def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
 
2233
                 "shl{l}\t{%cl, $dst|$dst, CL}",
 
2234
                 [(set GR32:$dst, (shl GR32:$src1, CL))]>;
 
2235
} // Uses = [CL]
 
2236
 
 
2237
def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
 
2238
                   "shl{b}\t{$src2, $dst|$dst, $src2}",
 
2239
                   [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
 
2240
                   
 
2241
let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
 
2242
def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
 
2243
                   "shl{w}\t{$src2, $dst|$dst, $src2}",
 
2244
                   [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
 
2245
def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
 
2246
                   "shl{l}\t{$src2, $dst|$dst, $src2}",
 
2247
                   [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
 
2248
 
 
2249
// NOTE: We don't include patterns for shifts of a register by one, because
 
2250
// 'add reg,reg' is cheaper.
 
2251
 
 
2252
def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
 
2253
                 "shl{b}\t$dst", []>;
 
2254
def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
 
2255
                 "shl{w}\t$dst", []>, OpSize;
 
2256
def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
 
2257
                 "shl{l}\t$dst", []>;
 
2258
 
 
2259
} // isConvertibleToThreeAddress = 1
 
2260
 
 
2261
let Constraints = "" in {
 
2262
  let Uses = [CL] in {
 
2263
  def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
 
2264
                   "shl{b}\t{%cl, $dst|$dst, CL}",
 
2265
                   [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
 
2266
  def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
 
2267
                   "shl{w}\t{%cl, $dst|$dst, CL}",
 
2268
                   [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
 
2269
  def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
 
2270
                   "shl{l}\t{%cl, $dst|$dst, CL}",
 
2271
                   [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
 
2272
  }
 
2273
  def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2274
                     "shl{b}\t{$src, $dst|$dst, $src}",
 
2275
                  [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2276
  def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
 
2277
                     "shl{w}\t{$src, $dst|$dst, $src}",
 
2278
                 [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
 
2279
                     OpSize;
 
2280
  def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
 
2281
                     "shl{l}\t{$src, $dst|$dst, $src}",
 
2282
                 [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2283
 
 
2284
  // Shift by 1
 
2285
  def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
 
2286
                   "shl{b}\t$dst",
 
2287
                  [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
 
2288
  def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
 
2289
                   "shl{w}\t$dst",
 
2290
                 [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
 
2291
                     OpSize;
 
2292
  def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
 
2293
                   "shl{l}\t$dst",
 
2294
                 [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
 
2295
} // Constraints = ""
 
2296
 
 
2297
let Uses = [CL] in {
 
2298
def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2299
                 "shr{b}\t{%cl, $dst|$dst, CL}",
 
2300
                 [(set GR8:$dst, (srl GR8:$src1, CL))]>;
 
2301
def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
 
2302
                 "shr{w}\t{%cl, $dst|$dst, CL}",
 
2303
                 [(set GR16:$dst, (srl GR16:$src1, CL))]>, OpSize;
 
2304
def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
 
2305
                 "shr{l}\t{%cl, $dst|$dst, CL}",
 
2306
                 [(set GR32:$dst, (srl GR32:$src1, CL))]>;
 
2307
}
 
2308
 
 
2309
def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
 
2310
                   "shr{b}\t{$src2, $dst|$dst, $src2}",
 
2311
                   [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
 
2312
def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
 
2313
                   "shr{w}\t{$src2, $dst|$dst, $src2}",
 
2314
                   [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
 
2315
def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
 
2316
                   "shr{l}\t{$src2, $dst|$dst, $src2}",
 
2317
                   [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
 
2318
 
 
2319
// Shift by 1
 
2320
def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
 
2321
                 "shr{b}\t$dst",
 
2322
                 [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
 
2323
def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
 
2324
                 "shr{w}\t$dst",
 
2325
                 [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
 
2326
def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
 
2327
                 "shr{l}\t$dst",
 
2328
                 [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
 
2329
 
 
2330
let Constraints = "" in {
 
2331
  let Uses = [CL] in {
 
2332
  def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
 
2333
                   "shr{b}\t{%cl, $dst|$dst, CL}",
 
2334
                   [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
 
2335
  def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
 
2336
                   "shr{w}\t{%cl, $dst|$dst, CL}",
 
2337
                   [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
 
2338
                   OpSize;
 
2339
  def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
 
2340
                   "shr{l}\t{%cl, $dst|$dst, CL}",
 
2341
                   [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
 
2342
  }
 
2343
  def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2344
                     "shr{b}\t{$src, $dst|$dst, $src}",
 
2345
                  [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2346
  def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
 
2347
                     "shr{w}\t{$src, $dst|$dst, $src}",
 
2348
                 [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
 
2349
                     OpSize;
 
2350
  def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
 
2351
                     "shr{l}\t{$src, $dst|$dst, $src}",
 
2352
                 [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2353
 
 
2354
  // Shift by 1
 
2355
  def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
 
2356
                   "shr{b}\t$dst",
 
2357
                  [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
 
2358
  def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
 
2359
                   "shr{w}\t$dst",
 
2360
                 [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
 
2361
  def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
 
2362
                   "shr{l}\t$dst",
 
2363
                 [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
 
2364
} // Constraints = ""
 
2365
 
 
2366
let Uses = [CL] in {
 
2367
def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2368
                 "sar{b}\t{%cl, $dst|$dst, CL}",
 
2369
                 [(set GR8:$dst, (sra GR8:$src1, CL))]>;
 
2370
def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
 
2371
                 "sar{w}\t{%cl, $dst|$dst, CL}",
 
2372
                 [(set GR16:$dst, (sra GR16:$src1, CL))]>, OpSize;
 
2373
def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
 
2374
                 "sar{l}\t{%cl, $dst|$dst, CL}",
 
2375
                 [(set GR32:$dst, (sra GR32:$src1, CL))]>;
 
2376
}
 
2377
 
 
2378
def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
 
2379
                   "sar{b}\t{$src2, $dst|$dst, $src2}",
 
2380
                   [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
 
2381
def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
 
2382
                   "sar{w}\t{$src2, $dst|$dst, $src2}",
 
2383
                   [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
 
2384
                   OpSize;
 
2385
def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
 
2386
                   "sar{l}\t{$src2, $dst|$dst, $src2}",
 
2387
                   [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
 
2388
 
 
2389
// Shift by 1
 
2390
def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2391
                 "sar{b}\t$dst",
 
2392
                 [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
 
2393
def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
 
2394
                 "sar{w}\t$dst",
 
2395
                 [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
 
2396
def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
 
2397
                 "sar{l}\t$dst",
 
2398
                 [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
 
2399
 
 
2400
let Constraints = "" in {
 
2401
  let Uses = [CL] in {
 
2402
  def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
 
2403
                   "sar{b}\t{%cl, $dst|$dst, CL}",
 
2404
                   [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
 
2405
  def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
 
2406
                   "sar{w}\t{%cl, $dst|$dst, CL}",
 
2407
                   [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
 
2408
  def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
 
2409
                   "sar{l}\t{%cl, $dst|$dst, CL}",
 
2410
                   [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
 
2411
  }
 
2412
  def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2413
                     "sar{b}\t{$src, $dst|$dst, $src}",
 
2414
                  [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2415
  def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
 
2416
                     "sar{w}\t{$src, $dst|$dst, $src}",
 
2417
                 [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
 
2418
                     OpSize;
 
2419
  def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
 
2420
                     "sar{l}\t{$src, $dst|$dst, $src}",
 
2421
                 [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2422
 
 
2423
  // Shift by 1
 
2424
  def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
 
2425
                   "sar{b}\t$dst",
 
2426
                  [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
 
2427
  def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
 
2428
                   "sar{w}\t$dst",
 
2429
                 [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
 
2430
                     OpSize;
 
2431
  def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
 
2432
                   "sar{l}\t$dst",
 
2433
                 [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
 
2434
} // Constraints = ""
 
2435
 
 
2436
// Rotate instructions
 
2437
 
 
2438
def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
 
2439
               "rcl{b}\t{1, $dst|$dst, 1}", []>;
 
2440
let Uses = [CL] in {
 
2441
def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
 
2442
                "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
 
2443
}
 
2444
def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
 
2445
                 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2446
  
 
2447
def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
 
2448
                "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
 
2449
let Uses = [CL] in {
 
2450
def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
 
2451
                 "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
 
2452
}
 
2453
def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
 
2454
                  "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
 
2455
 
 
2456
def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
 
2457
                "rcl{l}\t{1, $dst|$dst, 1}", []>;
 
2458
let Uses = [CL] in {
 
2459
def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
 
2460
                 "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
 
2461
}
 
2462
def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
 
2463
                  "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2464
                  
 
2465
def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
 
2466
               "rcr{b}\t{1, $dst|$dst, 1}", []>;
 
2467
let Uses = [CL] in {
 
2468
def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
 
2469
                "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
 
2470
}
 
2471
def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
 
2472
                 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2473
  
 
2474
def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
 
2475
                "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
 
2476
let Uses = [CL] in {
 
2477
def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
 
2478
                 "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
 
2479
}
 
2480
def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
 
2481
                  "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
 
2482
 
 
2483
def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
 
2484
                "rcr{l}\t{1, $dst|$dst, 1}", []>;
 
2485
let Uses = [CL] in {
 
2486
def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
 
2487
                 "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
 
2488
}
 
2489
def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
 
2490
                  "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2491
 
 
2492
let Constraints = "" in {
 
2493
def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
 
2494
               "rcl{b}\t{1, $dst|$dst, 1}", []>;
 
2495
def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
 
2496
                 "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2497
def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
 
2498
                "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
 
2499
def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
 
2500
                  "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
 
2501
def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
 
2502
                "rcl{l}\t{1, $dst|$dst, 1}", []>;
 
2503
def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
 
2504
                  "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2505
def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
 
2506
               "rcr{b}\t{1, $dst|$dst, 1}", []>;
 
2507
def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
 
2508
                 "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2509
def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
 
2510
                "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
 
2511
def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
 
2512
                  "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
 
2513
def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
 
2514
                "rcr{l}\t{1, $dst|$dst, 1}", []>;
 
2515
def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
 
2516
                  "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
 
2517
 
 
2518
let Uses = [CL] in {
 
2519
def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
 
2520
                "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
 
2521
def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
 
2522
                 "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
 
2523
def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
 
2524
                 "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
 
2525
def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
 
2526
                "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
 
2527
def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
 
2528
                 "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
 
2529
def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
 
2530
                 "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
 
2531
}
 
2532
} // Constraints = ""
 
2533
 
 
2534
// FIXME: provide shorter instructions when imm8 == 1
 
2535
let Uses = [CL] in {
 
2536
def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2537
                 "rol{b}\t{%cl, $dst|$dst, CL}",
 
2538
                 [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
 
2539
def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
 
2540
                 "rol{w}\t{%cl, $dst|$dst, CL}",
 
2541
                 [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize;
 
2542
def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
 
2543
                 "rol{l}\t{%cl, $dst|$dst, CL}",
 
2544
                 [(set GR32:$dst, (rotl GR32:$src1, CL))]>;
 
2545
}
 
2546
 
 
2547
def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
 
2548
                   "rol{b}\t{$src2, $dst|$dst, $src2}",
 
2549
                   [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
 
2550
def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
 
2551
                   "rol{w}\t{$src2, $dst|$dst, $src2}",
 
2552
                   [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, 
 
2553
                   OpSize;
 
2554
def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
 
2555
                   "rol{l}\t{$src2, $dst|$dst, $src2}",
 
2556
                   [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
 
2557
 
 
2558
// Rotate by 1
 
2559
def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2560
                 "rol{b}\t$dst",
 
2561
                 [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
 
2562
def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
 
2563
                 "rol{w}\t$dst",
 
2564
                 [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
 
2565
def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
 
2566
                 "rol{l}\t$dst",
 
2567
                 [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
 
2568
 
 
2569
let Constraints = "" in {
 
2570
  let Uses = [CL] in {
 
2571
  def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
 
2572
                   "rol{b}\t{%cl, $dst|$dst, CL}",
 
2573
                   [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
 
2574
  def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
 
2575
                   "rol{w}\t{%cl, $dst|$dst, CL}",
 
2576
                   [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
 
2577
  def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
 
2578
                   "rol{l}\t{%cl, $dst|$dst, CL}",
 
2579
                   [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
 
2580
  }
 
2581
  def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2582
                     "rol{b}\t{$src, $dst|$dst, $src}",
 
2583
                 [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2584
  def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
 
2585
                     "rol{w}\t{$src, $dst|$dst, $src}",
 
2586
                [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
 
2587
                     OpSize;
 
2588
  def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
 
2589
                     "rol{l}\t{$src, $dst|$dst, $src}",
 
2590
                [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2591
 
 
2592
  // Rotate by 1
 
2593
  def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
 
2594
                   "rol{b}\t$dst",
 
2595
                 [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
 
2596
  def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
 
2597
                   "rol{w}\t$dst",
 
2598
                [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
 
2599
                     OpSize;
 
2600
  def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
 
2601
                   "rol{l}\t$dst",
 
2602
                [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
 
2603
} // Constraints = ""
 
2604
 
 
2605
let Uses = [CL] in {
 
2606
def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2607
                 "ror{b}\t{%cl, $dst|$dst, CL}",
 
2608
                 [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
 
2609
def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
 
2610
                 "ror{w}\t{%cl, $dst|$dst, CL}",
 
2611
                 [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize;
 
2612
def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
 
2613
                 "ror{l}\t{%cl, $dst|$dst, CL}",
 
2614
                 [(set GR32:$dst, (rotr GR32:$src1, CL))]>;
 
2615
}
 
2616
 
 
2617
def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
 
2618
                   "ror{b}\t{$src2, $dst|$dst, $src2}",
 
2619
                   [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
 
2620
def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
 
2621
                   "ror{w}\t{$src2, $dst|$dst, $src2}",
 
2622
                   [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, 
 
2623
                   OpSize;
 
2624
def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
 
2625
                   "ror{l}\t{$src2, $dst|$dst, $src2}",
 
2626
                   [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
 
2627
 
 
2628
// Rotate by 1
 
2629
def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
 
2630
                 "ror{b}\t$dst",
 
2631
                 [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
 
2632
def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
 
2633
                 "ror{w}\t$dst",
 
2634
                 [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
 
2635
def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
 
2636
                 "ror{l}\t$dst",
 
2637
                 [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
 
2638
 
 
2639
let Constraints = "" in {
 
2640
  let Uses = [CL] in {
 
2641
  def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
 
2642
                   "ror{b}\t{%cl, $dst|$dst, CL}",
 
2643
                   [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
 
2644
  def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
 
2645
                   "ror{w}\t{%cl, $dst|$dst, CL}",
 
2646
                   [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
 
2647
  def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
 
2648
                   "ror{l}\t{%cl, $dst|$dst, CL}",
 
2649
                   [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
 
2650
  }
 
2651
  def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
 
2652
                     "ror{b}\t{$src, $dst|$dst, $src}",
 
2653
                 [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2654
  def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
 
2655
                     "ror{w}\t{$src, $dst|$dst, $src}",
 
2656
                [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
 
2657
                     OpSize;
 
2658
  def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
 
2659
                     "ror{l}\t{$src, $dst|$dst, $src}",
 
2660
                [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
 
2661
 
 
2662
  // Rotate by 1
 
2663
  def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
 
2664
                   "ror{b}\t$dst",
 
2665
                 [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
 
2666
  def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
 
2667
                   "ror{w}\t$dst",
 
2668
                [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
 
2669
                     OpSize;
 
2670
  def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
 
2671
                   "ror{l}\t$dst",
 
2672
                [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
 
2673
} // Constraints = ""
 
2674
 
 
2675
 
 
2676
// Double shift instructions (generalizations of rotate)
 
2677
let Uses = [CL] in {
 
2678
def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
 
2679
                   (ins GR32:$src1, GR32:$src2),
 
2680
                   "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2681
                   [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
 
2682
def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
 
2683
                   (ins GR32:$src1, GR32:$src2),
 
2684
                   "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2685
                   [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
 
2686
def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
 
2687
                   (ins GR16:$src1, GR16:$src2),
 
2688
                   "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2689
                   [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
 
2690
                   TB, OpSize;
 
2691
def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
 
2692
                   (ins GR16:$src1, GR16:$src2),
 
2693
                   "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2694
                   [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
 
2695
                   TB, OpSize;
 
2696
}
 
2697
 
 
2698
let isCommutable = 1 in {  // These instructions commute to each other.
 
2699
def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
 
2700
                     (outs GR32:$dst), 
 
2701
                     (ins GR32:$src1, GR32:$src2, i8imm:$src3),
 
2702
                     "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2703
                     [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
 
2704
                                      (i8 imm:$src3)))]>,
 
2705
                 TB;
 
2706
def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
 
2707
                     (outs GR32:$dst), 
 
2708
                     (ins GR32:$src1, GR32:$src2, i8imm:$src3),
 
2709
                     "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2710
                     [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
 
2711
                                      (i8 imm:$src3)))]>,
 
2712
                 TB;
 
2713
def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
 
2714
                     (outs GR16:$dst), 
 
2715
                     (ins GR16:$src1, GR16:$src2, i8imm:$src3),
 
2716
                     "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2717
                     [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
 
2718
                                      (i8 imm:$src3)))]>,
 
2719
                     TB, OpSize;
 
2720
def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
 
2721
                     (outs GR16:$dst), 
 
2722
                     (ins GR16:$src1, GR16:$src2, i8imm:$src3),
 
2723
                     "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2724
                     [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
 
2725
                                      (i8 imm:$src3)))]>,
 
2726
                     TB, OpSize;
 
2727
}
 
2728
 
 
2729
let Constraints = "" in {
 
2730
  let Uses = [CL] in {
 
2731
  def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
 
2732
                     "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2733
                     [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
 
2734
                       addr:$dst)]>, TB;
 
2735
  def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
 
2736
                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2737
                    [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
 
2738
                      addr:$dst)]>, TB;
 
2739
  }
 
2740
  def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
 
2741
                      (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
 
2742
                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2743
                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
 
2744
                                        (i8 imm:$src3)), addr:$dst)]>,
 
2745
                      TB;
 
2746
  def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
 
2747
                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
 
2748
                       "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2749
                       [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
 
2750
                                         (i8 imm:$src3)), addr:$dst)]>,
 
2751
                       TB;
 
2752
 
 
2753
  let Uses = [CL] in {
 
2754
  def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
2755
                     "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2756
                     [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
 
2757
                       addr:$dst)]>, TB, OpSize;
 
2758
  def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
2759
                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
 
2760
                    [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
 
2761
                      addr:$dst)]>, TB, OpSize;
 
2762
  }
 
2763
  def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
 
2764
                      (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
 
2765
                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2766
                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
 
2767
                                        (i8 imm:$src3)), addr:$dst)]>,
 
2768
                      TB, OpSize;
 
2769
  def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
 
2770
                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
 
2771
                       "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
 
2772
                      [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
 
2773
                                        (i8 imm:$src3)), addr:$dst)]>,
 
2774
                       TB, OpSize;
 
2775
} // Constraints = ""
 
2776
} // Defs = [EFLAGS]
 
2777
 
 
2778
 
 
2779
// Arithmetic.
 
2780
let Defs = [EFLAGS] in {
 
2781
let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
 
2782
// Register-Register Addition
 
2783
def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
 
2784
                                    (ins GR8 :$src1, GR8 :$src2),
 
2785
                  "add{b}\t{$src2, $dst|$dst, $src2}",
 
2786
                  [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
 
2787
 
 
2788
let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
 
2789
// Register-Register Addition
 
2790
def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
 
2791
                                   (ins GR16:$src1, GR16:$src2),
 
2792
                 "add{w}\t{$src2, $dst|$dst, $src2}",
 
2793
                 [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
 
2794
                                                       GR16:$src2))]>, OpSize;
 
2795
def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
 
2796
                                   (ins GR32:$src1, GR32:$src2),
 
2797
                 "add{l}\t{$src2, $dst|$dst, $src2}",
 
2798
                 [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
 
2799
                                                       GR32:$src2))]>;
 
2800
} // end isConvertibleToThreeAddress
 
2801
} // end isCommutable
 
2802
 
 
2803
// These are alternate spellings for use by the disassembler, we mark them as
 
2804
// code gen only to ensure they aren't matched by the assembler.
 
2805
let isCodeGenOnly = 1 in {
 
2806
  def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
2807
                   "add{b}\t{$src2, $dst|$dst, $src2}", []>;
 
2808
  def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
 
2809
                    "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
2810
  def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
 
2811
                    "add{l}\t{$src2, $dst|$dst, $src2}", []>;
 
2812
}
 
2813
 
 
2814
// Register-Memory Addition
 
2815
def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
 
2816
                                  (ins GR8 :$src1, i8mem :$src2),
 
2817
                 "add{b}\t{$src2, $dst|$dst, $src2}",
 
2818
                 [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
 
2819
                                                      (load addr:$src2)))]>;
 
2820
def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
 
2821
                                  (ins GR16:$src1, i16mem:$src2),
 
2822
                 "add{w}\t{$src2, $dst|$dst, $src2}",
 
2823
                 [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
 
2824
                                                  (load addr:$src2)))]>, OpSize;
 
2825
def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
 
2826
                                  (ins GR32:$src1, i32mem:$src2),
 
2827
                 "add{l}\t{$src2, $dst|$dst, $src2}",
 
2828
                 [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
 
2829
                                                       (load addr:$src2)))]>;
 
2830
                  
 
2831
// Register-Integer Addition
 
2832
def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
 
2833
                    "add{b}\t{$src2, $dst|$dst, $src2}",
 
2834
                    [(set GR8:$dst, EFLAGS,
 
2835
                          (X86add_flag GR8:$src1, imm:$src2))]>;
 
2836
 
 
2837
let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
 
2838
// Register-Integer Addition
 
2839
def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
 
2840
                                 (ins GR16:$src1, i16imm:$src2),
 
2841
                    "add{w}\t{$src2, $dst|$dst, $src2}",
 
2842
                    [(set GR16:$dst, EFLAGS,
 
2843
                          (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
 
2844
def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
 
2845
                                 (ins GR32:$src1, i32imm:$src2),
 
2846
                    "add{l}\t{$src2, $dst|$dst, $src2}",
 
2847
                    [(set GR32:$dst, EFLAGS, 
 
2848
                          (X86add_flag GR32:$src1, imm:$src2))]>;
 
2849
def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
 
2850
                                (ins GR16:$src1, i16i8imm:$src2),
 
2851
                   "add{w}\t{$src2, $dst|$dst, $src2}",
 
2852
                   [(set GR16:$dst, EFLAGS,
 
2853
                         (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
 
2854
def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
 
2855
                                (ins GR32:$src1, i32i8imm:$src2),
 
2856
                   "add{l}\t{$src2, $dst|$dst, $src2}",
 
2857
                   [(set GR32:$dst, EFLAGS,
 
2858
                         (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
 
2859
}
 
2860
 
 
2861
let Constraints = "" in {
 
2862
  // Memory-Register Addition
 
2863
  def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
 
2864
                   "add{b}\t{$src2, $dst|$dst, $src2}",
 
2865
                   [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
 
2866
                    (implicit EFLAGS)]>;
 
2867
  def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
2868
                   "add{w}\t{$src2, $dst|$dst, $src2}",
 
2869
                   [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
 
2870
                    (implicit EFLAGS)]>, OpSize;
 
2871
  def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
 
2872
                   "add{l}\t{$src2, $dst|$dst, $src2}",
 
2873
                   [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
 
2874
                    (implicit EFLAGS)]>;
 
2875
  def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
 
2876
                     "add{b}\t{$src2, $dst|$dst, $src2}",
 
2877
                   [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
 
2878
                    (implicit EFLAGS)]>;
 
2879
  def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
 
2880
                      "add{w}\t{$src2, $dst|$dst, $src2}",
 
2881
                  [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
 
2882
                   (implicit EFLAGS)]>, OpSize;
 
2883
  def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
 
2884
                      "add{l}\t{$src2, $dst|$dst, $src2}",
 
2885
                      [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
 
2886
                       (implicit EFLAGS)]>;
 
2887
  def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
 
2888
                     "add{w}\t{$src2, $dst|$dst, $src2}",
 
2889
                     [(store (add (load addr:$dst), i16immSExt8:$src2),
 
2890
                                  addr:$dst),
 
2891
                      (implicit EFLAGS)]>, OpSize;
 
2892
  def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
 
2893
                     "add{l}\t{$src2, $dst|$dst, $src2}",
 
2894
                  [(store (add (load addr:$dst), i32immSExt8:$src2),
 
2895
                               addr:$dst),
 
2896
                   (implicit EFLAGS)]>;
 
2897
 
 
2898
  // addition to rAX
 
2899
  def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
 
2900
                   "add{b}\t{$src, %al|%al, $src}", []>;
 
2901
  def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
 
2902
                      "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
2903
  def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
 
2904
                      "add{l}\t{$src, %eax|%eax, $src}", []>;
 
2905
} // Constraints = ""
 
2906
 
 
2907
let Uses = [EFLAGS] in {
 
2908
let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
 
2909
def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
2910
                 "adc{b}\t{$src2, $dst|$dst, $src2}",
 
2911
                 [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
 
2912
def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
 
2913
                                   (ins GR16:$src1, GR16:$src2),
 
2914
                 "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2915
                 [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
 
2916
def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
 
2917
                                   (ins GR32:$src1, GR32:$src2),
 
2918
                 "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2919
                 [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
 
2920
}
 
2921
 
 
2922
let isCodeGenOnly = 1 in {
 
2923
def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
2924
                 "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
 
2925
def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst), 
 
2926
                    (ins GR16:$src1, GR16:$src2),
 
2927
                    "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
2928
def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst), 
 
2929
                    (ins GR32:$src1, GR32:$src2),
 
2930
                    "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
 
2931
}
 
2932
 
 
2933
def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
 
2934
                                   (ins GR8:$src1, i8mem:$src2),
 
2935
                 "adc{b}\t{$src2, $dst|$dst, $src2}",
 
2936
                 [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
 
2937
def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
 
2938
                                   (ins GR16:$src1, i16mem:$src2),
 
2939
                 "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2940
                 [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
 
2941
                 OpSize;
 
2942
def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
 
2943
                                   (ins GR32:$src1, i32mem:$src2),
 
2944
                 "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2945
                 [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
 
2946
def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
 
2947
                    "adc{b}\t{$src2, $dst|$dst, $src2}",
 
2948
                 [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
 
2949
def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
 
2950
                                 (ins GR16:$src1, i16imm:$src2),
 
2951
                    "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2952
                 [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
 
2953
def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
 
2954
                                (ins GR16:$src1, i16i8imm:$src2),
 
2955
                   "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2956
                 [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
 
2957
                 OpSize;
 
2958
def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
 
2959
                                 (ins GR32:$src1, i32imm:$src2),
 
2960
                    "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2961
                 [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
 
2962
def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
 
2963
                                (ins GR32:$src1, i32i8imm:$src2),
 
2964
                   "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2965
                 [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
 
2966
 
 
2967
let Constraints = "" in {
 
2968
  def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
 
2969
                   "adc{b}\t{$src2, $dst|$dst, $src2}",
 
2970
                   [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
 
2971
  def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
2972
                   "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2973
                   [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
 
2974
                   OpSize;
 
2975
  def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
 
2976
                   "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2977
                   [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
 
2978
  def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
 
2979
                      "adc{b}\t{$src2, $dst|$dst, $src2}",
 
2980
                  [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
 
2981
  def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
 
2982
                      "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2983
                  [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
 
2984
                  OpSize;
 
2985
  def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
 
2986
                     "adc{w}\t{$src2, $dst|$dst, $src2}",
 
2987
               [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
 
2988
               OpSize;
 
2989
  def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
 
2990
                      "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2991
                  [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
 
2992
  def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
 
2993
                     "adc{l}\t{$src2, $dst|$dst, $src2}",
 
2994
               [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
 
2995
 
 
2996
  def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
 
2997
                   "adc{b}\t{$src, %al|%al, $src}", []>;
 
2998
  def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
 
2999
                      "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3000
  def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
 
3001
                      "adc{l}\t{$src, %eax|%eax, $src}", []>;
 
3002
} // Constraints = ""
 
3003
} // Uses = [EFLAGS]
 
3004
 
 
3005
// Register-Register Subtraction
 
3006
def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
3007
                "sub{b}\t{$src2, $dst|$dst, $src2}",
 
3008
                [(set GR8:$dst, EFLAGS,
 
3009
                      (X86sub_flag GR8:$src1, GR8:$src2))]>;
 
3010
def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
 
3011
                "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3012
                [(set GR16:$dst, EFLAGS,
 
3013
                      (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
 
3014
def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
 
3015
                "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3016
                [(set GR32:$dst, EFLAGS,
 
3017
                      (X86sub_flag GR32:$src1, GR32:$src2))]>;
 
3018
 
 
3019
let isCodeGenOnly = 1 in {
 
3020
def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
3021
                   "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
 
3022
def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst), 
 
3023
                    (ins GR16:$src1, GR16:$src2),
 
3024
                    "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
3025
def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst), 
 
3026
                    (ins GR32:$src1, GR32:$src2),
 
3027
                    "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
 
3028
}
 
3029
 
 
3030
// Register-Memory Subtraction
 
3031
def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
 
3032
                                 (ins GR8 :$src1, i8mem :$src2),
 
3033
                "sub{b}\t{$src2, $dst|$dst, $src2}",
 
3034
                [(set GR8:$dst, EFLAGS,
 
3035
                      (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
 
3036
def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
 
3037
                                 (ins GR16:$src1, i16mem:$src2),
 
3038
                "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3039
                [(set GR16:$dst, EFLAGS,
 
3040
                      (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
 
3041
def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
 
3042
                                 (ins GR32:$src1, i32mem:$src2),
 
3043
                "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3044
                [(set GR32:$dst, EFLAGS,
 
3045
                      (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
 
3046
 
 
3047
// Register-Integer Subtraction
 
3048
def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
 
3049
                                 (ins GR8:$src1, i8imm:$src2),
 
3050
                    "sub{b}\t{$src2, $dst|$dst, $src2}",
 
3051
                    [(set GR8:$dst, EFLAGS,
 
3052
                          (X86sub_flag GR8:$src1, imm:$src2))]>;
 
3053
def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
 
3054
                                 (ins GR16:$src1, i16imm:$src2),
 
3055
                    "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3056
                    [(set GR16:$dst, EFLAGS,
 
3057
                          (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
 
3058
def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
 
3059
                                 (ins GR32:$src1, i32imm:$src2),
 
3060
                    "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3061
                    [(set GR32:$dst, EFLAGS,
 
3062
                          (X86sub_flag GR32:$src1, imm:$src2))]>;
 
3063
def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
 
3064
                                (ins GR16:$src1, i16i8imm:$src2),
 
3065
                   "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3066
                   [(set GR16:$dst, EFLAGS,
 
3067
                         (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
 
3068
def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
 
3069
                                (ins GR32:$src1, i32i8imm:$src2),
 
3070
                   "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3071
                   [(set GR32:$dst, EFLAGS,
 
3072
                         (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
 
3073
 
 
3074
let Constraints = "" in {
 
3075
  // Memory-Register Subtraction
 
3076
  def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
 
3077
                   "sub{b}\t{$src2, $dst|$dst, $src2}",
 
3078
                   [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
 
3079
                    (implicit EFLAGS)]>;
 
3080
  def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
3081
                   "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3082
                   [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
 
3083
                    (implicit EFLAGS)]>, OpSize;
 
3084
  def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
 
3085
                   "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3086
                   [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
 
3087
                    (implicit EFLAGS)]>;
 
3088
 
 
3089
  // Memory-Integer Subtraction
 
3090
  def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
 
3091
                     "sub{b}\t{$src2, $dst|$dst, $src2}",
 
3092
                     [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
 
3093
                      (implicit EFLAGS)]>;
 
3094
  def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
 
3095
                      "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3096
                      [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
 
3097
                       (implicit EFLAGS)]>, OpSize;
 
3098
  def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
 
3099
                      "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3100
                      [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
 
3101
                       (implicit EFLAGS)]>;
 
3102
  def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
 
3103
                     "sub{w}\t{$src2, $dst|$dst, $src2}",
 
3104
                     [(store (sub (load addr:$dst), i16immSExt8:$src2),
 
3105
                             addr:$dst),
 
3106
                      (implicit EFLAGS)]>, OpSize;
 
3107
  def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
 
3108
                     "sub{l}\t{$src2, $dst|$dst, $src2}",
 
3109
                     [(store (sub (load addr:$dst), i32immSExt8:$src2),
 
3110
                             addr:$dst),
 
3111
                      (implicit EFLAGS)]>;
 
3112
                      
 
3113
  def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
 
3114
                   "sub{b}\t{$src, %al|%al, $src}", []>;
 
3115
  def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
 
3116
                      "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3117
  def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
 
3118
                      "sub{l}\t{$src, %eax|%eax, $src}", []>;
 
3119
} // Constraints = ""
 
3120
 
 
3121
let Uses = [EFLAGS] in {
 
3122
def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
 
3123
                                     (ins GR8:$src1, GR8:$src2),
 
3124
                  "sbb{b}\t{$src2, $dst|$dst, $src2}",
 
3125
                 [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
 
3126
def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
 
3127
                                     (ins GR16:$src1, GR16:$src2),
 
3128
                  "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3129
                 [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
 
3130
def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
 
3131
                                      (ins GR32:$src1, GR32:$src2),
 
3132
                  "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3133
                 [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
 
3134
 
 
3135
let Constraints = "" in {
 
3136
  def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
 
3137
                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
 
3138
                   [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
 
3139
  def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
 
3140
                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3141
                   [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
 
3142
                   OpSize;
 
3143
  def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
 
3144
                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3145
                   [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
 
3146
  def SBB8mi  : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
 
3147
                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
 
3148
                   [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
 
3149
  def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
 
3150
                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3151
                  [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
 
3152
                  OpSize;
 
3153
  def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
 
3154
                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3155
               [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
 
3156
               OpSize;
 
3157
  def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
 
3158
                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3159
                  [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
 
3160
  def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
 
3161
                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3162
               [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
 
3163
               
 
3164
  def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
 
3165
                   "sbb{b}\t{$src, %al|%al, $src}", []>;
 
3166
  def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
 
3167
                      "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3168
  def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
 
3169
                      "sbb{l}\t{$src, %eax|%eax, $src}", []>;
 
3170
} // Constraints = ""
 
3171
 
 
3172
let isCodeGenOnly = 1 in {
 
3173
def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
 
3174
                   "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
 
3175
def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst), 
 
3176
                    (ins GR16:$src1, GR16:$src2),
 
3177
                    "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
 
3178
def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst), 
 
3179
                    (ins GR32:$src1, GR32:$src2),
 
3180
                    "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
 
3181
}
 
3182
 
 
3183
def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
 
3184
                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
 
3185
                    [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
 
3186
def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
 
3187
                                  (ins GR16:$src1, i16mem:$src2),
 
3188
                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3189
                    [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
 
3190
                    OpSize;
 
3191
def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
 
3192
                                  (ins GR32:$src1, i32mem:$src2),
 
3193
                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3194
                    [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
 
3195
def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
 
3196
                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
 
3197
                    [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
 
3198
def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
 
3199
                                 (ins GR16:$src1, i16imm:$src2),
 
3200
                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3201
                    [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
 
3202
def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
 
3203
                                (ins GR16:$src1, i16i8imm:$src2),
 
3204
                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
 
3205
                   [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
 
3206
                   OpSize;
 
3207
def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
 
3208
                                 (ins GR32:$src1, i32imm:$src2),
 
3209
                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3210
                    [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
 
3211
def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
 
3212
                                (ins GR32:$src1, i32i8imm:$src2),
 
3213
                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
 
3214
                   [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
 
3215
} // Uses = [EFLAGS]
 
3216
} // Defs = [EFLAGS]
 
3217
 
 
3218
let Defs = [EFLAGS] in {
 
3219
let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
 
3220
// Register-Register Signed Integer Multiply
 
3221
def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
 
3222
                 "imul{w}\t{$src2, $dst|$dst, $src2}",
 
3223
                 [(set GR16:$dst, EFLAGS,
 
3224
                       (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
 
3225
def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
 
3226
                 "imul{l}\t{$src2, $dst|$dst, $src2}",
 
3227
                 [(set GR32:$dst, EFLAGS,
 
3228
                       (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
 
3229
}
 
3230
 
 
3231
// Register-Memory Signed Integer Multiply
 
3232
def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
 
3233
                                  (ins GR16:$src1, i16mem:$src2),
 
3234
                 "imul{w}\t{$src2, $dst|$dst, $src2}",
 
3235
                 [(set GR16:$dst, EFLAGS,
 
3236
                       (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
 
3237
               TB, OpSize;
 
3238
def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), 
 
3239
                 (ins GR32:$src1, i32mem:$src2),
 
3240
                 "imul{l}\t{$src2, $dst|$dst, $src2}",
 
3241
                 [(set GR32:$dst, EFLAGS,
 
3242
                       (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
 
3243
} // Defs = [EFLAGS]
 
3244
} // end Two Address instructions
 
3245
 
 
3246
// Suprisingly enough, these are not two address instructions!
 
3247
let Defs = [EFLAGS] in {
 
3248
// Register-Integer Signed Integer Multiply
 
3249
def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
 
3250
                      (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
 
3251
                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3252
                      [(set GR16:$dst, EFLAGS, 
 
3253
                            (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
 
3254
def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
 
3255
                      (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
 
3256
                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3257
                      [(set GR32:$dst, EFLAGS,
 
3258
                            (X86smul_flag GR32:$src1, imm:$src2))]>;
 
3259
def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
 
3260
                     (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
 
3261
                     "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3262
                     [(set GR16:$dst, EFLAGS,
 
3263
                           (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
 
3264
                 OpSize;
 
3265
def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
 
3266
                     (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
 
3267
                     "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3268
                     [(set GR32:$dst, EFLAGS,
 
3269
                           (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
 
3270
 
 
3271
// Memory-Integer Signed Integer Multiply
 
3272
def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                     // GR16 = [mem16]*I16
 
3273
                      (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
 
3274
                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3275
                      [(set GR16:$dst, EFLAGS,
 
3276
                            (X86smul_flag (load addr:$src1), imm:$src2))]>,
 
3277
                 OpSize;
 
3278
def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                     // GR32 = [mem32]*I32
 
3279
                      (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
 
3280
                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3281
                      [(set GR32:$dst, EFLAGS,
 
3282
                            (X86smul_flag (load addr:$src1), imm:$src2))]>;
 
3283
def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
 
3284
                     (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
 
3285
                     "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3286
                     [(set GR16:$dst, EFLAGS,
 
3287
                           (X86smul_flag (load addr:$src1),
 
3288
                                         i16immSExt8:$src2))]>, OpSize;
 
3289
def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
 
3290
                     (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
 
3291
                     "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
 
3292
                     [(set GR32:$dst, EFLAGS,
 
3293
                           (X86smul_flag (load addr:$src1),
 
3294
                                         i32immSExt8:$src2))]>;
 
3295
} // Defs = [EFLAGS]
 
3296
 
 
3297
//===----------------------------------------------------------------------===//
 
3298
// Test instructions are just like AND, except they don't generate a result.
 
3299
//
 
3300
let Defs = [EFLAGS] in {
 
3301
let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
 
3302
def TEST8rr  : I<0x84, MRMSrcReg, (outs),  (ins GR8:$src1, GR8:$src2),
 
3303
                     "test{b}\t{$src2, $src1|$src1, $src2}",
 
3304
                     [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
 
3305
def TEST16rr : I<0x85, MRMSrcReg, (outs),  (ins GR16:$src1, GR16:$src2),
 
3306
                     "test{w}\t{$src2, $src1|$src1, $src2}",
 
3307
                     [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
 
3308
                      0))]>,
 
3309
                 OpSize;
 
3310
def TEST32rr : I<0x85, MRMSrcReg, (outs),  (ins GR32:$src1, GR32:$src2),
 
3311
                     "test{l}\t{$src2, $src1|$src1, $src2}",
 
3312
                     [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
 
3313
                      0))]>;
 
3314
}
 
3315
 
 
3316
def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
 
3317
                   "test{b}\t{$src, %al|%al, $src}", []>;
 
3318
def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
 
3319
                     "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3320
def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
 
3321
                     "test{l}\t{$src, %eax|%eax, $src}", []>;
 
3322
 
 
3323
def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
 
3324
                     "test{b}\t{$src2, $src1|$src1, $src2}",
 
3325
                     [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
 
3326
                       0))]>;
 
3327
def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
 
3328
                     "test{w}\t{$src2, $src1|$src1, $src2}",
 
3329
                     [(set EFLAGS, (X86cmp (and GR16:$src1,
 
3330
                                         (loadi16 addr:$src2)), 0))]>, OpSize;
 
3331
def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
 
3332
                     "test{l}\t{$src2, $src1|$src1, $src2}",
 
3333
                     [(set EFLAGS, (X86cmp (and GR32:$src1,
 
3334
                                                (loadi32 addr:$src2)), 0))]>;
 
3335
 
 
3336
def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
 
3337
                    (outs),  (ins GR8:$src1, i8imm:$src2),
 
3338
                    "test{b}\t{$src2, $src1|$src1, $src2}",
 
3339
                    [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
 
3340
def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
 
3341
                    (outs),  (ins GR16:$src1, i16imm:$src2),
 
3342
                    "test{w}\t{$src2, $src1|$src1, $src2}",
 
3343
                    [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
 
3344
                    OpSize;
 
3345
def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
 
3346
                    (outs),  (ins GR32:$src1, i32imm:$src2),
 
3347
                    "test{l}\t{$src2, $src1|$src1, $src2}",
 
3348
                    [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
 
3349
 
 
3350
def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
 
3351
                    (outs), (ins i8mem:$src1, i8imm:$src2),
 
3352
                    "test{b}\t{$src2, $src1|$src1, $src2}",
 
3353
                    [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
 
3354
                     0))]>;
 
3355
def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
 
3356
                    (outs), (ins i16mem:$src1, i16imm:$src2),
 
3357
                    "test{w}\t{$src2, $src1|$src1, $src2}",
 
3358
                    [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
 
3359
                     0))]>, OpSize;
 
3360
def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
 
3361
                    (outs), (ins i32mem:$src1, i32imm:$src2),
 
3362
                    "test{l}\t{$src2, $src1|$src1, $src2}",
 
3363
                    [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
 
3364
                     0))]>;
 
3365
} // Defs = [EFLAGS]
 
3366
 
 
3367
 
 
3368
// Condition code ops, incl. set if equal/not equal/...
 
3369
let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
 
3370
def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
 
3371
let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
 
3372
def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
 
3373
 
 
3374
let Uses = [EFLAGS] in {
 
3375
// Use sbb to materialize carry bit.
 
3376
let Defs = [EFLAGS], isCodeGenOnly = 1 in {
 
3377
// FIXME: These are pseudo ops that should be replaced with Pat<> patterns.
 
3378
// However, Pat<> can't replicate the destination reg into the inputs of the
 
3379
// result.
 
3380
// FIXME: Change these to have encoding Pseudo when X86MCCodeEmitter replaces
 
3381
// X86CodeEmitter.
 
3382
def SETB_C8r : I<0x18, MRMInitReg, (outs GR8:$dst), (ins), "",
 
3383
                 [(set GR8:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
 
3384
def SETB_C16r : I<0x19, MRMInitReg, (outs GR16:$dst), (ins), "",
 
3385
                 [(set GR16:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>,
 
3386
                OpSize;
 
3387
def SETB_C32r : I<0x19, MRMInitReg, (outs GR32:$dst), (ins), "",
 
3388
                 [(set GR32:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
 
3389
} // isCodeGenOnly
 
3390
 
 
3391
def SETEr    : I<0x94, MRM0r, 
 
3392
                 (outs GR8   :$dst), (ins),
 
3393
                 "sete\t$dst",
 
3394
                 [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
 
3395
               TB;                        // GR8 = ==
 
3396
def SETEm    : I<0x94, MRM0m, 
 
3397
                 (outs), (ins i8mem:$dst),
 
3398
                 "sete\t$dst",
 
3399
                 [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
 
3400
               TB;                        // [mem8] = ==
 
3401
 
 
3402
def SETNEr   : I<0x95, MRM0r, 
 
3403
                 (outs GR8   :$dst), (ins),
 
3404
                 "setne\t$dst",
 
3405
                 [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
 
3406
               TB;                        // GR8 = !=
 
3407
def SETNEm   : I<0x95, MRM0m, 
 
3408
                 (outs), (ins i8mem:$dst),
 
3409
                 "setne\t$dst",
 
3410
                 [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
 
3411
               TB;                        // [mem8] = !=
 
3412
 
 
3413
def SETLr    : I<0x9C, MRM0r, 
 
3414
                 (outs GR8   :$dst), (ins),
 
3415
                 "setl\t$dst",
 
3416
                 [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
 
3417
               TB;                        // GR8 = <  signed
 
3418
def SETLm    : I<0x9C, MRM0m, 
 
3419
                 (outs), (ins i8mem:$dst),
 
3420
                 "setl\t$dst",
 
3421
                 [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
 
3422
               TB;                        // [mem8] = <  signed
 
3423
 
 
3424
def SETGEr   : I<0x9D, MRM0r, 
 
3425
                 (outs GR8   :$dst), (ins),
 
3426
                 "setge\t$dst",
 
3427
                 [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
 
3428
               TB;                        // GR8 = >= signed
 
3429
def SETGEm   : I<0x9D, MRM0m, 
 
3430
                 (outs), (ins i8mem:$dst),
 
3431
                 "setge\t$dst",
 
3432
                 [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
 
3433
               TB;                        // [mem8] = >= signed
 
3434
 
 
3435
def SETLEr   : I<0x9E, MRM0r, 
 
3436
                 (outs GR8   :$dst), (ins),
 
3437
                 "setle\t$dst",
 
3438
                 [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
 
3439
               TB;                        // GR8 = <= signed
 
3440
def SETLEm   : I<0x9E, MRM0m, 
 
3441
                 (outs), (ins i8mem:$dst),
 
3442
                 "setle\t$dst",
 
3443
                 [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
 
3444
               TB;                        // [mem8] = <= signed
 
3445
 
 
3446
def SETGr    : I<0x9F, MRM0r, 
 
3447
                 (outs GR8   :$dst), (ins),
 
3448
                 "setg\t$dst",
 
3449
                 [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
 
3450
               TB;                        // GR8 = >  signed
 
3451
def SETGm    : I<0x9F, MRM0m, 
 
3452
                 (outs), (ins i8mem:$dst),
 
3453
                 "setg\t$dst",
 
3454
                 [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
 
3455
               TB;                        // [mem8] = >  signed
 
3456
 
 
3457
def SETBr    : I<0x92, MRM0r,
 
3458
                 (outs GR8   :$dst), (ins),
 
3459
                 "setb\t$dst",
 
3460
                 [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
 
3461
               TB;                        // GR8 = <  unsign
 
3462
def SETBm    : I<0x92, MRM0m,
 
3463
                 (outs), (ins i8mem:$dst),
 
3464
                 "setb\t$dst",
 
3465
                 [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
 
3466
               TB;                        // [mem8] = <  unsign
 
3467
 
 
3468
def SETAEr   : I<0x93, MRM0r, 
 
3469
                 (outs GR8   :$dst), (ins),
 
3470
                 "setae\t$dst",
 
3471
                 [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
 
3472
               TB;                        // GR8 = >= unsign
 
3473
def SETAEm   : I<0x93, MRM0m, 
 
3474
                 (outs), (ins i8mem:$dst),
 
3475
                 "setae\t$dst",
 
3476
                 [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
 
3477
               TB;                        // [mem8] = >= unsign
 
3478
 
 
3479
def SETBEr   : I<0x96, MRM0r, 
 
3480
                 (outs GR8   :$dst), (ins),
 
3481
                 "setbe\t$dst",
 
3482
                 [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
 
3483
               TB;                        // GR8 = <= unsign
 
3484
def SETBEm   : I<0x96, MRM0m, 
 
3485
                 (outs), (ins i8mem:$dst),
 
3486
                 "setbe\t$dst",
 
3487
                 [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
 
3488
               TB;                        // [mem8] = <= unsign
 
3489
 
 
3490
def SETAr    : I<0x97, MRM0r, 
 
3491
                 (outs GR8   :$dst), (ins),
 
3492
                 "seta\t$dst",
 
3493
                 [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
 
3494
               TB;                        // GR8 = >  signed
 
3495
def SETAm    : I<0x97, MRM0m, 
 
3496
                 (outs), (ins i8mem:$dst),
 
3497
                 "seta\t$dst",
 
3498
                 [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
 
3499
               TB;                        // [mem8] = >  signed
 
3500
 
 
3501
def SETSr    : I<0x98, MRM0r, 
 
3502
                 (outs GR8   :$dst), (ins),
 
3503
                 "sets\t$dst",
 
3504
                 [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
 
3505
               TB;                        // GR8 = <sign bit>
 
3506
def SETSm    : I<0x98, MRM0m, 
 
3507
                 (outs), (ins i8mem:$dst),
 
3508
                 "sets\t$dst",
 
3509
                 [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
 
3510
               TB;                        // [mem8] = <sign bit>
 
3511
def SETNSr   : I<0x99, MRM0r, 
 
3512
                 (outs GR8   :$dst), (ins),
 
3513
                 "setns\t$dst",
 
3514
                 [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
 
3515
               TB;                        // GR8 = !<sign bit>
 
3516
def SETNSm   : I<0x99, MRM0m, 
 
3517
                 (outs), (ins i8mem:$dst),
 
3518
                 "setns\t$dst",
 
3519
                 [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
 
3520
               TB;                        // [mem8] = !<sign bit>
 
3521
 
 
3522
def SETPr    : I<0x9A, MRM0r, 
 
3523
                 (outs GR8   :$dst), (ins),
 
3524
                 "setp\t$dst",
 
3525
                 [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
 
3526
               TB;                        // GR8 = parity
 
3527
def SETPm    : I<0x9A, MRM0m, 
 
3528
                 (outs), (ins i8mem:$dst),
 
3529
                 "setp\t$dst",
 
3530
                 [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
 
3531
               TB;                        // [mem8] = parity
 
3532
def SETNPr   : I<0x9B, MRM0r, 
 
3533
                 (outs GR8   :$dst), (ins),
 
3534
                 "setnp\t$dst",
 
3535
                 [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
 
3536
               TB;                        // GR8 = not parity
 
3537
def SETNPm   : I<0x9B, MRM0m, 
 
3538
                 (outs), (ins i8mem:$dst),
 
3539
                 "setnp\t$dst",
 
3540
                 [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
 
3541
               TB;                        // [mem8] = not parity
 
3542
 
 
3543
def SETOr    : I<0x90, MRM0r, 
 
3544
                 (outs GR8   :$dst), (ins),
 
3545
                 "seto\t$dst",
 
3546
                 [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
 
3547
               TB;                        // GR8 = overflow
 
3548
def SETOm    : I<0x90, MRM0m, 
 
3549
                 (outs), (ins i8mem:$dst),
 
3550
                 "seto\t$dst",
 
3551
                 [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
 
3552
               TB;                        // [mem8] = overflow
 
3553
def SETNOr   : I<0x91, MRM0r, 
 
3554
                 (outs GR8   :$dst), (ins),
 
3555
                 "setno\t$dst",
 
3556
                 [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
 
3557
               TB;                        // GR8 = not overflow
 
3558
def SETNOm   : I<0x91, MRM0m, 
 
3559
                 (outs), (ins i8mem:$dst),
 
3560
                 "setno\t$dst",
 
3561
                 [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
 
3562
               TB;                        // [mem8] = not overflow
 
3563
} // Uses = [EFLAGS]
 
3564
 
 
3565
 
 
3566
// Integer comparisons
 
3567
let Defs = [EFLAGS] in {
 
3568
def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
 
3569
                 "cmp{b}\t{$src, %al|%al, $src}", []>;
 
3570
def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
 
3571
                    "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3572
def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
 
3573
                    "cmp{l}\t{$src, %eax|%eax, $src}", []>;
 
3574
 
 
3575
def CMP8rr  : I<0x38, MRMDestReg,
 
3576
                (outs), (ins GR8 :$src1, GR8 :$src2),
 
3577
                "cmp{b}\t{$src2, $src1|$src1, $src2}",
 
3578
                [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
 
3579
def CMP16rr : I<0x39, MRMDestReg,
 
3580
                (outs), (ins GR16:$src1, GR16:$src2),
 
3581
                "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3582
                [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
 
3583
def CMP32rr : I<0x39, MRMDestReg,
 
3584
                (outs), (ins GR32:$src1, GR32:$src2),
 
3585
                "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3586
                [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
 
3587
def CMP8mr  : I<0x38, MRMDestMem,
 
3588
                (outs), (ins i8mem :$src1, GR8 :$src2),
 
3589
                "cmp{b}\t{$src2, $src1|$src1, $src2}",
 
3590
                [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
 
3591
def CMP16mr : I<0x39, MRMDestMem,
 
3592
                (outs), (ins i16mem:$src1, GR16:$src2),
 
3593
                "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3594
                [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
 
3595
                 OpSize;
 
3596
def CMP32mr : I<0x39, MRMDestMem,
 
3597
                (outs), (ins i32mem:$src1, GR32:$src2),
 
3598
                "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3599
                [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
 
3600
def CMP8rm  : I<0x3A, MRMSrcMem,
 
3601
                (outs), (ins GR8 :$src1, i8mem :$src2),
 
3602
                "cmp{b}\t{$src2, $src1|$src1, $src2}",
 
3603
                [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
 
3604
def CMP16rm : I<0x3B, MRMSrcMem,
 
3605
                (outs), (ins GR16:$src1, i16mem:$src2),
 
3606
                "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3607
                [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
 
3608
                 OpSize;
 
3609
def CMP32rm : I<0x3B, MRMSrcMem,
 
3610
                (outs), (ins GR32:$src1, i32mem:$src2),
 
3611
                "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3612
                [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
 
3613
 
 
3614
// These are alternate spellings for use by the disassembler, we mark them as
 
3615
// code gen only to ensure they aren't matched by the assembler.
 
3616
let isCodeGenOnly = 1 in {
 
3617
  def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
 
3618
                    "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
 
3619
  def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
 
3620
                     "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
 
3621
  def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
 
3622
                     "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
 
3623
}
 
3624
 
 
3625
def CMP8ri  : Ii8<0x80, MRM7r,
 
3626
                  (outs), (ins GR8:$src1, i8imm:$src2),
 
3627
                  "cmp{b}\t{$src2, $src1|$src1, $src2}",
 
3628
                  [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
 
3629
def CMP16ri : Ii16<0x81, MRM7r,
 
3630
                   (outs), (ins GR16:$src1, i16imm:$src2),
 
3631
                   "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3632
                   [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
 
3633
def CMP32ri : Ii32<0x81, MRM7r,
 
3634
                   (outs), (ins GR32:$src1, i32imm:$src2),
 
3635
                   "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3636
                   [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
 
3637
def CMP8mi  : Ii8 <0x80, MRM7m,
 
3638
                   (outs), (ins i8mem :$src1, i8imm :$src2),
 
3639
                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
 
3640
                   [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
 
3641
def CMP16mi : Ii16<0x81, MRM7m,
 
3642
                   (outs), (ins i16mem:$src1, i16imm:$src2),
 
3643
                   "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3644
                   [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
 
3645
                   OpSize;
 
3646
def CMP32mi : Ii32<0x81, MRM7m,
 
3647
                   (outs), (ins i32mem:$src1, i32imm:$src2),
 
3648
                   "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3649
                   [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
 
3650
def CMP16ri8 : Ii8<0x83, MRM7r,
 
3651
                   (outs), (ins GR16:$src1, i16i8imm:$src2),
 
3652
                   "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3653
                   [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
 
3654
                    OpSize;
 
3655
def CMP16mi8 : Ii8<0x83, MRM7m,
 
3656
                   (outs), (ins i16mem:$src1, i16i8imm:$src2),
 
3657
                   "cmp{w}\t{$src2, $src1|$src1, $src2}",
 
3658
                   [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
 
3659
                                         i16immSExt8:$src2))]>, OpSize;
 
3660
def CMP32mi8 : Ii8<0x83, MRM7m,
 
3661
                   (outs), (ins i32mem:$src1, i32i8imm:$src2),
 
3662
                   "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3663
                   [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
 
3664
                                         i32immSExt8:$src2))]>;
 
3665
def CMP32ri8 : Ii8<0x83, MRM7r,
 
3666
                   (outs), (ins GR32:$src1, i32i8imm:$src2),
 
3667
                   "cmp{l}\t{$src2, $src1|$src1, $src2}",
 
3668
                   [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
 
3669
} // Defs = [EFLAGS]
 
3670
 
 
3671
// Bit tests.
 
3672
// TODO: BTC, BTR, and BTS
 
3673
let Defs = [EFLAGS] in {
 
3674
def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
 
3675
               "bt{w}\t{$src2, $src1|$src1, $src2}",
 
3676
               [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
 
3677
def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
 
3678
               "bt{l}\t{$src2, $src1|$src1, $src2}",
 
3679
               [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
 
3680
 
 
3681
// Unlike with the register+register form, the memory+register form of the
 
3682
// bt instruction does not ignore the high bits of the index. From ISel's
 
3683
// perspective, this is pretty bizarre. Make these instructions disassembly
 
3684
// only for now.
 
3685
 
 
3686
def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
 
3687
               "bt{w}\t{$src2, $src1|$src1, $src2}", 
 
3688
//               [(X86bt (loadi16 addr:$src1), GR16:$src2),
 
3689
//                (implicit EFLAGS)]
 
3690
               []
 
3691
               >, OpSize, TB, Requires<[FastBTMem]>;
 
3692
def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
 
3693
               "bt{l}\t{$src2, $src1|$src1, $src2}", 
 
3694
//               [(X86bt (loadi32 addr:$src1), GR32:$src2),
 
3695
//                (implicit EFLAGS)]
 
3696
               []
 
3697
               >, TB, Requires<[FastBTMem]>;
 
3698
 
 
3699
def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
 
3700
                "bt{w}\t{$src2, $src1|$src1, $src2}",
 
3701
                [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
 
3702
                OpSize, TB;
 
3703
def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
 
3704
                "bt{l}\t{$src2, $src1|$src1, $src2}",
 
3705
                [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
 
3706
// Note that these instructions don't need FastBTMem because that
 
3707
// only applies when the other operand is in a register. When it's
 
3708
// an immediate, bt is still fast.
 
3709
def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
 
3710
                "bt{w}\t{$src2, $src1|$src1, $src2}",
 
3711
                [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
 
3712
                 ]>, OpSize, TB;
 
3713
def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
 
3714
                "bt{l}\t{$src2, $src1|$src1, $src2}",
 
3715
                [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
 
3716
                 ]>, TB;
 
3717
 
 
3718
def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
 
3719
                "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3720
def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
 
3721
                "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3722
def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
 
3723
                "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3724
def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
 
3725
                "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3726
def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
 
3727
                    "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3728
def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
 
3729
                    "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3730
def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
 
3731
                    "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3732
def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
 
3733
                    "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3734
 
 
3735
def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
 
3736
                "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3737
def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
 
3738
                "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3739
def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
 
3740
                "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3741
def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
 
3742
                "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3743
def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
 
3744
                    "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3745
def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
 
3746
                    "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3747
def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
 
3748
                    "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3749
def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
 
3750
                    "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3751
 
 
3752
def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
 
3753
                "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3754
def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
 
3755
                "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3756
def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
 
3757
                "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3758
def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
 
3759
                "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3760
def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
 
3761
                    "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3762
def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
 
3763
                    "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3764
def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
 
3765
                    "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
 
3766
def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
 
3767
                    "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
 
3768
} // Defs = [EFLAGS]
 
3769
 
 
3770
// Sign/Zero extenders
 
3771
// Use movsbl intead of movsbw; we don't care about the high 16 bits
 
3772
// of the register here. This has a smaller encoding and avoids a
 
3773
// partial-register update.  Actual movsbw included for the disassembler.
 
3774
def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
 
3775
                    "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
3776
def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
 
3777
                    "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
3778
def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
 
3779
                   "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
 
3780
def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
 
3781
                   "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
 
3782
def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
 
3783
                   "movs{bl|x}\t{$src, $dst|$dst, $src}",
 
3784
                   [(set GR32:$dst, (sext GR8:$src))]>, TB;
 
3785
def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
 
3786
                   "movs{bl|x}\t{$src, $dst|$dst, $src}",
 
3787
                   [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
 
3788
def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
 
3789
                   "movs{wl|x}\t{$src, $dst|$dst, $src}",
 
3790
                   [(set GR32:$dst, (sext GR16:$src))]>, TB;
 
3791
def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
 
3792
                   "movs{wl|x}\t{$src, $dst|$dst, $src}",
 
3793
                   [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
 
3794
 
 
3795
// Use movzbl intead of movzbw; we don't care about the high 16 bits
 
3796
// of the register here. This has a smaller encoding and avoids a
 
3797
// partial-register update.  Actual movzbw included for the disassembler.
 
3798
def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
 
3799
                    "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
3800
def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
 
3801
                    "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;  
 
3802
def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
 
3803
                   "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
 
3804
def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
 
3805
                   "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
 
3806
def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
 
3807
                   "movz{bl|x}\t{$src, $dst|$dst, $src}",
 
3808
                   [(set GR32:$dst, (zext GR8:$src))]>, TB;
 
3809
def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
 
3810
                   "movz{bl|x}\t{$src, $dst|$dst, $src}",
 
3811
                   [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
 
3812
def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
 
3813
                   "movz{wl|x}\t{$src, $dst|$dst, $src}",
 
3814
                   [(set GR32:$dst, (zext GR16:$src))]>, TB;
 
3815
def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
 
3816
                   "movz{wl|x}\t{$src, $dst|$dst, $src}",
 
3817
                   [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
 
3818
 
 
3819
// These are the same as the regular MOVZX32rr8 and MOVZX32rm8
 
3820
// except that they use GR32_NOREX for the output operand register class
 
3821
// instead of GR32. This allows them to operate on h registers on x86-64.
 
3822
def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
 
3823
                         (outs GR32_NOREX:$dst), (ins GR8:$src),
 
3824
                         "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
 
3825
                         []>, TB;
 
3826
let mayLoad = 1 in
 
3827
def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
 
3828
                         (outs GR32_NOREX:$dst), (ins i8mem:$src),
 
3829
                         "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
 
3830
                         []>, TB;
 
3831
 
 
3832
let neverHasSideEffects = 1 in {
 
3833
  let Defs = [AX], Uses = [AL] in
 
3834
  def CBW : I<0x98, RawFrm, (outs), (ins),
 
3835
              "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
 
3836
  let Defs = [EAX], Uses = [AX] in
 
3837
  def CWDE : I<0x98, RawFrm, (outs), (ins),
 
3838
              "{cwtl|cwde}", []>;   // EAX = signext(AX)
 
3839
 
 
3840
  let Defs = [AX,DX], Uses = [AX] in
 
3841
  def CWD : I<0x99, RawFrm, (outs), (ins),
 
3842
              "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
 
3843
  let Defs = [EAX,EDX], Uses = [EAX] in
 
3844
  def CDQ : I<0x99, RawFrm, (outs), (ins),
 
3845
              "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
 
3846
}
 
3847
 
 
3848
//===----------------------------------------------------------------------===//
 
3849
// Alias Instructions
 
3850
//===----------------------------------------------------------------------===//
 
3851
 
 
3852
// Alias instructions that map movr0 to xor.
 
3853
// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
 
3854
// FIXME: Set encoding to pseudo.
 
3855
let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
 
3856
    isCodeGenOnly = 1 in {
 
3857
def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "",
 
3858
                 [(set GR8:$dst, 0)]>;
 
3859
 
 
3860
// We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller
 
3861
// encoding and avoids a partial-register update sometimes, but doing so
 
3862
// at isel time interferes with rematerialization in the current register
 
3863
// allocator. For now, this is rewritten when the instruction is lowered
 
3864
// to an MCInst.
 
3865
def MOV16r0   : I<0x31, MRMInitReg, (outs GR16:$dst), (ins),
 
3866
                 "",
 
3867
                 [(set GR16:$dst, 0)]>, OpSize;
 
3868
                 
 
3869
// FIXME: Set encoding to pseudo.
 
3870
def MOV32r0  : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "",
 
3871
                 [(set GR32:$dst, 0)]>;
 
3872
}
 
3873
 
 
3874
//===----------------------------------------------------------------------===//
 
3875
// Thread Local Storage Instructions
 
3876
//
 
3877
 
 
3878
// ELF TLS Support
 
3879
// All calls clobber the non-callee saved registers. ESP is marked as
 
3880
// a use to prevent stack-pointer assignments that appear immediately
 
3881
// before calls from potentially appearing dead.
 
3882
let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
 
3883
            MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
 
3884
            XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
 
3885
            XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
 
3886
    Uses = [ESP] in
 
3887
def TLS_addr32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
 
3888
                  "leal\t$sym, %eax; "
 
3889
                  "call\t___tls_get_addr@PLT",
 
3890
                  [(X86tlsaddr tls32addr:$sym)]>,
 
3891
                  Requires<[In32BitMode]>;
 
3892
 
 
3893
// Darwin TLS Support
 
3894
// For i386, the address of the thunk is passed on the stack, on return the 
 
3895
// address of the variable is in %eax.  %ecx is trashed during the function 
 
3896
// call.  All other registers are preserved.
 
3897
let Defs = [EAX, ECX],
 
3898
    Uses = [ESP],
 
3899
    usesCustomInserter = 1 in
 
3900
def TLSCall_32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
 
3901
                "# TLSCall_32",
 
3902
                [(X86TLSCall addr:$sym)]>,
 
3903
                Requires<[In32BitMode]>;
 
3904
                
 
3905
let AddedComplexity = 5, isCodeGenOnly = 1 in
 
3906
def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
3907
                   "movl\t%gs:$src, $dst",
 
3908
                   [(set GR32:$dst, (gsload addr:$src))]>, SegGS;
 
3909
 
 
3910
let AddedComplexity = 5, isCodeGenOnly = 1 in
 
3911
def FS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
3912
                   "movl\t%fs:$src, $dst",
 
3913
                   [(set GR32:$dst, (fsload addr:$src))]>, SegFS;
 
3914
 
 
3915
//===----------------------------------------------------------------------===//
 
3916
// EH Pseudo Instructions
 
3917
//
 
3918
let isTerminator = 1, isReturn = 1, isBarrier = 1,
 
3919
    hasCtrlDep = 1, isCodeGenOnly = 1 in {
 
3920
def EH_RETURN   : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
 
3921
                    "ret\t#eh_return, addr: $addr",
 
3922
                    [(X86ehret GR32:$addr)]>;
 
3923
 
 
3924
}
 
3925
 
 
3926
//===----------------------------------------------------------------------===//
 
3927
// Atomic support
 
3928
//
 
3929
 
 
3930
// Memory barriers
 
3931
 
 
3932
// TODO: Get this to fold the constant into the instruction.           
 
3933
def OR32mrLocked  : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$zero),
 
3934
                      "lock\n\t"
 
3935
                      "or{l}\t{$zero, $dst|$dst, $zero}",
 
3936
                      []>, Requires<[In32BitMode]>, LOCK;
 
3937
 
 
3938
let hasSideEffects = 1 in {
 
3939
def Int_MemBarrier : I<0, Pseudo, (outs), (ins),
 
3940
                     "#MEMBARRIER",
 
3941
                     [(X86MemBarrier)]>, Requires<[HasSSE2]>;
 
3942
}
 
3943
 
 
3944
// Atomic swap. These are just normal xchg instructions. But since a memory
 
3945
// operand is referenced, the atomicity is ensured.
 
3946
let Constraints = "$val = $dst" in {
 
3947
def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), 
 
3948
                 (ins GR32:$val, i32mem:$ptr),
 
3949
               "xchg{l}\t{$val, $ptr|$ptr, $val}", 
 
3950
               [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
 
3951
def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), 
 
3952
                 (ins GR16:$val, i16mem:$ptr),
 
3953
               "xchg{w}\t{$val, $ptr|$ptr, $val}", 
 
3954
               [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
 
3955
                OpSize;
 
3956
def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
 
3957
               "xchg{b}\t{$val, $ptr|$ptr, $val}", 
 
3958
               [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
 
3959
 
 
3960
def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
 
3961
                 "xchg{l}\t{$val, $src|$src, $val}", []>;
 
3962
def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
 
3963
                 "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
 
3964
def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
 
3965
                "xchg{b}\t{$val, $src|$src, $val}", []>;
 
3966
}
 
3967
 
 
3968
def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
 
3969
                  "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
 
3970
def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
 
3971
                  "xchg{l}\t{$src, %eax|%eax, $src}", []>;
 
3972
 
 
3973
// Atomic compare and swap.
 
3974
let Defs = [EAX, EFLAGS], Uses = [EAX] in {
 
3975
def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
 
3976
               "lock\n\t"
 
3977
               "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
 
3978
               [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
 
3979
}
 
3980
let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
 
3981
def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr),
 
3982
               "lock\n\t"
 
3983
               "cmpxchg8b\t$ptr",
 
3984
               [(X86cas8 addr:$ptr)]>, TB, LOCK;
 
3985
}
 
3986
 
 
3987
let Defs = [AX, EFLAGS], Uses = [AX] in {
 
3988
def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
 
3989
               "lock\n\t"
 
3990
               "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
 
3991
               [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
 
3992
}
 
3993
let Defs = [AL, EFLAGS], Uses = [AL] in {
 
3994
def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
 
3995
               "lock\n\t"
 
3996
               "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
 
3997
               [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
 
3998
}
 
3999
 
 
4000
// Atomic exchange and add
 
4001
let Constraints = "$val = $dst", Defs = [EFLAGS] in {
 
4002
def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr),
 
4003
               "lock\n\t"
 
4004
               "xadd{l}\t{$val, $ptr|$ptr, $val}",
 
4005
               [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
 
4006
                TB, LOCK;
 
4007
def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr),
 
4008
               "lock\n\t"
 
4009
               "xadd{w}\t{$val, $ptr|$ptr, $val}",
 
4010
               [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
 
4011
                TB, OpSize, LOCK;
 
4012
def LXADD8  : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
 
4013
               "lock\n\t"
 
4014
               "xadd{b}\t{$val, $ptr|$ptr, $val}",
 
4015
               [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
 
4016
                TB, LOCK;
 
4017
}
 
4018
 
 
4019
def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
 
4020
                "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
 
4021
def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
 
4022
                 "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4023
def XADD32rr  : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
 
4024
                 "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4025
 
 
4026
let mayLoad = 1, mayStore = 1 in {
 
4027
def XADD8rm   : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
 
4028
                 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
 
4029
def XADD16rm  : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
 
4030
                 "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4031
def XADD32rm  : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
 
4032
                 "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4033
}
 
4034
 
 
4035
def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
 
4036
                   "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
 
4037
def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
 
4038
                    "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4039
def CMPXCHG32rr  : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
 
4040
                     "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4041
 
 
4042
let mayLoad = 1, mayStore = 1 in {
 
4043
def CMPXCHG8rm   : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
 
4044
                     "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
 
4045
def CMPXCHG16rm  : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
 
4046
                     "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4047
def CMPXCHG32rm  : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
 
4048
                     "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4049
}
 
4050
 
 
4051
let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
 
4052
def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
 
4053
                  "cmpxchg8b\t$dst", []>, TB;
 
4054
 
 
4055
// Optimized codegen when the non-memory output is not used.
 
4056
// FIXME: Use normal add / sub instructions and add lock prefix dynamically.
 
4057
let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
 
4058
def LOCK_ADD8mr  : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
 
4059
                    "lock\n\t"
 
4060
                    "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4061
def LOCK_ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
4062
                    "lock\n\t"
 
4063
                    "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
 
4064
def LOCK_ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
 
4065
                    "lock\n\t"
 
4066
                    "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4067
def LOCK_ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
 
4068
                    "lock\n\t"
 
4069
                    "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4070
def LOCK_ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
 
4071
                    "lock\n\t"
 
4072
                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4073
def LOCK_ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
 
4074
                    "lock\n\t"
 
4075
                    "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4076
def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
 
4077
                    "lock\n\t"
 
4078
                    "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
 
4079
def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
 
4080
                    "lock\n\t"
 
4081
                    "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4082
 
 
4083
def LOCK_INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
 
4084
                    "lock\n\t"
 
4085
                    "inc{b}\t$dst", []>, LOCK;
 
4086
def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
 
4087
                    "lock\n\t"
 
4088
                    "inc{w}\t$dst", []>, OpSize, LOCK;
 
4089
def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
 
4090
                    "lock\n\t"
 
4091
                    "inc{l}\t$dst", []>, LOCK;
 
4092
 
 
4093
def LOCK_SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
 
4094
                    "lock\n\t"
 
4095
                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4096
def LOCK_SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
 
4097
                    "lock\n\t"
 
4098
                    "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
 
4099
def LOCK_SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
 
4100
                    "lock\n\t"
 
4101
                    "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4102
def LOCK_SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
 
4103
                    "lock\n\t"
 
4104
                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4105
def LOCK_SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
 
4106
                    "lock\n\t"
 
4107
                    "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
 
4108
def LOCK_SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
 
4109
                    "lock\n\t"
 
4110
                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4111
def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
 
4112
                    "lock\n\t"
 
4113
                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
 
4114
def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
 
4115
                    "lock\n\t"
 
4116
                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
 
4117
 
 
4118
def LOCK_DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
 
4119
                    "lock\n\t"
 
4120
                    "dec{b}\t$dst", []>, LOCK;
 
4121
def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
 
4122
                    "lock\n\t"
 
4123
                    "dec{w}\t$dst", []>, OpSize, LOCK;
 
4124
def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
 
4125
                    "lock\n\t"
 
4126
                    "dec{l}\t$dst", []>, LOCK;
 
4127
}
 
4128
 
 
4129
// Atomic exchange, and, or, xor
 
4130
let Constraints = "$val = $dst", Defs = [EFLAGS],
 
4131
                  usesCustomInserter = 1 in {
 
4132
def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4133
               "#ATOMAND32 PSEUDO!", 
 
4134
               [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
 
4135
def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4136
               "#ATOMOR32 PSEUDO!", 
 
4137
               [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
 
4138
def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4139
               "#ATOMXOR32 PSEUDO!", 
 
4140
               [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
 
4141
def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4142
               "#ATOMNAND32 PSEUDO!", 
 
4143
               [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
 
4144
def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
 
4145
               "#ATOMMIN32 PSEUDO!", 
 
4146
               [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
 
4147
def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4148
               "#ATOMMAX32 PSEUDO!", 
 
4149
               [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
 
4150
def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4151
               "#ATOMUMIN32 PSEUDO!", 
 
4152
               [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
 
4153
def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
 
4154
               "#ATOMUMAX32 PSEUDO!", 
 
4155
               [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
 
4156
 
 
4157
def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4158
               "#ATOMAND16 PSEUDO!", 
 
4159
               [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
 
4160
def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4161
               "#ATOMOR16 PSEUDO!", 
 
4162
               [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
 
4163
def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4164
               "#ATOMXOR16 PSEUDO!", 
 
4165
               [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
 
4166
def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4167
               "#ATOMNAND16 PSEUDO!", 
 
4168
               [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
 
4169
def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
 
4170
               "#ATOMMIN16 PSEUDO!", 
 
4171
               [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
 
4172
def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4173
               "#ATOMMAX16 PSEUDO!", 
 
4174
               [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
 
4175
def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4176
               "#ATOMUMIN16 PSEUDO!", 
 
4177
               [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
 
4178
def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
 
4179
               "#ATOMUMAX16 PSEUDO!", 
 
4180
               [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
 
4181
 
 
4182
def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
 
4183
               "#ATOMAND8 PSEUDO!", 
 
4184
               [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
 
4185
def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
 
4186
               "#ATOMOR8 PSEUDO!", 
 
4187
               [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
 
4188
def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
 
4189
               "#ATOMXOR8 PSEUDO!", 
 
4190
               [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
 
4191
def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
 
4192
               "#ATOMNAND8 PSEUDO!", 
 
4193
               [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
 
4194
}
 
4195
 
 
4196
let Constraints = "$val1 = $dst1, $val2 = $dst2", 
 
4197
                  Defs = [EFLAGS, EAX, EBX, ECX, EDX],
 
4198
                  Uses = [EAX, EBX, ECX, EDX],
 
4199
                  mayLoad = 1, mayStore = 1,
 
4200
                  usesCustomInserter = 1 in {
 
4201
def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4202
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4203
               "#ATOMAND6432 PSEUDO!", []>;
 
4204
def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4205
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4206
               "#ATOMOR6432 PSEUDO!", []>;
 
4207
def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4208
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4209
               "#ATOMXOR6432 PSEUDO!", []>;
 
4210
def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4211
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4212
               "#ATOMNAND6432 PSEUDO!", []>;
 
4213
def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4214
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4215
               "#ATOMADD6432 PSEUDO!", []>;
 
4216
def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4217
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4218
               "#ATOMSUB6432 PSEUDO!", []>;
 
4219
def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
 
4220
                               (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
 
4221
               "#ATOMSWAP6432 PSEUDO!", []>;
 
4222
}
 
4223
 
 
4224
// Segmentation support instructions.
 
4225
 
 
4226
def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 
 
4227
                "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4228
def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
4229
                "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4230
 
 
4231
// i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
 
4232
def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src), 
 
4233
                "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4234
def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
4235
                "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4236
 
 
4237
def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
 
4238
                "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize; 
 
4239
def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
 
4240
                "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4241
def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
4242
                "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB; 
 
4243
def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
4244
                "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4245
                
 
4246
def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
 
4247
 
 
4248
def STRr : I<0x00, MRM1r, (outs GR16:$dst), (ins),
 
4249
             "str{w}\t{$dst}", []>, TB;
 
4250
def STRm : I<0x00, MRM1m, (outs i16mem:$dst), (ins),
 
4251
             "str{w}\t{$dst}", []>, TB;
 
4252
def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src),
 
4253
             "ltr{w}\t{$src}", []>, TB;
 
4254
def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src),
 
4255
             "ltr{w}\t{$src}", []>, TB;
 
4256
             
 
4257
def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins),
 
4258
                 "push{w}\t%fs", []>, OpSize, TB;
 
4259
def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins),
 
4260
                 "push{l}\t%fs", []>, TB;
 
4261
def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins),
 
4262
                 "push{w}\t%gs", []>, OpSize, TB;
 
4263
def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins),
 
4264
                 "push{l}\t%gs", []>, TB;
 
4265
 
 
4266
def POPFS16 : I<0xa1, RawFrm, (outs), (ins),
 
4267
                "pop{w}\t%fs", []>, OpSize, TB;
 
4268
def POPFS32 : I<0xa1, RawFrm, (outs), (ins),
 
4269
                "pop{l}\t%fs", []>, TB;
 
4270
def POPGS16 : I<0xa9, RawFrm, (outs), (ins),
 
4271
                "pop{w}\t%gs", []>, OpSize, TB;
 
4272
def POPGS32 : I<0xa9, RawFrm, (outs), (ins),
 
4273
                "pop{l}\t%gs", []>, TB;
 
4274
 
 
4275
def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
 
4276
                "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
4277
def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
 
4278
                "lds{l}\t{$src, $dst|$dst, $src}", []>;
 
4279
def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
 
4280
                "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4281
def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
 
4282
                "lss{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4283
def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
 
4284
                "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
 
4285
def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
 
4286
                "les{l}\t{$src, $dst|$dst, $src}", []>;
 
4287
def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
 
4288
                "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4289
def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
 
4290
                "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4291
def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
 
4292
                "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
 
4293
def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
 
4294
                "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4295
 
 
4296
def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg),
 
4297
              "verr\t$seg", []>, TB;
 
4298
def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg),
 
4299
              "verr\t$seg", []>, TB;
 
4300
def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg),
 
4301
              "verw\t$seg", []>, TB;
 
4302
def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg),
 
4303
              "verw\t$seg", []>, TB;
 
4304
 
 
4305
// Descriptor-table support instructions
 
4306
 
 
4307
def SGDTm : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
 
4308
              "sgdt\t$dst", []>, TB;
 
4309
def SIDTm : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
 
4310
              "sidt\t$dst", []>, TB;
 
4311
def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
 
4312
                "sldt{w}\t$dst", []>, TB;
 
4313
def SLDT16m : I<0x00, MRM0m, (outs i16mem:$dst), (ins),
 
4314
                "sldt{w}\t$dst", []>, TB;
 
4315
def LGDTm : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
 
4316
              "lgdt\t$src", []>, TB;
 
4317
def LIDTm : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
 
4318
              "lidt\t$src", []>, TB;
 
4319
def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
 
4320
                "lldt{w}\t$src", []>, TB;
 
4321
def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
 
4322
                "lldt{w}\t$src", []>, TB;
 
4323
                
 
4324
// Lock instruction prefix
 
4325
def LOCK_PREFIX : I<0xF0, RawFrm, (outs),  (ins), "lock", []>;
 
4326
 
 
4327
// Repeat string operation instruction prefixes
 
4328
// These uses the DF flag in the EFLAGS register to inc or dec ECX
 
4329
let Defs = [ECX], Uses = [ECX,EFLAGS] in {
 
4330
// Repeat (used with INS, OUTS, MOVS, LODS and STOS)
 
4331
def REP_PREFIX : I<0xF3, RawFrm, (outs),  (ins), "rep", []>;
 
4332
// Repeat while not equal (used with CMPS and SCAS)
 
4333
def REPNE_PREFIX : I<0xF2, RawFrm, (outs),  (ins), "repne", []>;
 
4334
}
 
4335
 
 
4336
// Segment override instruction prefixes
 
4337
def CS_PREFIX : I<0x2E, RawFrm, (outs),  (ins), "cs", []>;
 
4338
def SS_PREFIX : I<0x36, RawFrm, (outs),  (ins), "ss", []>;
 
4339
def DS_PREFIX : I<0x3E, RawFrm, (outs),  (ins), "ds", []>;
 
4340
def ES_PREFIX : I<0x26, RawFrm, (outs),  (ins), "es", []>;
 
4341
def FS_PREFIX : I<0x64, RawFrm, (outs),  (ins), "fs", []>;
 
4342
def GS_PREFIX : I<0x65, RawFrm, (outs),  (ins), "gs", []>;
 
4343
 
 
4344
// String manipulation instructions
 
4345
 
 
4346
def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
 
4347
def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
 
4348
def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
 
4349
 
 
4350
def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
 
4351
def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
 
4352
def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
 
4353
 
 
4354
// CPU flow control instructions
 
4355
 
 
4356
def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
 
4357
def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
 
4358
 
 
4359
// FPU control instructions
 
4360
 
 
4361
def FNINIT : I<0xE3, RawFrm, (outs), (ins), "fninit", []>, DB;
 
4362
 
 
4363
// Flag instructions
 
4364
 
 
4365
def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
 
4366
def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
 
4367
def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
 
4368
def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
 
4369
def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
 
4370
def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
 
4371
def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
 
4372
 
 
4373
def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
 
4374
 
 
4375
// Table lookup instructions
 
4376
 
 
4377
def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
 
4378
 
 
4379
// Specialized register support
 
4380
 
 
4381
def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
 
4382
def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
 
4383
def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
 
4384
 
 
4385
def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins), 
 
4386
                "smsw{w}\t$dst", []>, OpSize, TB;
 
4387
def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins), 
 
4388
                "smsw{l}\t$dst", []>, TB;
 
4389
// For memory operands, there is only a 16-bit form
 
4390
def SMSW16m : I<0x01, MRM4m, (outs i16mem:$dst), (ins),
 
4391
                "smsw{w}\t$dst", []>, TB;
 
4392
 
 
4393
def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
 
4394
                "lmsw{w}\t$src", []>, TB;
 
4395
def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
 
4396
                "lmsw{w}\t$src", []>, TB;
 
4397
                
 
4398
def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
 
4399
 
 
4400
// Cache instructions
 
4401
 
 
4402
def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
 
4403
def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", []>, TB;
 
4404
 
 
4405
// VMX instructions
 
4406
 
 
4407
// 66 0F 38 80
 
4408
def INVEPT : I<0x80, RawFrm, (outs), (ins), "invept", []>, OpSize, T8;
 
4409
// 66 0F 38 81
 
4410
def INVVPID : I<0x81, RawFrm, (outs), (ins), "invvpid", []>, OpSize, T8;
 
4411
// 0F 01 C1
 
4412
def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
 
4413
def VMCLEARm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
 
4414
  "vmclear\t$vmcs", []>, OpSize, TB;
 
4415
// 0F 01 C2
 
4416
def VMLAUNCH : I<0x01, MRM_C2, (outs), (ins), "vmlaunch", []>, TB;
 
4417
// 0F 01 C3
 
4418
def VMRESUME : I<0x01, MRM_C3, (outs), (ins), "vmresume", []>, TB;
 
4419
def VMPTRLDm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
 
4420
  "vmptrld\t$vmcs", []>, TB;
 
4421
def VMPTRSTm : I<0xC7, MRM7m, (outs i64mem:$vmcs), (ins),
 
4422
  "vmptrst\t$vmcs", []>, TB;
 
4423
def VMREAD64rm : I<0x78, MRMDestMem, (outs i64mem:$dst), (ins GR64:$src),
 
4424
  "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
 
4425
def VMREAD64rr : I<0x78, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
 
4426
  "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
 
4427
def VMREAD32rm : I<0x78, MRMDestMem, (outs i32mem:$dst), (ins GR32:$src),
 
4428
  "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4429
def VMREAD32rr : I<0x78, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
 
4430
  "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4431
def VMWRITE64rm : I<0x79, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
 
4432
  "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
 
4433
def VMWRITE64rr : I<0x79, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
 
4434
  "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
 
4435
def VMWRITE32rm : I<0x79, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
 
4436
  "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4437
def VMWRITE32rr : I<0x79, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
 
4438
  "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
 
4439
// 0F 01 C4
 
4440
def VMXOFF : I<0x01, MRM_C4, (outs), (ins), "vmxoff", []>, TB;
 
4441
def VMXON : I<0xC7, MRM6m, (outs), (ins i64mem:$vmxon),
 
4442
  "vmxon\t{$vmxon}", []>, XS;
 
4443
 
 
4444
//===----------------------------------------------------------------------===//
 
4445
// Non-Instruction Patterns
 
4446
//===----------------------------------------------------------------------===//
 
4447
 
 
4448
// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
 
4449
def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
 
4450
def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
 
4451
def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
 
4452
def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
 
4453
def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
 
4454
def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>;
 
4455
 
 
4456
def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
 
4457
          (ADD32ri GR32:$src1, tconstpool:$src2)>;
 
4458
def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
 
4459
          (ADD32ri GR32:$src1, tjumptable:$src2)>;
 
4460
def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
 
4461
          (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
 
4462
def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
 
4463
          (ADD32ri GR32:$src1, texternalsym:$src2)>;
 
4464
def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)),
 
4465
          (ADD32ri GR32:$src1, tblockaddress:$src2)>;
 
4466
 
 
4467
def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
 
4468
          (MOV32mi addr:$dst, tglobaladdr:$src)>;
 
4469
def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
 
4470
          (MOV32mi addr:$dst, texternalsym:$src)>;
 
4471
def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst),
 
4472
          (MOV32mi addr:$dst, tblockaddress:$src)>;
 
4473
 
 
4474
// Calls
 
4475
// tailcall stuff
 
4476
def : Pat<(X86tcret GR32_TC:$dst, imm:$off),
 
4477
          (TCRETURNri GR32_TC:$dst, imm:$off)>,
 
4478
          Requires<[In32BitMode]>;
 
4479
 
 
4480
// FIXME: This is disabled for 32-bit PIC mode because the global base
 
4481
// register which is part of the address mode may be assigned a 
 
4482
// callee-saved register.
 
4483
def : Pat<(X86tcret (load addr:$dst), imm:$off),
 
4484
          (TCRETURNmi addr:$dst, imm:$off)>,
 
4485
          Requires<[In32BitMode, IsNotPIC]>;
 
4486
 
 
4487
def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
 
4488
          (TCRETURNdi texternalsym:$dst, imm:$off)>,
 
4489
          Requires<[In32BitMode]>;
 
4490
 
 
4491
def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
 
4492
          (TCRETURNdi texternalsym:$dst, imm:$off)>,
 
4493
          Requires<[In32BitMode]>;
 
4494
 
 
4495
// Normal calls, with various flavors of addresses.
 
4496
def : Pat<(X86call (i32 tglobaladdr:$dst)),
 
4497
          (CALLpcrel32 tglobaladdr:$dst)>;
 
4498
def : Pat<(X86call (i32 texternalsym:$dst)),
 
4499
          (CALLpcrel32 texternalsym:$dst)>;
 
4500
def : Pat<(X86call (i32 imm:$dst)),
 
4501
          (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
 
4502
 
 
4503
// X86 specific add which produces a flag.
 
4504
def : Pat<(addc GR32:$src1, GR32:$src2),
 
4505
          (ADD32rr GR32:$src1, GR32:$src2)>;
 
4506
def : Pat<(addc GR32:$src1, (load addr:$src2)),
 
4507
          (ADD32rm GR32:$src1, addr:$src2)>;
 
4508
def : Pat<(addc GR32:$src1, imm:$src2),
 
4509
          (ADD32ri GR32:$src1, imm:$src2)>;
 
4510
def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
 
4511
          (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4512
 
 
4513
def : Pat<(subc GR32:$src1, GR32:$src2),
 
4514
          (SUB32rr GR32:$src1, GR32:$src2)>;
 
4515
def : Pat<(subc GR32:$src1, (load addr:$src2)),
 
4516
          (SUB32rm GR32:$src1, addr:$src2)>;
 
4517
def : Pat<(subc GR32:$src1, imm:$src2),
 
4518
          (SUB32ri GR32:$src1, imm:$src2)>;
 
4519
def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
 
4520
          (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4521
 
 
4522
// Comparisons.
 
4523
 
 
4524
// TEST R,R is smaller than CMP R,0
 
4525
def : Pat<(X86cmp GR8:$src1, 0),
 
4526
          (TEST8rr GR8:$src1, GR8:$src1)>;
 
4527
def : Pat<(X86cmp GR16:$src1, 0),
 
4528
          (TEST16rr GR16:$src1, GR16:$src1)>;
 
4529
def : Pat<(X86cmp GR32:$src1, 0),
 
4530
          (TEST32rr GR32:$src1, GR32:$src1)>;
 
4531
 
 
4532
// Conditional moves with folded loads with operands swapped and conditions
 
4533
// inverted.
 
4534
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS),
 
4535
          (CMOVAE16rm GR16:$src2, addr:$src1)>;
 
4536
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS),
 
4537
          (CMOVAE32rm GR32:$src2, addr:$src1)>;
 
4538
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS),
 
4539
          (CMOVB16rm GR16:$src2, addr:$src1)>;
 
4540
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS),
 
4541
          (CMOVB32rm GR32:$src2, addr:$src1)>;
 
4542
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS),
 
4543
          (CMOVNE16rm GR16:$src2, addr:$src1)>;
 
4544
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS),
 
4545
          (CMOVNE32rm GR32:$src2, addr:$src1)>;
 
4546
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS),
 
4547
          (CMOVE16rm GR16:$src2, addr:$src1)>;
 
4548
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS),
 
4549
          (CMOVE32rm GR32:$src2, addr:$src1)>;
 
4550
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS),
 
4551
          (CMOVA16rm GR16:$src2, addr:$src1)>;
 
4552
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS),
 
4553
          (CMOVA32rm GR32:$src2, addr:$src1)>;
 
4554
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS),
 
4555
          (CMOVBE16rm GR16:$src2, addr:$src1)>;
 
4556
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS),
 
4557
          (CMOVBE32rm GR32:$src2, addr:$src1)>;
 
4558
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS),
 
4559
          (CMOVGE16rm GR16:$src2, addr:$src1)>;
 
4560
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS),
 
4561
          (CMOVGE32rm GR32:$src2, addr:$src1)>;
 
4562
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS),
 
4563
          (CMOVL16rm GR16:$src2, addr:$src1)>;
 
4564
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS),
 
4565
          (CMOVL32rm GR32:$src2, addr:$src1)>;
 
4566
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS),
 
4567
          (CMOVG16rm GR16:$src2, addr:$src1)>;
 
4568
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS),
 
4569
          (CMOVG32rm GR32:$src2, addr:$src1)>;
 
4570
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS),
 
4571
          (CMOVLE16rm GR16:$src2, addr:$src1)>;
 
4572
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS),
 
4573
          (CMOVLE32rm GR32:$src2, addr:$src1)>;
 
4574
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS),
 
4575
          (CMOVNP16rm GR16:$src2, addr:$src1)>;
 
4576
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS),
 
4577
          (CMOVNP32rm GR32:$src2, addr:$src1)>;
 
4578
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS),
 
4579
          (CMOVP16rm GR16:$src2, addr:$src1)>;
 
4580
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS),
 
4581
          (CMOVP32rm GR32:$src2, addr:$src1)>;
 
4582
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS),
 
4583
          (CMOVNS16rm GR16:$src2, addr:$src1)>;
 
4584
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS),
 
4585
          (CMOVNS32rm GR32:$src2, addr:$src1)>;
 
4586
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS),
 
4587
          (CMOVS16rm GR16:$src2, addr:$src1)>;
 
4588
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS),
 
4589
          (CMOVS32rm GR32:$src2, addr:$src1)>;
 
4590
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS),
 
4591
          (CMOVNO16rm GR16:$src2, addr:$src1)>;
 
4592
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS),
 
4593
          (CMOVNO32rm GR32:$src2, addr:$src1)>;
 
4594
def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS),
 
4595
          (CMOVO16rm GR16:$src2, addr:$src1)>;
 
4596
def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS),
 
4597
          (CMOVO32rm GR32:$src2, addr:$src1)>;
 
4598
 
 
4599
// zextload bool -> zextload byte
 
4600
def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
 
4601
def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
 
4602
def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
 
4603
 
 
4604
// extload bool -> extload byte
 
4605
def : Pat<(extloadi8i1 addr:$src),   (MOV8rm      addr:$src)>;
 
4606
def : Pat<(extloadi16i1 addr:$src),  (MOVZX16rm8  addr:$src)>;
 
4607
def : Pat<(extloadi32i1 addr:$src),  (MOVZX32rm8  addr:$src)>;
 
4608
def : Pat<(extloadi16i8 addr:$src),  (MOVZX16rm8  addr:$src)>;
 
4609
def : Pat<(extloadi32i8 addr:$src),  (MOVZX32rm8  addr:$src)>;
 
4610
def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
 
4611
 
 
4612
// anyext. Define these to do an explicit zero-extend to
 
4613
// avoid partial-register updates.
 
4614
def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8  GR8 :$src)>;
 
4615
def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8  GR8 :$src)>;
 
4616
 
 
4617
// Except for i16 -> i32 since isel expect i16 ops to be promoted to i32.
 
4618
def : Pat<(i32 (anyext GR16:$src)),
 
4619
          (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR16:$src, sub_16bit)>;
 
4620
 
 
4621
 
 
4622
//===----------------------------------------------------------------------===//
 
4623
// Some peepholes
 
4624
//===----------------------------------------------------------------------===//
 
4625
 
 
4626
// Odd encoding trick: -128 fits into an 8-bit immediate field while
 
4627
// +128 doesn't, so in this special case use a sub instead of an add.
 
4628
def : Pat<(add GR16:$src1, 128),
 
4629
          (SUB16ri8 GR16:$src1, -128)>;
 
4630
def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst),
 
4631
          (SUB16mi8 addr:$dst, -128)>;
 
4632
def : Pat<(add GR32:$src1, 128),
 
4633
          (SUB32ri8 GR32:$src1, -128)>;
 
4634
def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst),
 
4635
          (SUB32mi8 addr:$dst, -128)>;
 
4636
 
 
4637
// r & (2^16-1) ==> movz
 
4638
def : Pat<(and GR32:$src1, 0xffff),
 
4639
          (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, sub_16bit))>;
 
4640
// r & (2^8-1) ==> movz
 
4641
def : Pat<(and GR32:$src1, 0xff),
 
4642
          (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src1, 
 
4643
                                                             GR32_ABCD)),
 
4644
                                      sub_8bit))>,
 
4645
      Requires<[In32BitMode]>;
 
4646
// r & (2^8-1) ==> movz
 
4647
def : Pat<(and GR16:$src1, 0xff),
 
4648
          (MOVZX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src1, 
 
4649
                                                             GR16_ABCD)),
 
4650
                                      sub_8bit))>,
 
4651
      Requires<[In32BitMode]>;
 
4652
 
 
4653
// sext_inreg patterns
 
4654
def : Pat<(sext_inreg GR32:$src, i16),
 
4655
          (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, sub_16bit))>;
 
4656
def : Pat<(sext_inreg GR32:$src, i8),
 
4657
          (MOVSX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
 
4658
                                                             GR32_ABCD)),
 
4659
                                      sub_8bit))>,
 
4660
      Requires<[In32BitMode]>;
 
4661
def : Pat<(sext_inreg GR16:$src, i8),
 
4662
          (MOVSX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
 
4663
                                                             GR16_ABCD)),
 
4664
                                      sub_8bit))>,
 
4665
      Requires<[In32BitMode]>;
 
4666
 
 
4667
// trunc patterns
 
4668
def : Pat<(i16 (trunc GR32:$src)),
 
4669
          (EXTRACT_SUBREG GR32:$src, sub_16bit)>;
 
4670
def : Pat<(i8 (trunc GR32:$src)),
 
4671
          (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
 
4672
                          sub_8bit)>,
 
4673
      Requires<[In32BitMode]>;
 
4674
def : Pat<(i8 (trunc GR16:$src)),
 
4675
          (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
 
4676
                          sub_8bit)>,
 
4677
      Requires<[In32BitMode]>;
 
4678
 
 
4679
// h-register tricks
 
4680
def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))),
 
4681
          (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
 
4682
                          sub_8bit_hi)>,
 
4683
      Requires<[In32BitMode]>;
 
4684
def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))),
 
4685
          (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
 
4686
                          sub_8bit_hi)>,
 
4687
      Requires<[In32BitMode]>;
 
4688
def : Pat<(srl GR16:$src, (i8 8)),
 
4689
          (EXTRACT_SUBREG
 
4690
            (MOVZX32rr8
 
4691
              (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
 
4692
                              sub_8bit_hi)),
 
4693
            sub_16bit)>,
 
4694
      Requires<[In32BitMode]>;
 
4695
def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
 
4696
          (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
 
4697
                                                             GR16_ABCD)),
 
4698
                                      sub_8bit_hi))>,
 
4699
      Requires<[In32BitMode]>;
 
4700
def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
 
4701
          (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
 
4702
                                                             GR16_ABCD)),
 
4703
                                      sub_8bit_hi))>,
 
4704
      Requires<[In32BitMode]>;
 
4705
def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
 
4706
          (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
 
4707
                                                             GR32_ABCD)),
 
4708
                                      sub_8bit_hi))>,
 
4709
      Requires<[In32BitMode]>;
 
4710
def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
 
4711
          (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
 
4712
                                                             GR32_ABCD)),
 
4713
                                      sub_8bit_hi))>,
 
4714
      Requires<[In32BitMode]>;
 
4715
 
 
4716
// (shl x, 1) ==> (add x, x)
 
4717
def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr  GR8 :$src1, GR8 :$src1)>;
 
4718
def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
 
4719
def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
 
4720
 
 
4721
// (shl x (and y, 31)) ==> (shl x, y)
 
4722
def : Pat<(shl GR8:$src1, (and CL, 31)),
 
4723
          (SHL8rCL GR8:$src1)>;
 
4724
def : Pat<(shl GR16:$src1, (and CL, 31)),
 
4725
          (SHL16rCL GR16:$src1)>;
 
4726
def : Pat<(shl GR32:$src1, (and CL, 31)),
 
4727
          (SHL32rCL GR32:$src1)>;
 
4728
def : Pat<(store (shl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
 
4729
          (SHL8mCL addr:$dst)>;
 
4730
def : Pat<(store (shl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
 
4731
          (SHL16mCL addr:$dst)>;
 
4732
def : Pat<(store (shl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
 
4733
          (SHL32mCL addr:$dst)>;
 
4734
 
 
4735
def : Pat<(srl GR8:$src1, (and CL, 31)),
 
4736
          (SHR8rCL GR8:$src1)>;
 
4737
def : Pat<(srl GR16:$src1, (and CL, 31)),
 
4738
          (SHR16rCL GR16:$src1)>;
 
4739
def : Pat<(srl GR32:$src1, (and CL, 31)),
 
4740
          (SHR32rCL GR32:$src1)>;
 
4741
def : Pat<(store (srl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
 
4742
          (SHR8mCL addr:$dst)>;
 
4743
def : Pat<(store (srl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
 
4744
          (SHR16mCL addr:$dst)>;
 
4745
def : Pat<(store (srl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
 
4746
          (SHR32mCL addr:$dst)>;
 
4747
 
 
4748
def : Pat<(sra GR8:$src1, (and CL, 31)),
 
4749
          (SAR8rCL GR8:$src1)>;
 
4750
def : Pat<(sra GR16:$src1, (and CL, 31)),
 
4751
          (SAR16rCL GR16:$src1)>;
 
4752
def : Pat<(sra GR32:$src1, (and CL, 31)),
 
4753
          (SAR32rCL GR32:$src1)>;
 
4754
def : Pat<(store (sra (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
 
4755
          (SAR8mCL addr:$dst)>;
 
4756
def : Pat<(store (sra (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
 
4757
          (SAR16mCL addr:$dst)>;
 
4758
def : Pat<(store (sra (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
 
4759
          (SAR32mCL addr:$dst)>;
 
4760
 
 
4761
// (anyext (setcc_carry)) -> (setcc_carry)
 
4762
def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
 
4763
          (SETB_C16r)>;
 
4764
def : Pat<(i32 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
 
4765
          (SETB_C32r)>;
 
4766
def : Pat<(i32 (anyext (i16 (X86setcc_c X86_COND_B, EFLAGS)))),
 
4767
          (SETB_C32r)>;
 
4768
 
 
4769
// (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
 
4770
let AddedComplexity = 5 in { // Try this before the selecting to OR
 
4771
def : Pat<(or_is_add GR16:$src1, imm:$src2),
 
4772
          (ADD16ri GR16:$src1, imm:$src2)>;
 
4773
def : Pat<(or_is_add GR32:$src1, imm:$src2),
 
4774
          (ADD32ri GR32:$src1, imm:$src2)>;
 
4775
def : Pat<(or_is_add GR16:$src1, i16immSExt8:$src2),
 
4776
          (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4777
def : Pat<(or_is_add GR32:$src1, i32immSExt8:$src2),
 
4778
          (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4779
def : Pat<(or_is_add GR16:$src1, GR16:$src2),
 
4780
          (ADD16rr GR16:$src1, GR16:$src2)>;
 
4781
def : Pat<(or_is_add GR32:$src1, GR32:$src2),
 
4782
          (ADD32rr GR32:$src1, GR32:$src2)>;
 
4783
} // AddedComplexity
 
4784
 
 
4785
//===----------------------------------------------------------------------===//
 
4786
// EFLAGS-defining Patterns
 
4787
//===----------------------------------------------------------------------===//
 
4788
 
 
4789
// add reg, reg
 
4790
def : Pat<(add GR8 :$src1, GR8 :$src2), (ADD8rr  GR8 :$src1, GR8 :$src2)>;
 
4791
def : Pat<(add GR16:$src1, GR16:$src2), (ADD16rr GR16:$src1, GR16:$src2)>;
 
4792
def : Pat<(add GR32:$src1, GR32:$src2), (ADD32rr GR32:$src1, GR32:$src2)>;
 
4793
 
 
4794
// add reg, mem
 
4795
def : Pat<(add GR8:$src1, (loadi8 addr:$src2)),
 
4796
          (ADD8rm GR8:$src1, addr:$src2)>;
 
4797
def : Pat<(add GR16:$src1, (loadi16 addr:$src2)),
 
4798
          (ADD16rm GR16:$src1, addr:$src2)>;
 
4799
def : Pat<(add GR32:$src1, (loadi32 addr:$src2)),
 
4800
          (ADD32rm GR32:$src1, addr:$src2)>;
 
4801
 
 
4802
// add reg, imm
 
4803
def : Pat<(add GR8 :$src1, imm:$src2), (ADD8ri  GR8:$src1 , imm:$src2)>;
 
4804
def : Pat<(add GR16:$src1, imm:$src2), (ADD16ri GR16:$src1, imm:$src2)>;
 
4805
def : Pat<(add GR32:$src1, imm:$src2), (ADD32ri GR32:$src1, imm:$src2)>;
 
4806
def : Pat<(add GR16:$src1, i16immSExt8:$src2),
 
4807
          (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4808
def : Pat<(add GR32:$src1, i32immSExt8:$src2),
 
4809
          (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4810
 
 
4811
// sub reg, reg
 
4812
def : Pat<(sub GR8 :$src1, GR8 :$src2), (SUB8rr  GR8 :$src1, GR8 :$src2)>;
 
4813
def : Pat<(sub GR16:$src1, GR16:$src2), (SUB16rr GR16:$src1, GR16:$src2)>;
 
4814
def : Pat<(sub GR32:$src1, GR32:$src2), (SUB32rr GR32:$src1, GR32:$src2)>;
 
4815
 
 
4816
// sub reg, mem
 
4817
def : Pat<(sub GR8:$src1, (loadi8 addr:$src2)),
 
4818
          (SUB8rm GR8:$src1, addr:$src2)>;
 
4819
def : Pat<(sub GR16:$src1, (loadi16 addr:$src2)),
 
4820
          (SUB16rm GR16:$src1, addr:$src2)>;
 
4821
def : Pat<(sub GR32:$src1, (loadi32 addr:$src2)),
 
4822
          (SUB32rm GR32:$src1, addr:$src2)>;
 
4823
 
 
4824
// sub reg, imm
 
4825
def : Pat<(sub GR8:$src1, imm:$src2),
 
4826
          (SUB8ri GR8:$src1, imm:$src2)>;
 
4827
def : Pat<(sub GR16:$src1, imm:$src2),
 
4828
          (SUB16ri GR16:$src1, imm:$src2)>;
 
4829
def : Pat<(sub GR32:$src1, imm:$src2),
 
4830
          (SUB32ri GR32:$src1, imm:$src2)>;
 
4831
def : Pat<(sub GR16:$src1, i16immSExt8:$src2),
 
4832
          (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4833
def : Pat<(sub GR32:$src1, i32immSExt8:$src2),
 
4834
          (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4835
 
 
4836
// mul reg, reg
 
4837
def : Pat<(mul GR16:$src1, GR16:$src2),
 
4838
          (IMUL16rr GR16:$src1, GR16:$src2)>;
 
4839
def : Pat<(mul GR32:$src1, GR32:$src2),
 
4840
          (IMUL32rr GR32:$src1, GR32:$src2)>;
 
4841
 
 
4842
// mul reg, mem
 
4843
def : Pat<(mul GR16:$src1, (loadi16 addr:$src2)),
 
4844
          (IMUL16rm GR16:$src1, addr:$src2)>;
 
4845
def : Pat<(mul GR32:$src1, (loadi32 addr:$src2)),
 
4846
          (IMUL32rm GR32:$src1, addr:$src2)>;
 
4847
 
 
4848
// mul reg, imm
 
4849
def : Pat<(mul GR16:$src1, imm:$src2),
 
4850
          (IMUL16rri GR16:$src1, imm:$src2)>;
 
4851
def : Pat<(mul GR32:$src1, imm:$src2),
 
4852
          (IMUL32rri GR32:$src1, imm:$src2)>;
 
4853
def : Pat<(mul GR16:$src1, i16immSExt8:$src2),
 
4854
          (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>;
 
4855
def : Pat<(mul GR32:$src1, i32immSExt8:$src2),
 
4856
          (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>;
 
4857
 
 
4858
// reg = mul mem, imm
 
4859
def : Pat<(mul (loadi16 addr:$src1), imm:$src2),
 
4860
          (IMUL16rmi addr:$src1, imm:$src2)>;
 
4861
def : Pat<(mul (loadi32 addr:$src1), imm:$src2),
 
4862
          (IMUL32rmi addr:$src1, imm:$src2)>;
 
4863
def : Pat<(mul (loadi16 addr:$src1), i16immSExt8:$src2),
 
4864
          (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>;
 
4865
def : Pat<(mul (loadi32 addr:$src1), i32immSExt8:$src2),
 
4866
          (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>;
 
4867
 
 
4868
// Optimize multiply by 2 with EFLAGS result.
 
4869
let AddedComplexity = 2 in {
 
4870
def : Pat<(X86smul_flag GR16:$src1, 2), (ADD16rr GR16:$src1, GR16:$src1)>;
 
4871
def : Pat<(X86smul_flag GR32:$src1, 2), (ADD32rr GR32:$src1, GR32:$src1)>;
 
4872
}
 
4873
 
 
4874
// Patterns for nodes that do not produce flags, for instructions that do.
 
4875
 
 
4876
// Increment reg.
 
4877
def : Pat<(add GR8:$src1 ,  1), (INC8r  GR8:$src1)>;
 
4878
def : Pat<(add GR16:$src1,  1), (INC16r GR16:$src1)>, Requires<[In32BitMode]>;
 
4879
def : Pat<(add GR32:$src1,  1), (INC32r GR32:$src1)>, Requires<[In32BitMode]>;
 
4880
 
 
4881
// Decrement reg.
 
4882
def : Pat<(add GR8:$src1 , -1), (DEC8r  GR8:$src1)>;
 
4883
def : Pat<(add GR16:$src1, -1), (DEC16r GR16:$src1)>, Requires<[In32BitMode]>;
 
4884
def : Pat<(add GR32:$src1, -1), (DEC32r GR32:$src1)>, Requires<[In32BitMode]>;
 
4885
 
 
4886
// or reg/reg.
 
4887
def : Pat<(or GR8 :$src1, GR8 :$src2), (OR8rr  GR8 :$src1, GR8 :$src2)>;
 
4888
def : Pat<(or GR16:$src1, GR16:$src2), (OR16rr GR16:$src1, GR16:$src2)>;
 
4889
def : Pat<(or GR32:$src1, GR32:$src2), (OR32rr GR32:$src1, GR32:$src2)>;
 
4890
 
 
4891
// or reg/mem
 
4892
def : Pat<(or GR8:$src1, (loadi8 addr:$src2)),
 
4893
          (OR8rm GR8:$src1, addr:$src2)>;
 
4894
def : Pat<(or GR16:$src1, (loadi16 addr:$src2)),
 
4895
          (OR16rm GR16:$src1, addr:$src2)>;
 
4896
def : Pat<(or GR32:$src1, (loadi32 addr:$src2)),
 
4897
          (OR32rm GR32:$src1, addr:$src2)>;
 
4898
 
 
4899
// or reg/imm
 
4900
def : Pat<(or GR8:$src1 , imm:$src2), (OR8ri  GR8 :$src1, imm:$src2)>;
 
4901
def : Pat<(or GR16:$src1, imm:$src2), (OR16ri GR16:$src1, imm:$src2)>;
 
4902
def : Pat<(or GR32:$src1, imm:$src2), (OR32ri GR32:$src1, imm:$src2)>;
 
4903
def : Pat<(or GR16:$src1, i16immSExt8:$src2),
 
4904
          (OR16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4905
def : Pat<(or GR32:$src1, i32immSExt8:$src2),
 
4906
          (OR32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4907
 
 
4908
// xor reg/reg
 
4909
def : Pat<(xor GR8 :$src1, GR8 :$src2), (XOR8rr  GR8 :$src1, GR8 :$src2)>;
 
4910
def : Pat<(xor GR16:$src1, GR16:$src2), (XOR16rr GR16:$src1, GR16:$src2)>;
 
4911
def : Pat<(xor GR32:$src1, GR32:$src2), (XOR32rr GR32:$src1, GR32:$src2)>;
 
4912
 
 
4913
// xor reg/mem
 
4914
def : Pat<(xor GR8:$src1, (loadi8 addr:$src2)),
 
4915
          (XOR8rm GR8:$src1, addr:$src2)>;
 
4916
def : Pat<(xor GR16:$src1, (loadi16 addr:$src2)),
 
4917
          (XOR16rm GR16:$src1, addr:$src2)>;
 
4918
def : Pat<(xor GR32:$src1, (loadi32 addr:$src2)),
 
4919
          (XOR32rm GR32:$src1, addr:$src2)>;
 
4920
 
 
4921
// xor reg/imm
 
4922
def : Pat<(xor GR8:$src1, imm:$src2),
 
4923
          (XOR8ri GR8:$src1, imm:$src2)>;
 
4924
def : Pat<(xor GR16:$src1, imm:$src2),
 
4925
          (XOR16ri GR16:$src1, imm:$src2)>;
 
4926
def : Pat<(xor GR32:$src1, imm:$src2),
 
4927
          (XOR32ri GR32:$src1, imm:$src2)>;
 
4928
def : Pat<(xor GR16:$src1, i16immSExt8:$src2),
 
4929
          (XOR16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4930
def : Pat<(xor GR32:$src1, i32immSExt8:$src2),
 
4931
          (XOR32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4932
 
 
4933
// and reg/reg
 
4934
def : Pat<(and GR8 :$src1, GR8 :$src2), (AND8rr  GR8 :$src1, GR8 :$src2)>;
 
4935
def : Pat<(and GR16:$src1, GR16:$src2), (AND16rr GR16:$src1, GR16:$src2)>;
 
4936
def : Pat<(and GR32:$src1, GR32:$src2), (AND32rr GR32:$src1, GR32:$src2)>;
 
4937
 
 
4938
// and reg/mem
 
4939
def : Pat<(and GR8:$src1, (loadi8 addr:$src2)),
 
4940
          (AND8rm GR8:$src1, addr:$src2)>;
 
4941
def : Pat<(and GR16:$src1, (loadi16 addr:$src2)),
 
4942
          (AND16rm GR16:$src1, addr:$src2)>;
 
4943
def : Pat<(and GR32:$src1, (loadi32 addr:$src2)),
 
4944
          (AND32rm GR32:$src1, addr:$src2)>;
 
4945
 
 
4946
// and reg/imm
 
4947
def : Pat<(and GR8:$src1, imm:$src2),
 
4948
          (AND8ri GR8:$src1, imm:$src2)>;
 
4949
def : Pat<(and GR16:$src1, imm:$src2),
 
4950
          (AND16ri GR16:$src1, imm:$src2)>;
 
4951
def : Pat<(and GR32:$src1, imm:$src2),
 
4952
          (AND32ri GR32:$src1, imm:$src2)>;
 
4953
def : Pat<(and GR16:$src1, i16immSExt8:$src2),
 
4954
          (AND16ri8 GR16:$src1, i16immSExt8:$src2)>;
 
4955
def : Pat<(and GR32:$src1, i32immSExt8:$src2),
 
4956
          (AND32ri8 GR32:$src1, i32immSExt8:$src2)>;
 
4957
 
 
4958
//===----------------------------------------------------------------------===//
 
4959
// Floating Point Stack Support
 
4960
//===----------------------------------------------------------------------===//
 
4961
 
 
4962
include "X86InstrFPStack.td"
 
4963
 
 
4964
//===----------------------------------------------------------------------===//
 
4965
// X86-64 Support
 
4966
//===----------------------------------------------------------------------===//
 
4967
 
 
4968
include "X86Instr64bit.td"
 
4969
 
 
4970
//===----------------------------------------------------------------------===//
 
4971
// SIMD support (SSE, MMX and AVX)
 
4972
//===----------------------------------------------------------------------===//
 
4973
 
 
4974
include "X86InstrFragmentsSIMD.td"
 
4975
 
 
4976
//===----------------------------------------------------------------------===//
 
4977
// FMA - Fused Multiply-Add support (requires FMA)
 
4978
//===----------------------------------------------------------------------===//
 
4979
 
 
4980
include "X86InstrFMA.td"
 
4981
 
 
4982
//===----------------------------------------------------------------------===//
 
4983
// XMM Floating point support (requires SSE / SSE2)
 
4984
//===----------------------------------------------------------------------===//
 
4985
 
 
4986
include "X86InstrSSE.td"
 
4987
 
 
4988
//===----------------------------------------------------------------------===//
 
4989
// MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
 
4990
//===----------------------------------------------------------------------===//
 
4991
 
 
4992
include "X86InstrMMX.td"