X86InstrCMovSetCC.td 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //===-- X86InstrCMovSetCC.td - Conditional Move and SetCC --*- tablegen -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the X86 conditional move and set on condition
  10. // instructions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. // CMOV instructions.
  14. let isCodeGenOnly = 1, ForceDisassemble = 1 in {
  15. let Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst",
  16. isCommutable = 1, SchedRW = [WriteCMOV] in {
  17. def CMOV16rr
  18. : I<0x40, MRMSrcRegCC, (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, ccode:$cond),
  19. "cmov${cond}{w}\t{$src2, $dst|$dst, $src2}",
  20. [(set GR16:$dst,
  21. (X86cmov GR16:$src1, GR16:$src2, timm:$cond, EFLAGS))]>,
  22. TB, OpSize16;
  23. def CMOV32rr
  24. : I<0x40, MRMSrcRegCC, (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, ccode:$cond),
  25. "cmov${cond}{l}\t{$src2, $dst|$dst, $src2}",
  26. [(set GR32:$dst,
  27. (X86cmov GR32:$src1, GR32:$src2, timm:$cond, EFLAGS))]>,
  28. TB, OpSize32;
  29. def CMOV64rr
  30. :RI<0x40, MRMSrcRegCC, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, ccode:$cond),
  31. "cmov${cond}{q}\t{$src2, $dst|$dst, $src2}",
  32. [(set GR64:$dst,
  33. (X86cmov GR64:$src1, GR64:$src2, timm:$cond, EFLAGS))]>, TB;
  34. }
  35. let Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst",
  36. SchedRW = [WriteCMOV.Folded, WriteCMOV.ReadAfterFold] in {
  37. def CMOV16rm
  38. : I<0x40, MRMSrcMemCC, (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2, ccode:$cond),
  39. "cmov${cond}{w}\t{$src2, $dst|$dst, $src2}",
  40. [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
  41. timm:$cond, EFLAGS))]>, TB, OpSize16;
  42. def CMOV32rm
  43. : I<0x40, MRMSrcMemCC, (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2, ccode:$cond),
  44. "cmov${cond}{l}\t{$src2, $dst|$dst, $src2}",
  45. [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
  46. timm:$cond, EFLAGS))]>, TB, OpSize32;
  47. def CMOV64rm
  48. :RI<0x40, MRMSrcMemCC, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2, ccode:$cond),
  49. "cmov${cond}{q}\t{$src2, $dst|$dst, $src2}",
  50. [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
  51. timm:$cond, EFLAGS))]>, TB;
  52. } // Uses = [EFLAGS], Predicates = [HasCMov], Constraints = "$src1 = $dst"
  53. } // isCodeGenOnly = 1, ForceDisassemble = 1
  54. def inv_cond_XFORM : SDNodeXForm<imm, [{
  55. X86::CondCode CC = static_cast<X86::CondCode>(N->getZExtValue());
  56. return CurDAG->getTargetConstant(X86::GetOppositeBranchCondition(CC),
  57. SDLoc(N), MVT::i8);
  58. }]>;
  59. // Conditional moves with folded loads with operands swapped and conditions
  60. // inverted.
  61. let Predicates = [HasCMov] in {
  62. def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, timm:$cond, EFLAGS),
  63. (CMOV16rm GR16:$src2, addr:$src1, (inv_cond_XFORM timm:$cond))>;
  64. def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, timm:$cond, EFLAGS),
  65. (CMOV32rm GR32:$src2, addr:$src1, (inv_cond_XFORM timm:$cond))>;
  66. def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, timm:$cond, EFLAGS),
  67. (CMOV64rm GR64:$src2, addr:$src1, (inv_cond_XFORM timm:$cond))>;
  68. }
  69. // SetCC instructions.
  70. let Uses = [EFLAGS], isCodeGenOnly = 1, ForceDisassemble = 1 in {
  71. def SETCCr : I<0x90, MRMXrCC, (outs GR8:$dst), (ins ccode:$cond),
  72. "set${cond}\t$dst",
  73. [(set GR8:$dst, (X86setcc timm:$cond, EFLAGS))]>,
  74. TB, Sched<[WriteSETCC]>;
  75. def SETCCm : I<0x90, MRMXmCC, (outs), (ins i8mem:$dst, ccode:$cond),
  76. "set${cond}\t$dst",
  77. [(store (X86setcc timm:$cond, EFLAGS), addr:$dst)]>,
  78. TB, Sched<[WriteSETCCStore]>;
  79. } // Uses = [EFLAGS]
  80. multiclass CMOV_SETCC_Aliases<string Cond, int CC> {
  81. def : InstAlias<"cmov"#Cond#"{w}\t{$src, $dst|$dst, $src}",
  82. (CMOV16rr GR16:$dst, GR16:$src, CC), 0>;
  83. def : InstAlias<"cmov"#Cond#"{w}\t{$src, $dst|$dst, $src}",
  84. (CMOV16rm GR16:$dst, i16mem:$src, CC), 0>;
  85. def : InstAlias<"cmov"#Cond#"{l}\t{$src, $dst|$dst, $src}",
  86. (CMOV32rr GR32:$dst, GR32:$src, CC), 0>;
  87. def : InstAlias<"cmov"#Cond#"{l}\t{$src, $dst|$dst, $src}",
  88. (CMOV32rm GR32:$dst, i32mem:$src, CC), 0>;
  89. def : InstAlias<"cmov"#Cond#"{q}\t{$src, $dst|$dst, $src}",
  90. (CMOV64rr GR64:$dst, GR64:$src, CC), 0>;
  91. def : InstAlias<"cmov"#Cond#"{q}\t{$src, $dst|$dst, $src}",
  92. (CMOV64rm GR64:$dst, i64mem:$src, CC), 0>;
  93. def : InstAlias<"set"#Cond#"\t$dst", (SETCCr GR8:$dst, CC), 0>;
  94. def : InstAlias<"set"#Cond#"\t$dst", (SETCCm i8mem:$dst, CC), 0>;
  95. }
  96. defm : CMOV_SETCC_Aliases<"o" , 0>;
  97. defm : CMOV_SETCC_Aliases<"no", 1>;
  98. defm : CMOV_SETCC_Aliases<"b" , 2>;
  99. defm : CMOV_SETCC_Aliases<"ae", 3>;
  100. defm : CMOV_SETCC_Aliases<"e" , 4>;
  101. defm : CMOV_SETCC_Aliases<"ne", 5>;
  102. defm : CMOV_SETCC_Aliases<"be", 6>;
  103. defm : CMOV_SETCC_Aliases<"a" , 7>;
  104. defm : CMOV_SETCC_Aliases<"s" , 8>;
  105. defm : CMOV_SETCC_Aliases<"ns", 9>;
  106. defm : CMOV_SETCC_Aliases<"p" , 10>;
  107. defm : CMOV_SETCC_Aliases<"np", 11>;
  108. defm : CMOV_SETCC_Aliases<"l" , 12>;
  109. defm : CMOV_SETCC_Aliases<"ge", 13>;
  110. defm : CMOV_SETCC_Aliases<"le", 14>;
  111. defm : CMOV_SETCC_Aliases<"g" , 15>;
  112. // SALC is an undocumented instruction. Information for this instruction can be found
  113. // here http://www.rcollins.org/secrets/opcodes/SALC.html
  114. // Set AL if carry.
  115. let Uses = [EFLAGS], Defs = [AL], SchedRW = [WriteALU] in {
  116. def SALC : I<0xD6, RawFrm, (outs), (ins), "salc", []>, Requires<[Not64BitMode]>;
  117. }