X86InstrXOP.td 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. //===-- X86InstrXOP.td - XOP Instruction Set ---------------*- 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 XOP (eXtended OPerations)
  10. //
  11. //===----------------------------------------------------------------------===//
  12. multiclass xop2op<bits<8> opc, string OpcodeStr, Intrinsic Int> {
  13. def rr : IXOP<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
  14. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  15. [(set VR128:$dst, (Int VR128:$src))]>, XOP, Sched<[SchedWritePHAdd.XMM]>;
  16. def rm : IXOP<opc, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
  17. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  18. [(set VR128:$dst, (Int (load addr:$src)))]>, XOP,
  19. Sched<[SchedWritePHAdd.XMM.Folded, SchedWritePHAdd.XMM.ReadAfterFold]>;
  20. }
  21. let ExeDomain = SSEPackedInt in {
  22. defm VPHSUBWD : xop2op<0xE2, "vphsubwd", int_x86_xop_vphsubwd>;
  23. defm VPHSUBDQ : xop2op<0xE3, "vphsubdq", int_x86_xop_vphsubdq>;
  24. defm VPHSUBBW : xop2op<0xE1, "vphsubbw", int_x86_xop_vphsubbw>;
  25. defm VPHADDWQ : xop2op<0xC7, "vphaddwq", int_x86_xop_vphaddwq>;
  26. defm VPHADDWD : xop2op<0xC6, "vphaddwd", int_x86_xop_vphaddwd>;
  27. defm VPHADDUWQ : xop2op<0xD7, "vphadduwq", int_x86_xop_vphadduwq>;
  28. defm VPHADDUWD : xop2op<0xD6, "vphadduwd", int_x86_xop_vphadduwd>;
  29. defm VPHADDUDQ : xop2op<0xDB, "vphaddudq", int_x86_xop_vphaddudq>;
  30. defm VPHADDUBW : xop2op<0xD1, "vphaddubw", int_x86_xop_vphaddubw>;
  31. defm VPHADDUBQ : xop2op<0xD3, "vphaddubq", int_x86_xop_vphaddubq>;
  32. defm VPHADDUBD : xop2op<0xD2, "vphaddubd", int_x86_xop_vphaddubd>;
  33. defm VPHADDDQ : xop2op<0xCB, "vphadddq", int_x86_xop_vphadddq>;
  34. defm VPHADDBW : xop2op<0xC1, "vphaddbw", int_x86_xop_vphaddbw>;
  35. defm VPHADDBQ : xop2op<0xC3, "vphaddbq", int_x86_xop_vphaddbq>;
  36. defm VPHADDBD : xop2op<0xC2, "vphaddbd", int_x86_xop_vphaddbd>;
  37. }
  38. // Scalar load 2 addr operand instructions
  39. multiclass xop2opsld<bits<8> opc, string OpcodeStr, Intrinsic Int,
  40. Operand memop, PatFrags mem_frags,
  41. X86FoldableSchedWrite sched> {
  42. def rr : IXOP<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
  43. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  44. [(set VR128:$dst, (Int VR128:$src))]>, XOP, Sched<[sched]>;
  45. def rm : IXOP<opc, MRMSrcMem, (outs VR128:$dst), (ins memop:$src),
  46. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  47. [(set VR128:$dst, (Int (mem_frags addr:$src)))]>, XOP,
  48. Sched<[sched.Folded, sched.ReadAfterFold]>;
  49. }
  50. multiclass xop2op128<bits<8> opc, string OpcodeStr, Intrinsic Int,
  51. X86FoldableSchedWrite sched> {
  52. def rr : IXOP<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
  53. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  54. [(set VR128:$dst, (Int VR128:$src))]>, XOP, Sched<[sched]>;
  55. def rm : IXOP<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
  56. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  57. [(set VR128:$dst, (Int (load addr:$src)))]>, XOP,
  58. Sched<[sched.Folded, sched.ReadAfterFold]>;
  59. }
  60. multiclass xop2op256<bits<8> opc, string OpcodeStr, Intrinsic Int,
  61. X86FoldableSchedWrite sched> {
  62. def Yrr : IXOP<opc, MRMSrcReg, (outs VR256:$dst), (ins VR256:$src),
  63. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  64. [(set VR256:$dst, (Int VR256:$src))]>, XOP, VEX_L, Sched<[sched]>;
  65. def Yrm : IXOP<opc, MRMSrcMem, (outs VR256:$dst), (ins f256mem:$src),
  66. !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
  67. [(set VR256:$dst, (Int (load addr:$src)))]>, XOP, VEX_L,
  68. Sched<[sched.Folded, sched.ReadAfterFold]>;
  69. }
  70. let ExeDomain = SSEPackedSingle in {
  71. defm VFRCZSS : xop2opsld<0x82, "vfrczss", int_x86_xop_vfrcz_ss,
  72. ssmem, sse_load_f32, SchedWriteFRnd.Scl>;
  73. defm VFRCZPS : xop2op128<0x80, "vfrczps", int_x86_xop_vfrcz_ps,
  74. SchedWriteFRnd.XMM>;
  75. defm VFRCZPS : xop2op256<0x80, "vfrczps", int_x86_xop_vfrcz_ps_256,
  76. SchedWriteFRnd.YMM>;
  77. }
  78. let ExeDomain = SSEPackedDouble in {
  79. defm VFRCZSD : xop2opsld<0x83, "vfrczsd", int_x86_xop_vfrcz_sd,
  80. sdmem, sse_load_f64, SchedWriteFRnd.Scl>;
  81. defm VFRCZPD : xop2op128<0x81, "vfrczpd", int_x86_xop_vfrcz_pd,
  82. SchedWriteFRnd.XMM>;
  83. defm VFRCZPD : xop2op256<0x81, "vfrczpd", int_x86_xop_vfrcz_pd_256,
  84. SchedWriteFRnd.YMM>;
  85. }
  86. multiclass xop3op<bits<8> opc, string OpcodeStr, SDNode OpNode,
  87. ValueType vt128, X86FoldableSchedWrite sched> {
  88. def rr : IXOP<opc, MRMSrcReg4VOp3, (outs VR128:$dst),
  89. (ins VR128:$src1, VR128:$src2),
  90. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  91. [(set VR128:$dst,
  92. (vt128 (OpNode (vt128 VR128:$src1), (vt128 VR128:$src2))))]>,
  93. XOP, Sched<[sched]>;
  94. def rm : IXOP<opc, MRMSrcMem, (outs VR128:$dst),
  95. (ins VR128:$src1, i128mem:$src2),
  96. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  97. [(set VR128:$dst,
  98. (vt128 (OpNode (vt128 VR128:$src1),
  99. (vt128 (load addr:$src2)))))]>,
  100. XOP_4V, VEX_W, Sched<[sched.Folded, sched.ReadAfterFold]>;
  101. def mr : IXOP<opc, MRMSrcMem4VOp3, (outs VR128:$dst),
  102. (ins i128mem:$src1, VR128:$src2),
  103. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  104. [(set VR128:$dst,
  105. (vt128 (OpNode (vt128 (load addr:$src1)),
  106. (vt128 VR128:$src2))))]>,
  107. XOP, Sched<[sched.Folded, sched.ReadAfterFold]>;
  108. // For disassembler
  109. let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0 in
  110. def rr_REV : IXOP<opc, MRMSrcReg, (outs VR128:$dst),
  111. (ins VR128:$src1, VR128:$src2),
  112. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  113. []>,
  114. XOP_4V, VEX_W, Sched<[sched]>, FoldGenData<NAME#rr>;
  115. }
  116. let ExeDomain = SSEPackedInt in {
  117. defm VPROTB : xop3op<0x90, "vprotb", rotl, v16i8, SchedWriteVarVecShift.XMM>;
  118. defm VPROTD : xop3op<0x92, "vprotd", rotl, v4i32, SchedWriteVarVecShift.XMM>;
  119. defm VPROTQ : xop3op<0x93, "vprotq", rotl, v2i64, SchedWriteVarVecShift.XMM>;
  120. defm VPROTW : xop3op<0x91, "vprotw", rotl, v8i16, SchedWriteVarVecShift.XMM>;
  121. defm VPSHAB : xop3op<0x98, "vpshab", X86vpsha, v16i8, SchedWriteVarVecShift.XMM>;
  122. defm VPSHAD : xop3op<0x9A, "vpshad", X86vpsha, v4i32, SchedWriteVarVecShift.XMM>;
  123. defm VPSHAQ : xop3op<0x9B, "vpshaq", X86vpsha, v2i64, SchedWriteVarVecShift.XMM>;
  124. defm VPSHAW : xop3op<0x99, "vpshaw", X86vpsha, v8i16, SchedWriteVarVecShift.XMM>;
  125. defm VPSHLB : xop3op<0x94, "vpshlb", X86vpshl, v16i8, SchedWriteVarVecShift.XMM>;
  126. defm VPSHLD : xop3op<0x96, "vpshld", X86vpshl, v4i32, SchedWriteVarVecShift.XMM>;
  127. defm VPSHLQ : xop3op<0x97, "vpshlq", X86vpshl, v2i64, SchedWriteVarVecShift.XMM>;
  128. defm VPSHLW : xop3op<0x95, "vpshlw", X86vpshl, v8i16, SchedWriteVarVecShift.XMM>;
  129. }
  130. multiclass xop3opimm<bits<8> opc, string OpcodeStr, SDNode OpNode,
  131. ValueType vt128, X86FoldableSchedWrite sched> {
  132. def ri : IXOPi8<opc, MRMSrcReg, (outs VR128:$dst),
  133. (ins VR128:$src1, u8imm:$src2),
  134. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  135. [(set VR128:$dst,
  136. (vt128 (OpNode (vt128 VR128:$src1), timm:$src2)))]>,
  137. XOP, Sched<[sched]>;
  138. def mi : IXOPi8<opc, MRMSrcMem, (outs VR128:$dst),
  139. (ins i128mem:$src1, u8imm:$src2),
  140. !strconcat(OpcodeStr, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
  141. [(set VR128:$dst,
  142. (vt128 (OpNode (vt128 (load addr:$src1)), timm:$src2)))]>,
  143. XOP, Sched<[sched.Folded, sched.ReadAfterFold]>;
  144. }
  145. let ExeDomain = SSEPackedInt in {
  146. defm VPROTB : xop3opimm<0xC0, "vprotb", X86vrotli, v16i8,
  147. SchedWriteVecShiftImm.XMM>;
  148. defm VPROTD : xop3opimm<0xC2, "vprotd", X86vrotli, v4i32,
  149. SchedWriteVecShiftImm.XMM>;
  150. defm VPROTQ : xop3opimm<0xC3, "vprotq", X86vrotli, v2i64,
  151. SchedWriteVecShiftImm.XMM>;
  152. defm VPROTW : xop3opimm<0xC1, "vprotw", X86vrotli, v8i16,
  153. SchedWriteVecShiftImm.XMM>;
  154. }
  155. // Instruction where second source can be memory, but third must be register
  156. multiclass xop4opm2<bits<8> opc, string OpcodeStr, Intrinsic Int,
  157. X86FoldableSchedWrite sched> {
  158. let isCommutable = 1 in
  159. def rr : IXOPi8Reg<opc, MRMSrcReg, (outs VR128:$dst),
  160. (ins VR128:$src1, VR128:$src2, VR128:$src3),
  161. !strconcat(OpcodeStr,
  162. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  163. [(set VR128:$dst,
  164. (Int VR128:$src1, VR128:$src2, VR128:$src3))]>, XOP_4V,
  165. Sched<[sched]>;
  166. def rm : IXOPi8Reg<opc, MRMSrcMem, (outs VR128:$dst),
  167. (ins VR128:$src1, i128mem:$src2, VR128:$src3),
  168. !strconcat(OpcodeStr,
  169. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  170. [(set VR128:$dst,
  171. (Int VR128:$src1, (load addr:$src2),
  172. VR128:$src3))]>, XOP_4V, Sched<[sched.Folded, sched.ReadAfterFold]>;
  173. }
  174. let ExeDomain = SSEPackedInt in {
  175. defm VPMADCSWD : xop4opm2<0xB6, "vpmadcswd",
  176. int_x86_xop_vpmadcswd, SchedWriteVecIMul.XMM>;
  177. defm VPMADCSSWD : xop4opm2<0xA6, "vpmadcsswd",
  178. int_x86_xop_vpmadcsswd, SchedWriteVecIMul.XMM>;
  179. defm VPMACSWW : xop4opm2<0x95, "vpmacsww",
  180. int_x86_xop_vpmacsww, SchedWriteVecIMul.XMM>;
  181. defm VPMACSWD : xop4opm2<0x96, "vpmacswd",
  182. int_x86_xop_vpmacswd, SchedWriteVecIMul.XMM>;
  183. defm VPMACSSWW : xop4opm2<0x85, "vpmacssww",
  184. int_x86_xop_vpmacssww, SchedWriteVecIMul.XMM>;
  185. defm VPMACSSWD : xop4opm2<0x86, "vpmacsswd",
  186. int_x86_xop_vpmacsswd, SchedWriteVecIMul.XMM>;
  187. defm VPMACSSDQL : xop4opm2<0x87, "vpmacssdql",
  188. int_x86_xop_vpmacssdql, SchedWritePMULLD.XMM>;
  189. defm VPMACSSDQH : xop4opm2<0x8F, "vpmacssdqh",
  190. int_x86_xop_vpmacssdqh, SchedWritePMULLD.XMM>;
  191. defm VPMACSSDD : xop4opm2<0x8E, "vpmacssdd",
  192. int_x86_xop_vpmacssdd, SchedWritePMULLD.XMM>;
  193. defm VPMACSDQL : xop4opm2<0x97, "vpmacsdql",
  194. int_x86_xop_vpmacsdql, SchedWritePMULLD.XMM>;
  195. defm VPMACSDQH : xop4opm2<0x9F, "vpmacsdqh",
  196. int_x86_xop_vpmacsdqh, SchedWritePMULLD.XMM>;
  197. defm VPMACSDD : xop4opm2<0x9E, "vpmacsdd",
  198. int_x86_xop_vpmacsdd, SchedWritePMULLD.XMM>;
  199. }
  200. // IFMA patterns - for cases where we can safely ignore the overflow bits from
  201. // the multiply or easily match with existing intrinsics.
  202. let Predicates = [HasXOP] in {
  203. def : Pat<(v8i16 (add (mul (v8i16 VR128:$src1), (v8i16 VR128:$src2)),
  204. (v8i16 VR128:$src3))),
  205. (VPMACSWWrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  206. def : Pat<(v4i32 (add (mul (v4i32 VR128:$src1), (v4i32 VR128:$src2)),
  207. (v4i32 VR128:$src3))),
  208. (VPMACSDDrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  209. def : Pat<(v2i64 (add (X86pmuldq (bc_v2i64 (X86PShufd (v4i32 VR128:$src1), (i8 -11))),
  210. (bc_v2i64 (X86PShufd (v4i32 VR128:$src2), (i8 -11)))),
  211. (v2i64 VR128:$src3))),
  212. (VPMACSDQHrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  213. def : Pat<(v2i64 (add (X86pmuldq (v2i64 VR128:$src1), (v2i64 VR128:$src2)),
  214. (v2i64 VR128:$src3))),
  215. (VPMACSDQLrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  216. def : Pat<(v4i32 (add (X86vpmaddwd (v8i16 VR128:$src1), (v8i16 VR128:$src2)),
  217. (v4i32 VR128:$src3))),
  218. (VPMADCSWDrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  219. }
  220. // Transforms to swizzle an immediate to help matching memory operand in first
  221. // operand.
  222. def CommuteVPCOMCC : SDNodeXForm<imm, [{
  223. uint8_t Imm = N->getZExtValue() & 0x7;
  224. Imm = X86::getSwappedVPCOMImm(Imm);
  225. return getI8Imm(Imm, SDLoc(N));
  226. }]>;
  227. // Instruction where second source can be memory, third must be imm8
  228. multiclass xopvpcom<bits<8> opc, string Suffix, SDNode OpNode, ValueType vt128,
  229. X86FoldableSchedWrite sched> {
  230. let ExeDomain = SSEPackedInt in { // SSE integer instructions
  231. let isCommutable = 1 in
  232. def ri : IXOPi8<opc, MRMSrcReg, (outs VR128:$dst),
  233. (ins VR128:$src1, VR128:$src2, u8imm:$cc),
  234. !strconcat("vpcom", Suffix,
  235. "\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}"),
  236. [(set VR128:$dst,
  237. (vt128 (OpNode (vt128 VR128:$src1), (vt128 VR128:$src2),
  238. timm:$cc)))]>,
  239. XOP_4V, Sched<[sched]>;
  240. def mi : IXOPi8<opc, MRMSrcMem, (outs VR128:$dst),
  241. (ins VR128:$src1, i128mem:$src2, u8imm:$cc),
  242. !strconcat("vpcom", Suffix,
  243. "\t{$cc, $src2, $src1, $dst|$dst, $src1, $src2, $cc}"),
  244. [(set VR128:$dst,
  245. (vt128 (OpNode (vt128 VR128:$src1),
  246. (vt128 (load addr:$src2)),
  247. timm:$cc)))]>,
  248. XOP_4V, Sched<[sched.Folded, sched.ReadAfterFold]>;
  249. }
  250. def : Pat<(OpNode (load addr:$src2),
  251. (vt128 VR128:$src1), timm:$cc),
  252. (!cast<Instruction>(NAME#"mi") VR128:$src1, addr:$src2,
  253. (CommuteVPCOMCC timm:$cc))>;
  254. }
  255. defm VPCOMB : xopvpcom<0xCC, "b", X86vpcom, v16i8, SchedWriteVecALU.XMM>;
  256. defm VPCOMW : xopvpcom<0xCD, "w", X86vpcom, v8i16, SchedWriteVecALU.XMM>;
  257. defm VPCOMD : xopvpcom<0xCE, "d", X86vpcom, v4i32, SchedWriteVecALU.XMM>;
  258. defm VPCOMQ : xopvpcom<0xCF, "q", X86vpcom, v2i64, SchedWriteVecALU.XMM>;
  259. defm VPCOMUB : xopvpcom<0xEC, "ub", X86vpcomu, v16i8, SchedWriteVecALU.XMM>;
  260. defm VPCOMUW : xopvpcom<0xED, "uw", X86vpcomu, v8i16, SchedWriteVecALU.XMM>;
  261. defm VPCOMUD : xopvpcom<0xEE, "ud", X86vpcomu, v4i32, SchedWriteVecALU.XMM>;
  262. defm VPCOMUQ : xopvpcom<0xEF, "uq", X86vpcomu, v2i64, SchedWriteVecALU.XMM>;
  263. multiclass xop4op<bits<8> opc, string OpcodeStr, SDNode OpNode,
  264. ValueType vt128, X86FoldableSchedWrite sched> {
  265. def rrr : IXOPi8Reg<opc, MRMSrcReg, (outs VR128:$dst),
  266. (ins VR128:$src1, VR128:$src2, VR128:$src3),
  267. !strconcat(OpcodeStr,
  268. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  269. [(set VR128:$dst,
  270. (vt128 (OpNode (vt128 VR128:$src1), (vt128 VR128:$src2),
  271. (vt128 VR128:$src3))))]>,
  272. XOP_4V, Sched<[sched]>;
  273. def rrm : IXOPi8Reg<opc, MRMSrcMemOp4, (outs VR128:$dst),
  274. (ins VR128:$src1, VR128:$src2, i128mem:$src3),
  275. !strconcat(OpcodeStr,
  276. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  277. [(set VR128:$dst,
  278. (vt128 (OpNode (vt128 VR128:$src1), (vt128 VR128:$src2),
  279. (vt128 (load addr:$src3)))))]>,
  280. XOP_4V, VEX_W, Sched<[sched.Folded, sched.ReadAfterFold, sched.ReadAfterFold]>;
  281. def rmr : IXOPi8Reg<opc, MRMSrcMem, (outs VR128:$dst),
  282. (ins VR128:$src1, i128mem:$src2, VR128:$src3),
  283. !strconcat(OpcodeStr,
  284. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  285. [(set VR128:$dst,
  286. (v16i8 (OpNode (vt128 VR128:$src1), (vt128 (load addr:$src2)),
  287. (vt128 VR128:$src3))))]>,
  288. XOP_4V, Sched<[sched.Folded, sched.ReadAfterFold,
  289. // 128mem:$src2
  290. ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  291. ReadDefault,
  292. // VR128:$src3
  293. sched.ReadAfterFold]>;
  294. // For disassembler
  295. let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0 in
  296. def rrr_REV : IXOPi8Reg<opc, MRMSrcRegOp4, (outs VR128:$dst),
  297. (ins VR128:$src1, VR128:$src2, VR128:$src3),
  298. !strconcat(OpcodeStr,
  299. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  300. []>, XOP_4V, VEX_W, Sched<[sched]>, FoldGenData<NAME#rrr>;
  301. }
  302. let ExeDomain = SSEPackedInt in {
  303. defm VPPERM : xop4op<0xA3, "vpperm", X86vpperm, v16i8,
  304. SchedWriteVarShuffle.XMM>;
  305. }
  306. // Instruction where either second or third source can be memory
  307. multiclass xop4op_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
  308. X86MemOperand x86memop, ValueType VT,
  309. X86FoldableSchedWrite sched> {
  310. def rrr : IXOPi8Reg<opc, MRMSrcReg, (outs RC:$dst),
  311. (ins RC:$src1, RC:$src2, RC:$src3),
  312. !strconcat(OpcodeStr,
  313. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  314. [(set RC:$dst, (VT (or (and RC:$src3, RC:$src1),
  315. (X86andnp RC:$src3, RC:$src2))))]>, XOP_4V,
  316. Sched<[sched]>;
  317. // FIXME: We can't write a pattern for this in tablegen.
  318. let hasSideEffects = 0, mayLoad = 1 in
  319. def rrm : IXOPi8Reg<opc, MRMSrcMemOp4, (outs RC:$dst),
  320. (ins RC:$src1, RC:$src2, x86memop:$src3),
  321. !strconcat(OpcodeStr,
  322. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  323. []>,
  324. XOP_4V, VEX_W, Sched<[sched.Folded, sched.ReadAfterFold, sched.ReadAfterFold]>;
  325. def rmr : IXOPi8Reg<opc, MRMSrcMem, (outs RC:$dst),
  326. (ins RC:$src1, x86memop:$src2, RC:$src3),
  327. !strconcat(OpcodeStr,
  328. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  329. [(set RC:$dst, (VT (or (and RC:$src3, RC:$src1),
  330. (X86andnp RC:$src3, (load addr:$src2)))))]>,
  331. XOP_4V, Sched<[sched.Folded, sched.ReadAfterFold,
  332. // x86memop:$src2
  333. ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  334. ReadDefault,
  335. // RC::$src3
  336. sched.ReadAfterFold]>;
  337. // For disassembler
  338. let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0 in
  339. def rrr_REV : IXOPi8Reg<opc, MRMSrcRegOp4, (outs RC:$dst),
  340. (ins RC:$src1, RC:$src2, RC:$src3),
  341. !strconcat(OpcodeStr,
  342. "\t{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}"),
  343. []>, XOP_4V, VEX_W, Sched<[sched]>, FoldGenData<NAME#rrr>;
  344. }
  345. let ExeDomain = SSEPackedInt in {
  346. defm VPCMOV : xop4op_int<0xA2, "vpcmov", VR128, i128mem, v2i64,
  347. SchedWriteShuffle.XMM>;
  348. defm VPCMOVY : xop4op_int<0xA2, "vpcmov", VR256, i256mem, v4i64,
  349. SchedWriteShuffle.YMM>, VEX_L;
  350. }
  351. let Predicates = [HasXOP] in {
  352. def : Pat<(v16i8 (or (and VR128:$src3, VR128:$src1),
  353. (X86andnp VR128:$src3, VR128:$src2))),
  354. (VPCMOVrrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  355. def : Pat<(v8i16 (or (and VR128:$src3, VR128:$src1),
  356. (X86andnp VR128:$src3, VR128:$src2))),
  357. (VPCMOVrrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  358. def : Pat<(v4i32 (or (and VR128:$src3, VR128:$src1),
  359. (X86andnp VR128:$src3, VR128:$src2))),
  360. (VPCMOVrrr VR128:$src1, VR128:$src2, VR128:$src3)>;
  361. def : Pat<(or (and VR128:$src3, VR128:$src1),
  362. (X86andnp VR128:$src3, (loadv16i8 addr:$src2))),
  363. (VPCMOVrmr VR128:$src1, addr:$src2, VR128:$src3)>;
  364. def : Pat<(or (and VR128:$src3, VR128:$src1),
  365. (X86andnp VR128:$src3, (loadv8i16 addr:$src2))),
  366. (VPCMOVrmr VR128:$src1, addr:$src2, VR128:$src3)>;
  367. def : Pat<(or (and VR128:$src3, VR128:$src1),
  368. (X86andnp VR128:$src3, (loadv4i32 addr:$src2))),
  369. (VPCMOVrmr VR128:$src1, addr:$src2, VR128:$src3)>;
  370. def : Pat<(v32i8 (or (and VR256:$src3, VR256:$src1),
  371. (X86andnp VR256:$src3, VR256:$src2))),
  372. (VPCMOVYrrr VR256:$src1, VR256:$src2, VR256:$src3)>;
  373. def : Pat<(v16i16 (or (and VR256:$src3, VR256:$src1),
  374. (X86andnp VR256:$src3, VR256:$src2))),
  375. (VPCMOVYrrr VR256:$src1, VR256:$src2, VR256:$src3)>;
  376. def : Pat<(v8i32 (or (and VR256:$src3, VR256:$src1),
  377. (X86andnp VR256:$src3, VR256:$src2))),
  378. (VPCMOVYrrr VR256:$src1, VR256:$src2, VR256:$src3)>;
  379. def : Pat<(or (and VR256:$src3, VR256:$src1),
  380. (X86andnp VR256:$src3, (loadv32i8 addr:$src2))),
  381. (VPCMOVYrmr VR256:$src1, addr:$src2, VR256:$src3)>;
  382. def : Pat<(or (and VR256:$src3, VR256:$src1),
  383. (X86andnp VR256:$src3, (loadv16i16 addr:$src2))),
  384. (VPCMOVYrmr VR256:$src1, addr:$src2, VR256:$src3)>;
  385. def : Pat<(or (and VR256:$src3, VR256:$src1),
  386. (X86andnp VR256:$src3, (loadv8i32 addr:$src2))),
  387. (VPCMOVYrmr VR256:$src1, addr:$src2, VR256:$src3)>;
  388. }
  389. multiclass xop_vpermil2<bits<8> Opc, string OpcodeStr, RegisterClass RC,
  390. X86MemOperand intmemop, X86MemOperand fpmemop,
  391. ValueType VT, PatFrag FPLdFrag, PatFrag IntLdFrag,
  392. X86FoldableSchedWrite sched> {
  393. def rr : IXOP5<Opc, MRMSrcReg, (outs RC:$dst),
  394. (ins RC:$src1, RC:$src2, RC:$src3, u4imm:$src4),
  395. !strconcat(OpcodeStr,
  396. "\t{$src4, $src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3, $src4}"),
  397. [(set RC:$dst,
  398. (VT (X86vpermil2 RC:$src1, RC:$src2, RC:$src3, (i8 timm:$src4))))]>,
  399. Sched<[sched]>;
  400. def rm : IXOP5<Opc, MRMSrcMemOp4, (outs RC:$dst),
  401. (ins RC:$src1, RC:$src2, intmemop:$src3, u4imm:$src4),
  402. !strconcat(OpcodeStr,
  403. "\t{$src4, $src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3, $src4}"),
  404. [(set RC:$dst,
  405. (VT (X86vpermil2 RC:$src1, RC:$src2, (IntLdFrag addr:$src3),
  406. (i8 timm:$src4))))]>, VEX_W,
  407. Sched<[sched.Folded, sched.ReadAfterFold, sched.ReadAfterFold]>;
  408. def mr : IXOP5<Opc, MRMSrcMem, (outs RC:$dst),
  409. (ins RC:$src1, fpmemop:$src2, RC:$src3, u4imm:$src4),
  410. !strconcat(OpcodeStr,
  411. "\t{$src4, $src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3, $src4}"),
  412. [(set RC:$dst,
  413. (VT (X86vpermil2 RC:$src1, (FPLdFrag addr:$src2),
  414. RC:$src3, (i8 timm:$src4))))]>,
  415. Sched<[sched.Folded, sched.ReadAfterFold,
  416. // fpmemop:$src2
  417. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  418. // RC:$src3
  419. sched.ReadAfterFold]>;
  420. // For disassembler
  421. let isCodeGenOnly = 1, ForceDisassemble = 1, hasSideEffects = 0 in
  422. def rr_REV : IXOP5<Opc, MRMSrcRegOp4, (outs RC:$dst),
  423. (ins RC:$src1, RC:$src2, RC:$src3, u4imm:$src4),
  424. !strconcat(OpcodeStr,
  425. "\t{$src4, $src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3, $src4}"),
  426. []>, VEX_W, Sched<[sched]>, FoldGenData<NAME#rr>;
  427. }
  428. let ExeDomain = SSEPackedDouble in {
  429. defm VPERMIL2PD : xop_vpermil2<0x49, "vpermil2pd", VR128, i128mem, f128mem,
  430. v2f64, loadv2f64, loadv2i64,
  431. SchedWriteFVarShuffle.XMM>;
  432. defm VPERMIL2PDY : xop_vpermil2<0x49, "vpermil2pd", VR256, i256mem, f256mem,
  433. v4f64, loadv4f64, loadv4i64,
  434. SchedWriteFVarShuffle.YMM>, VEX_L;
  435. }
  436. let ExeDomain = SSEPackedSingle in {
  437. defm VPERMIL2PS : xop_vpermil2<0x48, "vpermil2ps", VR128, i128mem, f128mem,
  438. v4f32, loadv4f32, loadv4i32,
  439. SchedWriteFVarShuffle.XMM>;
  440. defm VPERMIL2PSY : xop_vpermil2<0x48, "vpermil2ps", VR256, i256mem, f256mem,
  441. v8f32, loadv8f32, loadv8i32,
  442. SchedWriteFVarShuffle.YMM>, VEX_L;
  443. }