1 //===-- X86InstrCMovSetCC.td - Conditional Move and SetCC --*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file describes the X86 conditional move and set on condition
12 //===----------------------------------------------------------------------===//
16 multiclass CMOV<bits<8> opc, string Mnemonic, X86FoldableSchedWrite Sched,
18 let Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst",
19 isCommutable = 1, SchedRW = [Sched] in {
21 : I<opc, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
22 !strconcat(Mnemonic, "{w}\t{$src2, $dst|$dst, $src2}"),
24 (X86cmov GR16:$src1, GR16:$src2, CondNode, EFLAGS))]>,
27 : I<opc, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
28 !strconcat(Mnemonic, "{l}\t{$src2, $dst|$dst, $src2}"),
30 (X86cmov GR32:$src1, GR32:$src2, CondNode, EFLAGS))]>,
33 :RI<opc, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
34 !strconcat(Mnemonic, "{q}\t{$src2, $dst|$dst, $src2}"),
36 (X86cmov GR64:$src1, GR64:$src2, CondNode, EFLAGS))]>, TB;
39 let Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst",
40 SchedRW = [Sched.Folded, Sched.ReadAfterFold] in {
42 : I<opc, MRMSrcMem, (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
43 !strconcat(Mnemonic, "{w}\t{$src2, $dst|$dst, $src2}"),
44 [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
45 CondNode, EFLAGS))]>, TB, OpSize16;
47 : I<opc, MRMSrcMem, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
48 !strconcat(Mnemonic, "{l}\t{$src2, $dst|$dst, $src2}"),
49 [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
50 CondNode, EFLAGS))]>, TB, OpSize32;
52 :RI<opc, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
53 !strconcat(Mnemonic, "{q}\t{$src2, $dst|$dst, $src2}"),
54 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
55 CondNode, EFLAGS))]>, TB;
56 } // Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst"
61 defm CMOVO : CMOV<0x40, "cmovo" , WriteCMOV, X86_COND_O>;
62 defm CMOVNO : CMOV<0x41, "cmovno", WriteCMOV, X86_COND_NO>;
63 defm CMOVB : CMOV<0x42, "cmovb" , WriteCMOV, X86_COND_B>;
64 defm CMOVAE : CMOV<0x43, "cmovae", WriteCMOV, X86_COND_AE>;
65 defm CMOVE : CMOV<0x44, "cmove" , WriteCMOV, X86_COND_E>;
66 defm CMOVNE : CMOV<0x45, "cmovne", WriteCMOV, X86_COND_NE>;
67 defm CMOVBE : CMOV<0x46, "cmovbe", WriteCMOV2, X86_COND_BE>;
68 defm CMOVA : CMOV<0x47, "cmova" , WriteCMOV2, X86_COND_A>;
69 defm CMOVS : CMOV<0x48, "cmovs" , WriteCMOV, X86_COND_S>;
70 defm CMOVNS : CMOV<0x49, "cmovns", WriteCMOV, X86_COND_NS>;
71 defm CMOVP : CMOV<0x4A, "cmovp" , WriteCMOV, X86_COND_P>;
72 defm CMOVNP : CMOV<0x4B, "cmovnp", WriteCMOV, X86_COND_NP>;
73 defm CMOVL : CMOV<0x4C, "cmovl" , WriteCMOV, X86_COND_L>;
74 defm CMOVGE : CMOV<0x4D, "cmovge", WriteCMOV, X86_COND_GE>;
75 defm CMOVLE : CMOV<0x4E, "cmovle", WriteCMOV, X86_COND_LE>;
76 defm CMOVG : CMOV<0x4F, "cmovg" , WriteCMOV, X86_COND_G>;
79 // SetCC instructions.
80 multiclass SETCC<bits<8> opc, string Mnemonic, PatLeaf OpNode> {
81 let Uses = [EFLAGS] in {
82 def r : I<opc, MRMXr, (outs GR8:$dst), (ins),
83 !strconcat(Mnemonic, "\t$dst"),
84 [(set GR8:$dst, (X86setcc OpNode, EFLAGS))]>,
85 TB, Sched<[WriteSETCC]>;
86 def m : I<opc, MRMXm, (outs), (ins i8mem:$dst),
87 !strconcat(Mnemonic, "\t$dst"),
88 [(store (X86setcc OpNode, EFLAGS), addr:$dst)]>,
89 TB, Sched<[WriteSETCCStore]>;
93 defm SETO : SETCC<0x90, "seto", X86_COND_O>; // is overflow bit set
94 defm SETNO : SETCC<0x91, "setno", X86_COND_NO>; // is overflow bit not set
95 defm SETB : SETCC<0x92, "setb", X86_COND_B>; // unsigned less than
96 defm SETAE : SETCC<0x93, "setae", X86_COND_AE>; // unsigned greater or equal
97 defm SETE : SETCC<0x94, "sete", X86_COND_E>; // equal to
98 defm SETNE : SETCC<0x95, "setne", X86_COND_NE>; // not equal to
99 defm SETBE : SETCC<0x96, "setbe", X86_COND_BE>; // unsigned less than or equal
100 defm SETA : SETCC<0x97, "seta", X86_COND_A>; // unsigned greater than
101 defm SETS : SETCC<0x98, "sets", X86_COND_S>; // is signed bit set
102 defm SETNS : SETCC<0x99, "setns", X86_COND_NS>; // is not signed
103 defm SETP : SETCC<0x9A, "setp", X86_COND_P>; // is parity bit set
104 defm SETNP : SETCC<0x9B, "setnp", X86_COND_NP>; // is parity bit not set
105 defm SETL : SETCC<0x9C, "setl", X86_COND_L>; // signed less than
106 defm SETGE : SETCC<0x9D, "setge", X86_COND_GE>; // signed greater or equal
107 defm SETLE : SETCC<0x9E, "setle", X86_COND_LE>; // signed less than or equal
108 defm SETG : SETCC<0x9F, "setg", X86_COND_G>; // signed greater than
110 // SALC is an undocumented instruction. Information for this instruction can be found
111 // here http://www.rcollins.org/secrets/opcodes/SALC.html
113 let Uses = [EFLAGS], Defs = [AL], SchedRW = [WriteALU] in {
114 def SALC : I<0xD6, RawFrm, (outs), (ins), "salc", []>, Requires<[Not64BitMode]>;