1 //===- X86InstrArithmetic.td - Integer Arithmetic Instrs ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the integer arithmetic instructions in the X86
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // LEA - Load Effective Address
18 let neverHasSideEffects = 1 in
19 def LEA16r : I<0x8D, MRMSrcMem,
20 (outs GR16:$dst), (ins i32mem:$src),
21 "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
22 let isReMaterializable = 1 in
23 def LEA32r : I<0x8D, MRMSrcMem,
24 (outs GR32:$dst), (ins i32mem:$src),
25 "lea{l}\t{$src|$dst}, {$dst|$src}",
26 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
28 def LEA64_32r : I<0x8D, MRMSrcMem,
29 (outs GR32:$dst), (ins lea64_32mem:$src),
30 "lea{l}\t{$src|$dst}, {$dst|$src}",
31 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
33 let isReMaterializable = 1 in
34 def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
35 "lea{q}\t{$src|$dst}, {$dst|$src}",
36 [(set GR64:$dst, lea64addr:$src)]>;
40 //===----------------------------------------------------------------------===//
41 // Fixed-Register Multiplication and Division Instructions.
44 // Extra precision multiplication
46 // AL is really implied by AX, but the registers in Defs must match the
47 // SDNode results (i8, i32).
48 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
49 def MUL8r : I<0xF6, MRM4r, (outs), (ins GR8:$src), "mul{b}\t$src",
50 // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
51 // This probably ought to be moved to a def : Pat<> if the
52 // syntax can be accepted.
53 [(set AL, (mul AL, GR8:$src)),
54 (implicit EFLAGS)]>; // AL,AH = AL*GR8
56 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
57 def MUL16r : I<0xF7, MRM4r, (outs), (ins GR16:$src),
59 []>, OpSize; // AX,DX = AX*GR16
61 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
62 def MUL32r : I<0xF7, MRM4r, (outs), (ins GR32:$src),
64 []>; // EAX,EDX = EAX*GR32
65 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in
66 def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
67 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
69 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
70 def MUL8m : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
72 // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
73 // This probably ought to be moved to a def : Pat<> if the
74 // syntax can be accepted.
75 [(set AL, (mul AL, (loadi8 addr:$src))),
76 (implicit EFLAGS)]>; // AL,AH = AL*[mem8]
78 let mayLoad = 1, neverHasSideEffects = 1 in {
79 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
80 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
82 []>, OpSize; // AX,DX = AX*[mem16]
84 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
85 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
87 []>; // EAX,EDX = EAX*[mem32]
88 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in
89 def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
90 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
93 let neverHasSideEffects = 1 in {
94 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
95 def IMUL8r : I<0xF6, MRM5r, (outs), (ins GR8:$src), "imul{b}\t$src", []>;
97 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
98 def IMUL16r : I<0xF7, MRM5r, (outs), (ins GR16:$src), "imul{w}\t$src", []>,
99 OpSize; // AX,DX = AX*GR16
100 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
101 def IMUL32r : I<0xF7, MRM5r, (outs), (ins GR32:$src), "imul{l}\t$src", []>;
102 // EAX,EDX = EAX*GR32
103 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in
104 def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src), "imul{q}\t$src", []>;
105 // RAX,RDX = RAX*GR64
108 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
109 def IMUL8m : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
110 "imul{b}\t$src", []>; // AL,AH = AL*[mem8]
111 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
112 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
113 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
114 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
115 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
116 "imul{l}\t$src", []>; // EAX,EDX = EAX*[mem32]
117 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in
118 def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
119 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
121 } // neverHasSideEffects
124 let Defs = [EFLAGS] in {
125 let Constraints = "$src1 = $dst" in {
127 let isCommutable = 1 in { // X = IMUL Y, Z --> X = IMUL Z, Y
128 // Register-Register Signed Integer Multiply
129 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
130 "imul{w}\t{$src2, $dst|$dst, $src2}",
131 [(set GR16:$dst, EFLAGS,
132 (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
133 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
134 "imul{l}\t{$src2, $dst|$dst, $src2}",
135 [(set GR32:$dst, EFLAGS,
136 (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
137 def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
138 (ins GR64:$src1, GR64:$src2),
139 "imul{q}\t{$src2, $dst|$dst, $src2}",
140 [(set GR64:$dst, EFLAGS,
141 (X86smul_flag GR64:$src1, GR64:$src2))]>, TB;
144 // Register-Memory Signed Integer Multiply
145 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
146 (ins GR16:$src1, i16mem:$src2),
147 "imul{w}\t{$src2, $dst|$dst, $src2}",
148 [(set GR16:$dst, EFLAGS,
149 (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
151 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst),
152 (ins GR32:$src1, i32mem:$src2),
153 "imul{l}\t{$src2, $dst|$dst, $src2}",
154 [(set GR32:$dst, EFLAGS,
155 (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
156 def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
157 (ins GR64:$src1, i64mem:$src2),
158 "imul{q}\t{$src2, $dst|$dst, $src2}",
159 [(set GR64:$dst, EFLAGS,
160 (X86smul_flag GR64:$src1, (load addr:$src2)))]>, TB;
161 } // Constraints = "$src1 = $dst"
165 // Suprisingly enough, these are not two address instructions!
166 let Defs = [EFLAGS] in {
167 // Register-Integer Signed Integer Multiply
168 def IMUL16rri : Ii16<0x69, MRMSrcReg, // GR16 = GR16*I16
169 (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
170 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
171 [(set GR16:$dst, EFLAGS,
172 (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
173 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg, // GR16 = GR16*I8
174 (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
175 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
176 [(set GR16:$dst, EFLAGS,
177 (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
179 def IMUL32rri : Ii32<0x69, MRMSrcReg, // GR32 = GR32*I32
180 (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
181 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
182 [(set GR32:$dst, EFLAGS,
183 (X86smul_flag GR32:$src1, imm:$src2))]>;
184 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg, // GR32 = GR32*I8
185 (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
186 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
187 [(set GR32:$dst, EFLAGS,
188 (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
189 def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
190 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
191 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
192 [(set GR64:$dst, EFLAGS,
193 (X86smul_flag GR64:$src1, i64immSExt32:$src2))]>;
194 def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
195 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
196 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
197 [(set GR64:$dst, EFLAGS,
198 (X86smul_flag GR64:$src1, i64immSExt8:$src2))]>;
201 // Memory-Integer Signed Integer Multiply
202 def IMUL16rmi : Ii16<0x69, MRMSrcMem, // GR16 = [mem16]*I16
203 (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
204 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
205 [(set GR16:$dst, EFLAGS,
206 (X86smul_flag (load addr:$src1), imm:$src2))]>,
208 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem, // GR16 = [mem16]*I8
209 (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
210 "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
211 [(set GR16:$dst, EFLAGS,
212 (X86smul_flag (load addr:$src1),
213 i16immSExt8:$src2))]>, OpSize;
214 def IMUL32rmi : Ii32<0x69, MRMSrcMem, // GR32 = [mem32]*I32
215 (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
216 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
217 [(set GR32:$dst, EFLAGS,
218 (X86smul_flag (load addr:$src1), imm:$src2))]>;
219 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem, // GR32 = [mem32]*I8
220 (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
221 "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
222 [(set GR32:$dst, EFLAGS,
223 (X86smul_flag (load addr:$src1),
224 i32immSExt8:$src2))]>;
225 def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
226 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
227 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
228 [(set GR64:$dst, EFLAGS,
229 (X86smul_flag (load addr:$src1),
230 i64immSExt32:$src2))]>;
231 def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
232 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
233 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
234 [(set GR64:$dst, EFLAGS,
235 (X86smul_flag (load addr:$src1),
236 i64immSExt8:$src2))]>;
242 // unsigned division/remainder
243 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
244 def DIV8r : I<0xF6, MRM6r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
246 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
247 def DIV16r : I<0xF7, MRM6r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
248 "div{w}\t$src", []>, OpSize;
249 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
250 def DIV32r : I<0xF7, MRM6r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
252 // RDX:RAX/r64 = RAX,RDX
253 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
254 def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src),
258 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
259 def DIV8m : I<0xF6, MRM6m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
261 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
262 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
263 "div{w}\t$src", []>, OpSize;
264 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in // EDX:EAX/[mem32] = EAX,EDX
265 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
267 // RDX:RAX/[mem64] = RAX,RDX
268 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
269 def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src),
273 // Signed division/remainder.
274 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
275 def IDIV8r : I<0xF6, MRM7r, (outs), (ins GR8:$src), // AX/r8 = AL,AH
276 "idiv{b}\t$src", []>;
277 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
278 def IDIV16r: I<0xF7, MRM7r, (outs), (ins GR16:$src), // DX:AX/r16 = AX,DX
279 "idiv{w}\t$src", []>, OpSize;
280 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
281 def IDIV32r: I<0xF7, MRM7r, (outs), (ins GR32:$src), // EDX:EAX/r32 = EAX,EDX
282 "idiv{l}\t$src", []>;
283 // RDX:RAX/r64 = RAX,RDX
284 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in
285 def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src),
286 "idiv{q}\t$src", []>;
288 let mayLoad = 1, mayLoad = 1 in {
289 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
290 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src), // AX/[mem8] = AL,AH
291 "idiv{b}\t$src", []>;
292 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
293 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src), // DX:AX/[mem16] = AX,DX
294 "idiv{w}\t$src", []>, OpSize;
295 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in // EDX:EAX/[mem32] = EAX,EDX
296 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src),
297 "idiv{l}\t$src", []>;
298 let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in // RDX:RAX/[mem64] = RAX,RDX
299 def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src),
300 "idiv{q}\t$src", []>;
303 //===----------------------------------------------------------------------===//
304 // Two address Instructions.
307 // unary instructions
308 let CodeSize = 2 in {
309 let Defs = [EFLAGS] in {
310 let Constraints = "$src1 = $dst" in {
311 def NEG8r : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
313 [(set GR8:$dst, (ineg GR8:$src1)),
315 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
317 [(set GR16:$dst, (ineg GR16:$src1)),
318 (implicit EFLAGS)]>, OpSize;
319 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
321 [(set GR32:$dst, (ineg GR32:$src1)),
323 def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src1), "neg{q}\t$dst",
324 [(set GR64:$dst, (ineg GR64:$src1)),
326 } // Constraints = "$src1 = $dst"
328 def NEG8m : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
330 [(store (ineg (loadi8 addr:$dst)), addr:$dst),
332 def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
334 [(store (ineg (loadi16 addr:$dst)), addr:$dst),
335 (implicit EFLAGS)]>, OpSize;
336 def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
338 [(store (ineg (loadi32 addr:$dst)), addr:$dst),
340 def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
341 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
346 // Note: NOT does not set EFLAGS!
348 let Constraints = "$src1 = $dst" in {
349 // Match xor -1 to not. Favors these over a move imm + xor to save code size.
350 let AddedComplexity = 15 in {
351 def NOT8r : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
353 [(set GR8:$dst, (not GR8:$src1))]>;
354 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
356 [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
357 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
359 [(set GR32:$dst, (not GR32:$src1))]>;
360 def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src1), "not{q}\t$dst",
361 [(set GR64:$dst, (not GR64:$src1))]>;
363 } // Constraints = "$src1 = $dst"
365 def NOT8m : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
367 [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
368 def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
370 [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
371 def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
373 [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
374 def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
375 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
378 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
379 let Defs = [EFLAGS] in {
380 let Constraints = "$src1 = $dst" in {
382 def INC8r : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
384 [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
386 let isConvertibleToThreeAddress = 1, CodeSize = 1 in { // Can xform into LEA.
387 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1),
389 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
390 OpSize, Requires<[In32BitMode]>;
391 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1),
393 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
394 Requires<[In32BitMode]>;
395 def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src1), "inc{q}\t$dst",
396 [(set GR64:$dst, EFLAGS, (X86inc_flag GR64:$src1))]>;
397 } // isConvertibleToThreeAddress = 1, CodeSize = 1
400 // In 64-bit mode, single byte INC and DEC cannot be encoded.
401 let isConvertibleToThreeAddress = 1, CodeSize = 2 in {
402 // Can transform into LEA.
403 def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
405 [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
406 OpSize, Requires<[In64BitMode]>;
407 def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
409 [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
410 Requires<[In64BitMode]>;
411 def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
413 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
414 OpSize, Requires<[In64BitMode]>;
415 def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
417 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
418 Requires<[In64BitMode]>;
419 } // isConvertibleToThreeAddress = 1, CodeSize = 2
421 } // Constraints = "$src1 = $dst"
423 let CodeSize = 2 in {
424 def INC8m : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
425 [(store (add (loadi8 addr:$dst), 1), addr:$dst),
427 def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
428 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
430 OpSize, Requires<[In32BitMode]>;
431 def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
432 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
434 Requires<[In32BitMode]>;
435 def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
436 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
439 // These are duplicates of their 32-bit counterparts. Only needed so X86 knows
440 // how to unfold them.
441 // FIXME: What is this for??
442 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
443 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
445 OpSize, Requires<[In64BitMode]>;
446 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
447 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
449 Requires<[In64BitMode]>;
450 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
451 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
453 OpSize, Requires<[In64BitMode]>;
454 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
455 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
457 Requires<[In64BitMode]>;
460 let Constraints = "$src1 = $dst" in {
462 def DEC8r : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
464 [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
465 let isConvertibleToThreeAddress = 1, CodeSize = 1 in { // Can xform into LEA.
466 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1),
468 [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
469 OpSize, Requires<[In32BitMode]>;
470 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1),
472 [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
473 Requires<[In32BitMode]>;
474 def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src1), "dec{q}\t$dst",
475 [(set GR64:$dst, EFLAGS, (X86dec_flag GR64:$src1))]>;
477 } // Constraints = "$src1 = $dst"
480 let CodeSize = 2 in {
481 def DEC8m : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
482 [(store (add (loadi8 addr:$dst), -1), addr:$dst),
484 def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
485 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
487 OpSize, Requires<[In32BitMode]>;
488 def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
489 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
491 Requires<[In32BitMode]>;
492 def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
493 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
499 /// X86TypeInfo - This is a bunch of information that describes relevant X86
500 /// information about value types. For example, it can tell you what the
501 /// register class and preferred load to use.
502 class X86TypeInfo<ValueType vt, string instrsuffix, RegisterClass regclass,
503 PatFrag loadnode, X86MemOperand memoperand, ImmType immkind,
504 Operand immoperand, SDPatternOperator immoperator,
505 Operand imm8operand, SDPatternOperator imm8operator,
506 bit hasOddOpcode, bit hasOpSizePrefix, bit hasREX_WPrefix> {
507 /// VT - This is the value type itself.
510 /// InstrSuffix - This is the suffix used on instructions with this type. For
511 /// example, i8 -> "b", i16 -> "w", i32 -> "l", i64 -> "q".
512 string InstrSuffix = instrsuffix;
514 /// RegClass - This is the register class associated with this type. For
515 /// example, i8 -> GR8, i16 -> GR16, i32 -> GR32, i64 -> GR64.
516 RegisterClass RegClass = regclass;
518 /// LoadNode - This is the load node associated with this type. For
519 /// example, i8 -> loadi8, i16 -> loadi16, i32 -> loadi32, i64 -> loadi64.
520 PatFrag LoadNode = loadnode;
522 /// MemOperand - This is the memory operand associated with this type. For
523 /// example, i8 -> i8mem, i16 -> i16mem, i32 -> i32mem, i64 -> i64mem.
524 X86MemOperand MemOperand = memoperand;
526 /// ImmEncoding - This is the encoding of an immediate of this type. For
527 /// example, i8 -> Imm8, i16 -> Imm16, i32 -> Imm32. Note that i64 -> Imm32
528 /// since the immediate fields of i64 instructions is a 32-bit sign extended
530 ImmType ImmEncoding = immkind;
532 /// ImmOperand - This is the operand kind of an immediate of this type. For
533 /// example, i8 -> i8imm, i16 -> i16imm, i32 -> i32imm. Note that i64 ->
534 /// i64i32imm since the immediate fields of i64 instructions is a 32-bit sign
536 Operand ImmOperand = immoperand;
538 /// ImmOperator - This is the operator that should be used to match an
539 /// immediate of this kind in a pattern (e.g. imm, or i64immSExt32).
540 SDPatternOperator ImmOperator = immoperator;
542 /// Imm8Operand - This is the operand kind to use for an imm8 of this type.
543 /// For example, i8 -> <invalid>, i16 -> i16i8imm, i32 -> i32i8imm. This is
544 /// only used for instructions that have a sign-extended imm8 field form.
545 Operand Imm8Operand = imm8operand;
547 /// Imm8Operator - This is the operator that should be used to match an 8-bit
548 /// sign extended immediate of this kind in a pattern (e.g. imm16immSExt8).
549 SDPatternOperator Imm8Operator = imm8operator;
551 /// HasOddOpcode - This bit is true if the instruction should have an odd (as
552 /// opposed to even) opcode. Operations on i8 are usually even, operations on
553 /// other datatypes are odd.
554 bit HasOddOpcode = hasOddOpcode;
556 /// HasOpSizePrefix - This bit is set to true if the instruction should have
557 /// the 0x66 operand size prefix. This is set for i16 types.
558 bit HasOpSizePrefix = hasOpSizePrefix;
560 /// HasREX_WPrefix - This bit is set to true if the instruction should have
561 /// the 0x40 REX prefix. This is set for i64 types.
562 bit HasREX_WPrefix = hasREX_WPrefix;
565 def invalid_node : SDNode<"<<invalid_node>>", SDTIntLeaf,[],"<<invalid_node>>">;
568 def Xi8 : X86TypeInfo<i8 , "b", GR8 , loadi8 , i8mem ,
569 Imm8 , i8imm , imm, i8imm , invalid_node,
571 def Xi16 : X86TypeInfo<i16, "w", GR16, loadi16, i16mem,
572 Imm16, i16imm, imm, i16i8imm, i16immSExt8,
574 def Xi32 : X86TypeInfo<i32, "l", GR32, loadi32, i32mem,
575 Imm32, i32imm, imm, i32i8imm, i32immSExt8,
577 def Xi64 : X86TypeInfo<i64, "q", GR64, loadi64, i64mem,
578 Imm32, i64i32imm, i64immSExt32, i64i8imm, i64immSExt8,
581 /// ITy - This instruction base class takes the type info for the instruction.
583 /// 1. Concatenates together the instruction mnemonic with the appropriate
584 /// suffix letter, a tab, and the arguments.
585 /// 2. Infers whether the instruction should have a 0x66 prefix byte.
586 /// 3. Infers whether the instruction should have a 0x40 REX_W prefix.
587 /// 4. Infers whether the low bit of the opcode should be 0 (for i8 operations)
588 /// or 1 (for i16,i32,i64 operations).
589 class ITy<bits<8> opcode, Format f, X86TypeInfo typeinfo, dag outs, dag ins,
590 string mnemonic, string args, list<dag> pattern>
591 : I<{opcode{7}, opcode{6}, opcode{5}, opcode{4},
592 opcode{3}, opcode{2}, opcode{1}, typeinfo.HasOddOpcode },
594 !strconcat(mnemonic, "{", typeinfo.InstrSuffix, "}\t", args), pattern> {
596 // Infer instruction prefixes from type info.
597 let hasOpSizePrefix = typeinfo.HasOpSizePrefix;
598 let hasREX_WPrefix = typeinfo.HasREX_WPrefix;
601 // BinOpRR - Instructions like "add reg, reg, reg".
602 class BinOpRR<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
603 dag outlist, list<dag> pattern, Format f = MRMDestReg>
604 : ITy<opcode, f, typeinfo, outlist,
605 (ins typeinfo.RegClass:$src1, typeinfo.RegClass:$src2),
606 mnemonic, "{$src2, $src1|$src1, $src2}", pattern>;
608 // BinOpRR_R - Instructions like "add reg, reg, reg", where the pattern has
609 // just a regclass (no eflags) as a result.
610 class BinOpRR_R<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
612 : BinOpRR<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst),
613 [(set typeinfo.RegClass:$dst,
614 (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2))]>;
616 // BinOpRR_F - Instructions like "cmp reg, Reg", where the pattern has
617 // just a EFLAGS as a result.
618 class BinOpRR_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
619 SDPatternOperator opnode, Format f = MRMDestReg>
620 : BinOpRR<opcode, mnemonic, typeinfo, (outs),
622 (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2))],
625 // BinOpRR_RF - Instructions like "add reg, reg, reg", where the pattern has
626 // both a regclass and EFLAGS as a result.
627 class BinOpRR_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
629 : BinOpRR<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst),
630 [(set typeinfo.RegClass:$dst, EFLAGS,
631 (opnode typeinfo.RegClass:$src1, typeinfo.RegClass:$src2))]>;
633 // BinOpRR_Rev - Instructions like "add reg, reg, reg" (reversed encoding).
634 class BinOpRR_Rev<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo>
635 : ITy<opcode, MRMSrcReg, typeinfo,
636 (outs typeinfo.RegClass:$dst),
637 (ins typeinfo.RegClass:$src1, typeinfo.RegClass:$src2),
638 mnemonic, "{$src2, $dst|$dst, $src2}", []> {
639 // The disassembler should know about this, but not the asmparser.
640 let isCodeGenOnly = 1;
643 // BinOpRM - Instructions like "add reg, reg, [mem]".
644 class BinOpRM<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
645 dag outlist, list<dag> pattern>
646 : ITy<opcode, MRMSrcMem, typeinfo, outlist,
647 (ins typeinfo.RegClass:$src1, typeinfo.MemOperand:$src2),
648 mnemonic, "{$src2, $src1|$src1, $src2}", pattern>;
650 // BinOpRM_R - Instructions like "add reg, reg, [mem]".
651 class BinOpRM_R<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
653 : BinOpRM<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst),
654 [(set typeinfo.RegClass:$dst,
655 (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2)))]>;
657 // BinOpRM_F - Instructions like "cmp reg, [mem]".
658 class BinOpRM_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
659 SDPatternOperator opnode>
660 : BinOpRM<opcode, mnemonic, typeinfo, (outs),
662 (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2)))]>;
664 // BinOpRM_RF - Instructions like "add reg, reg, [mem]".
665 class BinOpRM_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
667 : BinOpRM<opcode, mnemonic, typeinfo, (outs typeinfo.RegClass:$dst),
668 [(set typeinfo.RegClass:$dst, EFLAGS,
669 (opnode typeinfo.RegClass:$src1, (typeinfo.LoadNode addr:$src2)))]>;
671 // BinOpRI - Instructions like "add reg, reg, imm".
672 class BinOpRI<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
673 Format f, dag outlist, list<dag> pattern>
674 : ITy<opcode, f, typeinfo, outlist,
675 (ins typeinfo.RegClass:$src1, typeinfo.ImmOperand:$src2),
676 mnemonic, "{$src2, $src1|$src1, $src2}", pattern> {
677 let ImmT = typeinfo.ImmEncoding;
680 // BinOpRI_R - Instructions like "add reg, reg, imm".
681 class BinOpRI_R<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
682 SDNode opnode, Format f>
683 : BinOpRI<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst),
684 [(set typeinfo.RegClass:$dst,
685 (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2))]>;
687 // BinOpRI_F - Instructions like "cmp reg, imm".
688 class BinOpRI_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
689 SDPatternOperator opnode, Format f>
690 : BinOpRI<opcode, mnemonic, typeinfo, f, (outs),
692 (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2))]>;
694 // BinOpRI_RF - Instructions like "add reg, reg, imm".
695 class BinOpRI_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
696 SDNode opnode, Format f>
697 : BinOpRI<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst),
698 [(set typeinfo.RegClass:$dst, EFLAGS,
699 (opnode typeinfo.RegClass:$src1, typeinfo.ImmOperator:$src2))]>;
701 // BinOpRI8 - Instructions like "add reg, reg, imm8".
702 class BinOpRI8<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
703 Format f, dag outlist, list<dag> pattern>
704 : ITy<opcode, f, typeinfo, outlist,
705 (ins typeinfo.RegClass:$src1, typeinfo.Imm8Operand:$src2),
706 mnemonic, "{$src2, $src1|$src1, $src2}", pattern> {
707 let ImmT = Imm8; // Always 8-bit immediate.
710 // BinOpRI8_R - Instructions like "add reg, reg, imm8".
711 class BinOpRI8_R<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
712 SDNode opnode, Format f>
713 : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst),
714 [(set typeinfo.RegClass:$dst,
715 (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2))]>;
717 // BinOpRI8_F - Instructions like "cmp reg, imm8".
718 class BinOpRI8_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
719 SDNode opnode, Format f>
720 : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs),
722 (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2))]>;
724 // BinOpRI8_RF - Instructions like "add reg, reg, imm8".
725 class BinOpRI8_RF<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
726 SDNode opnode, Format f>
727 : BinOpRI8<opcode, mnemonic, typeinfo, f, (outs typeinfo.RegClass:$dst),
728 [(set typeinfo.RegClass:$dst, EFLAGS,
729 (opnode typeinfo.RegClass:$src1, typeinfo.Imm8Operator:$src2))]>;
731 // BinOpMR - Instructions like "add [mem], reg".
732 class BinOpMR<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
734 : ITy<opcode, MRMDestMem, typeinfo,
735 (outs), (ins typeinfo.MemOperand:$dst, typeinfo.RegClass:$src),
736 mnemonic, "{$src, $dst|$dst, $src}", pattern>;
738 // BinOpMR_RMW - Instructions like "add [mem], reg".
739 class BinOpMR_RMW<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
741 : BinOpMR<opcode, mnemonic, typeinfo,
742 [(store (opnode (load addr:$dst), typeinfo.RegClass:$src), addr:$dst),
745 // BinOpMR_F - Instructions like "cmp [mem], reg".
746 class BinOpMR_F<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
748 : BinOpMR<opcode, mnemonic, typeinfo,
749 [(set EFLAGS, (opnode (load addr:$dst), typeinfo.RegClass:$src))]>;
751 // BinOpMI - Instructions like "add [mem], imm".
752 class BinOpMI<string mnemonic, X86TypeInfo typeinfo,
753 Format f, list<dag> pattern, bits<8> opcode = 0x80>
754 : ITy<opcode, f, typeinfo,
755 (outs), (ins typeinfo.MemOperand:$dst, typeinfo.ImmOperand:$src),
756 mnemonic, "{$src, $dst|$dst, $src}", pattern> {
757 let ImmT = typeinfo.ImmEncoding;
760 // BinOpMI_RMW - Instructions like "add [mem], imm".
761 class BinOpMI_RMW<string mnemonic, X86TypeInfo typeinfo,
762 SDNode opnode, Format f>
763 : BinOpMI<mnemonic, typeinfo, f,
764 [(store (opnode (typeinfo.VT (load addr:$dst)),
765 typeinfo.ImmOperator:$src), addr:$dst),
768 // BinOpMI_F - Instructions like "cmp [mem], imm".
769 class BinOpMI_F<string mnemonic, X86TypeInfo typeinfo,
770 SDPatternOperator opnode, Format f, bits<8> opcode = 0x80>
771 : BinOpMI<mnemonic, typeinfo, f,
772 [(set EFLAGS, (opnode (typeinfo.VT (load addr:$dst)),
773 typeinfo.ImmOperator:$src))],
776 // BinOpMI8 - Instructions like "add [mem], imm8".
777 class BinOpMI8<string mnemonic, X86TypeInfo typeinfo,
778 Format f, list<dag> pattern>
779 : ITy<0x82, f, typeinfo,
780 (outs), (ins typeinfo.MemOperand:$dst, typeinfo.Imm8Operand:$src),
781 mnemonic, "{$src, $dst|$dst, $src}", pattern> {
782 let ImmT = Imm8; // Always 8-bit immediate.
785 // BinOpMI8_RMW - Instructions like "add [mem], imm8".
786 class BinOpMI8_RMW<string mnemonic, X86TypeInfo typeinfo,
787 SDNode opnode, Format f>
788 : BinOpMI8<mnemonic, typeinfo, f,
789 [(store (opnode (load addr:$dst),
790 typeinfo.Imm8Operator:$src), addr:$dst),
793 // BinOpMI8_F - Instructions like "cmp [mem], imm8".
794 class BinOpMI8_F<string mnemonic, X86TypeInfo typeinfo,
795 SDNode opnode, Format f>
796 : BinOpMI8<mnemonic, typeinfo, f,
797 [(set EFLAGS, (opnode (load addr:$dst),
798 typeinfo.Imm8Operator:$src))]>;
800 // BinOpAI - Instructions like "add %eax, %eax, imm".
801 class BinOpAI<bits<8> opcode, string mnemonic, X86TypeInfo typeinfo,
803 : ITy<opcode, RawFrm, typeinfo,
804 (outs), (ins typeinfo.ImmOperand:$src),
805 mnemonic, !strconcat("{$src, %", areg.AsmName, "|%",
806 areg.AsmName, ", $src}"), []> {
807 let ImmT = typeinfo.ImmEncoding;
812 /// ArithBinOp_RF - This is an arithmetic binary operator where the pattern is
813 /// defined with "(set GPR:$dst, EFLAGS, (...".
815 /// It would be nice to get rid of the second and third argument here, but
816 /// tblgen can't handle dependent type references aggressively enough: PR8330
817 multiclass ArithBinOp_RF<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
818 string mnemonic, Format RegMRM, Format MemMRM,
819 SDNode opnodeflag, SDNode opnode,
820 bit CommutableRR, bit ConvertibleToThreeAddress> {
821 let Defs = [EFLAGS] in {
822 let Constraints = "$src1 = $dst" in {
823 let isCommutable = CommutableRR,
824 isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
825 def #NAME#8rr : BinOpRR_RF<BaseOpc, mnemonic, Xi8 , opnodeflag>;
826 def #NAME#16rr : BinOpRR_RF<BaseOpc, mnemonic, Xi16, opnodeflag>;
827 def #NAME#32rr : BinOpRR_RF<BaseOpc, mnemonic, Xi32, opnodeflag>;
828 def #NAME#64rr : BinOpRR_RF<BaseOpc, mnemonic, Xi64, opnodeflag>;
831 def #NAME#8rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi8>;
832 def #NAME#16rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi16>;
833 def #NAME#32rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi32>;
834 def #NAME#64rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi64>;
836 def #NAME#8rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi8 , opnodeflag>;
837 def #NAME#16rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi16, opnodeflag>;
838 def #NAME#32rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi32, opnodeflag>;
839 def #NAME#64rm : BinOpRM_RF<BaseOpc2, mnemonic, Xi64, opnodeflag>;
841 let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
842 // NOTE: These are order specific, we want the ri8 forms to be listed
843 // first so that they are slightly preferred to the ri forms.
844 def #NAME#16ri8 : BinOpRI8_RF<0x82, mnemonic, Xi16, opnodeflag, RegMRM>;
845 def #NAME#32ri8 : BinOpRI8_RF<0x82, mnemonic, Xi32, opnodeflag, RegMRM>;
846 def #NAME#64ri8 : BinOpRI8_RF<0x82, mnemonic, Xi64, opnodeflag, RegMRM>;
848 def #NAME#8ri : BinOpRI_RF<0x80, mnemonic, Xi8 , opnodeflag, RegMRM>;
849 def #NAME#16ri : BinOpRI_RF<0x80, mnemonic, Xi16, opnodeflag, RegMRM>;
850 def #NAME#32ri : BinOpRI_RF<0x80, mnemonic, Xi32, opnodeflag, RegMRM>;
851 def #NAME#64ri32: BinOpRI_RF<0x80, mnemonic, Xi64, opnodeflag, RegMRM>;
853 } // Constraints = "$src1 = $dst"
855 def #NAME#8mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi8 , opnode>;
856 def #NAME#16mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi16, opnode>;
857 def #NAME#32mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi32, opnode>;
858 def #NAME#64mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi64, opnode>;
860 // NOTE: These are order specific, we want the mi8 forms to be listed
861 // first so that they are slightly preferred to the mi forms.
862 def #NAME#16mi8 : BinOpMI8_RMW<mnemonic, Xi16, opnode, MemMRM>;
863 def #NAME#32mi8 : BinOpMI8_RMW<mnemonic, Xi32, opnode, MemMRM>;
864 def #NAME#64mi8 : BinOpMI8_RMW<mnemonic, Xi64, opnode, MemMRM>;
866 def #NAME#8mi : BinOpMI_RMW<mnemonic, Xi8 , opnode, MemMRM>;
867 def #NAME#16mi : BinOpMI_RMW<mnemonic, Xi16, opnode, MemMRM>;
868 def #NAME#32mi : BinOpMI_RMW<mnemonic, Xi32, opnode, MemMRM>;
869 def #NAME#64mi32 : BinOpMI_RMW<mnemonic, Xi64, opnode, MemMRM>;
871 def #NAME#8i8 : BinOpAI<BaseOpc4, mnemonic, Xi8 , AL>;
872 def #NAME#16i16 : BinOpAI<BaseOpc4, mnemonic, Xi16, AX>;
873 def #NAME#32i32 : BinOpAI<BaseOpc4, mnemonic, Xi32, EAX>;
874 def #NAME#64i32 : BinOpAI<BaseOpc4, mnemonic, Xi64, RAX>;
878 /// ArithBinOp_R - This is an arithmetic binary operator where the pattern is
879 /// defined with "(set GPR:$dst, (...". It would be really nice to find a way
880 /// to factor this with the other ArithBinOp_*.
882 multiclass ArithBinOp_R<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
883 string mnemonic, Format RegMRM, Format MemMRM,
885 bit CommutableRR, bit ConvertibleToThreeAddress> {
886 let Defs = [EFLAGS] in {
887 let Constraints = "$src1 = $dst" in {
888 let isCommutable = CommutableRR,
889 isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
890 def #NAME#8rr : BinOpRR_R<BaseOpc, mnemonic, Xi8 , opnode>;
891 def #NAME#16rr : BinOpRR_R<BaseOpc, mnemonic, Xi16, opnode>;
892 def #NAME#32rr : BinOpRR_R<BaseOpc, mnemonic, Xi32, opnode>;
893 def #NAME#64rr : BinOpRR_R<BaseOpc, mnemonic, Xi64, opnode>;
896 def #NAME#8rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi8>;
897 def #NAME#16rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi16>;
898 def #NAME#32rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi32>;
899 def #NAME#64rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi64>;
901 def #NAME#8rm : BinOpRM_R<BaseOpc2, mnemonic, Xi8 , opnode>;
902 def #NAME#16rm : BinOpRM_R<BaseOpc2, mnemonic, Xi16, opnode>;
903 def #NAME#32rm : BinOpRM_R<BaseOpc2, mnemonic, Xi32, opnode>;
904 def #NAME#64rm : BinOpRM_R<BaseOpc2, mnemonic, Xi64, opnode>;
906 let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
907 // NOTE: These are order specific, we want the ri8 forms to be listed
908 // first so that they are slightly preferred to the ri forms.
909 def #NAME#16ri8 : BinOpRI8_R<0x82, mnemonic, Xi16, opnode, RegMRM>;
910 def #NAME#32ri8 : BinOpRI8_R<0x82, mnemonic, Xi32, opnode, RegMRM>;
911 def #NAME#64ri8 : BinOpRI8_R<0x82, mnemonic, Xi64, opnode, RegMRM>;
913 def #NAME#8ri : BinOpRI_R<0x80, mnemonic, Xi8 , opnode, RegMRM>;
914 def #NAME#16ri : BinOpRI_R<0x80, mnemonic, Xi16, opnode, RegMRM>;
915 def #NAME#32ri : BinOpRI_R<0x80, mnemonic, Xi32, opnode, RegMRM>;
916 def #NAME#64ri32: BinOpRI_R<0x80, mnemonic, Xi64, opnode, RegMRM>;
918 } // Constraints = "$src1 = $dst"
920 def #NAME#8mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi8 , opnode>;
921 def #NAME#16mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi16, opnode>;
922 def #NAME#32mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi32, opnode>;
923 def #NAME#64mr : BinOpMR_RMW<BaseOpc, mnemonic, Xi64, opnode>;
925 // NOTE: These are order specific, we want the mi8 forms to be listed
926 // first so that they are slightly preferred to the mi forms.
927 def #NAME#16mi8 : BinOpMI8_RMW<mnemonic, Xi16, opnode, MemMRM>;
928 def #NAME#32mi8 : BinOpMI8_RMW<mnemonic, Xi32, opnode, MemMRM>;
929 def #NAME#64mi8 : BinOpMI8_RMW<mnemonic, Xi64, opnode, MemMRM>;
931 def #NAME#8mi : BinOpMI_RMW<mnemonic, Xi8 , opnode, MemMRM>;
932 def #NAME#16mi : BinOpMI_RMW<mnemonic, Xi16, opnode, MemMRM>;
933 def #NAME#32mi : BinOpMI_RMW<mnemonic, Xi32, opnode, MemMRM>;
934 def #NAME#64mi32 : BinOpMI_RMW<mnemonic, Xi64, opnode, MemMRM>;
936 def #NAME#8i8 : BinOpAI<BaseOpc4, mnemonic, Xi8 , AL>;
937 def #NAME#16i16 : BinOpAI<BaseOpc4, mnemonic, Xi16, AX>;
938 def #NAME#32i32 : BinOpAI<BaseOpc4, mnemonic, Xi32, EAX>;
939 def #NAME#64i32 : BinOpAI<BaseOpc4, mnemonic, Xi64, RAX>;
943 /// ArithBinOp_F - This is an arithmetic binary operator where the pattern is
944 /// defined with "(set EFLAGS, (...". It would be really nice to find a way
945 /// to factor this with the other ArithBinOp_*.
947 multiclass ArithBinOp_F<bits<8> BaseOpc, bits<8> BaseOpc2, bits<8> BaseOpc4,
948 string mnemonic, Format RegMRM, Format MemMRM,
950 bit CommutableRR, bit ConvertibleToThreeAddress> {
951 let Defs = [EFLAGS] in {
952 let isCommutable = CommutableRR,
953 isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
954 def #NAME#8rr : BinOpRR_F<BaseOpc, mnemonic, Xi8 , opnode>;
955 def #NAME#16rr : BinOpRR_F<BaseOpc, mnemonic, Xi16, opnode>;
956 def #NAME#32rr : BinOpRR_F<BaseOpc, mnemonic, Xi32, opnode>;
957 def #NAME#64rr : BinOpRR_F<BaseOpc, mnemonic, Xi64, opnode>;
960 def #NAME#8rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi8>;
961 def #NAME#16rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi16>;
962 def #NAME#32rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi32>;
963 def #NAME#64rr_REV : BinOpRR_Rev<BaseOpc2, mnemonic, Xi64>;
965 def #NAME#8rm : BinOpRM_F<BaseOpc2, mnemonic, Xi8 , opnode>;
966 def #NAME#16rm : BinOpRM_F<BaseOpc2, mnemonic, Xi16, opnode>;
967 def #NAME#32rm : BinOpRM_F<BaseOpc2, mnemonic, Xi32, opnode>;
968 def #NAME#64rm : BinOpRM_F<BaseOpc2, mnemonic, Xi64, opnode>;
970 let isConvertibleToThreeAddress = ConvertibleToThreeAddress in {
971 // NOTE: These are order specific, we want the ri8 forms to be listed
972 // first so that they are slightly preferred to the ri forms.
973 def #NAME#16ri8 : BinOpRI8_F<0x82, mnemonic, Xi16, opnode, RegMRM>;
974 def #NAME#32ri8 : BinOpRI8_F<0x82, mnemonic, Xi32, opnode, RegMRM>;
975 def #NAME#64ri8 : BinOpRI8_F<0x82, mnemonic, Xi64, opnode, RegMRM>;
977 def #NAME#8ri : BinOpRI_F<0x80, mnemonic, Xi8 , opnode, RegMRM>;
978 def #NAME#16ri : BinOpRI_F<0x80, mnemonic, Xi16, opnode, RegMRM>;
979 def #NAME#32ri : BinOpRI_F<0x80, mnemonic, Xi32, opnode, RegMRM>;
980 def #NAME#64ri32: BinOpRI_F<0x80, mnemonic, Xi64, opnode, RegMRM>;
983 def #NAME#8mr : BinOpMR_F<BaseOpc, mnemonic, Xi8 , opnode>;
984 def #NAME#16mr : BinOpMR_F<BaseOpc, mnemonic, Xi16, opnode>;
985 def #NAME#32mr : BinOpMR_F<BaseOpc, mnemonic, Xi32, opnode>;
986 def #NAME#64mr : BinOpMR_F<BaseOpc, mnemonic, Xi64, opnode>;
988 // NOTE: These are order specific, we want the mi8 forms to be listed
989 // first so that they are slightly preferred to the mi forms.
990 def #NAME#16mi8 : BinOpMI8_F<mnemonic, Xi16, opnode, MemMRM>;
991 def #NAME#32mi8 : BinOpMI8_F<mnemonic, Xi32, opnode, MemMRM>;
992 def #NAME#64mi8 : BinOpMI8_F<mnemonic, Xi64, opnode, MemMRM>;
994 def #NAME#8mi : BinOpMI_F<mnemonic, Xi8 , opnode, MemMRM>;
995 def #NAME#16mi : BinOpMI_F<mnemonic, Xi16, opnode, MemMRM>;
996 def #NAME#32mi : BinOpMI_F<mnemonic, Xi32, opnode, MemMRM>;
997 def #NAME#64mi32 : BinOpMI_F<mnemonic, Xi64, opnode, MemMRM>;
999 def #NAME#8i8 : BinOpAI<BaseOpc4, mnemonic, Xi8 , AL>;
1000 def #NAME#16i16 : BinOpAI<BaseOpc4, mnemonic, Xi16, AX>;
1001 def #NAME#32i32 : BinOpAI<BaseOpc4, mnemonic, Xi32, EAX>;
1002 def #NAME#64i32 : BinOpAI<BaseOpc4, mnemonic, Xi64, RAX>;
1007 defm AND : ArithBinOp_RF<0x20, 0x22, 0x24, "and", MRM4r, MRM4m,
1008 X86and_flag, and, 1, 0>;
1009 defm OR : ArithBinOp_RF<0x08, 0x0A, 0x0C, "or", MRM1r, MRM1m,
1010 X86or_flag, or, 1, 0>;
1011 defm XOR : ArithBinOp_RF<0x30, 0x32, 0x34, "xor", MRM6r, MRM6m,
1012 X86xor_flag, xor, 1, 0>;
1013 defm ADD : ArithBinOp_RF<0x00, 0x02, 0x04, "add", MRM0r, MRM0m,
1014 X86add_flag, add, 1, 1>;
1015 defm SUB : ArithBinOp_RF<0x28, 0x2A, 0x2C, "sub", MRM5r, MRM5m,
1016 X86sub_flag, sub, 0, 0>;
1019 let Uses = [EFLAGS] in {
1020 // FIXME: Delete ArithBinOp_R if these switch off adde/sube.
1021 defm ADC : ArithBinOp_R<0x10, 0x12, 0x14, "adc", MRM2r, MRM2m, adde, 1, 0>;
1022 defm SBB : ArithBinOp_R<0x18, 0x1A, 0x1C, "sbb", MRM3r, MRM3m, sube, 0, 0>;
1027 defm CMP : ArithBinOp_F<0x38, 0x3A, 0x3C, "cmp", MRM7r, MRM7m, X86cmp, 0, 0>;
1030 //===----------------------------------------------------------------------===//
1031 // Semantically, test instructions are similar like AND, except they don't
1032 // generate a result. From an encoding perspective, they are very different:
1033 // they don't have all the usual imm8 and REV forms, and are encoded into a
1035 def X86testpat : PatFrag<(ops node:$lhs, node:$rhs),
1036 (X86cmp (and_su node:$lhs, node:$rhs), 0)>;
1038 let Defs = [EFLAGS] in {
1039 let isCommutable = 1 in {
1040 def TEST8rr : BinOpRR_F<0x84, "test", Xi8 , X86testpat, MRMSrcReg>;
1041 def TEST16rr : BinOpRR_F<0x84, "test", Xi16, X86testpat, MRMSrcReg>;
1042 def TEST32rr : BinOpRR_F<0x84, "test", Xi32, X86testpat, MRMSrcReg>;
1043 def TEST64rr : BinOpRR_F<0x84, "test", Xi64, X86testpat, MRMSrcReg>;
1046 def TEST8rm : BinOpRM_F<0x84, "test", Xi8 , X86testpat>;
1047 def TEST16rm : BinOpRM_F<0x84, "test", Xi16, X86testpat>;
1048 def TEST32rm : BinOpRM_F<0x84, "test", Xi32, X86testpat>;
1049 def TEST64rm : BinOpRM_F<0x84, "test", Xi64, X86testpat>;
1051 def TEST8ri : BinOpRI_F<0xF6, "test", Xi8 , X86testpat, MRM0r>;
1052 def TEST16ri : BinOpRI_F<0xF6, "test", Xi16, X86testpat, MRM0r>;
1053 def TEST32ri : BinOpRI_F<0xF6, "test", Xi32, X86testpat, MRM0r>;
1054 def TEST64ri32 : BinOpRI_F<0xF6, "test", Xi64, X86testpat, MRM0r>;
1056 def TEST8mi : BinOpMI_F<"test", Xi8 , X86testpat, MRM0m, 0xF6>;
1057 def TEST16mi : BinOpMI_F<"test", Xi16, X86testpat, MRM0m, 0xF6>;
1058 def TEST32mi : BinOpMI_F<"test", Xi32, X86testpat, MRM0m, 0xF6>;
1059 def TEST64mi32 : BinOpMI_F<"test", Xi64, X86testpat, MRM0m, 0xF6>;
1061 def TEST8i8 : BinOpAI<0xA8, "test", Xi8 , AL>;
1062 def TEST16i16 : BinOpAI<0xA8, "test", Xi16, AX>;
1063 def TEST32i32 : BinOpAI<0xA8, "test", Xi32, EAX>;
1064 def TEST64i32 : BinOpAI<0xA8, "test", Xi64, RAX>;