X86InstrVecCompiler.td 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. //===- X86InstrVecCompiler.td - Vector Compiler Patterns ---*- 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 various vector pseudo instructions used by the
  10. // compiler, as well as Pat patterns used during instruction selection.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. // Non-instruction patterns
  15. //===----------------------------------------------------------------------===//
  16. let Predicates = [NoAVX512] in {
  17. // A vector extract of the first f32/f64 position is a subregister copy
  18. def : Pat<(f16 (extractelt (v8f16 VR128:$src), (iPTR 0))),
  19. (COPY_TO_REGCLASS (v8f16 VR128:$src), FR16)>;
  20. def : Pat<(f32 (extractelt (v4f32 VR128:$src), (iPTR 0))),
  21. (COPY_TO_REGCLASS (v4f32 VR128:$src), FR32)>;
  22. def : Pat<(f64 (extractelt (v2f64 VR128:$src), (iPTR 0))),
  23. (COPY_TO_REGCLASS (v2f64 VR128:$src), FR64)>;
  24. }
  25. let Predicates = [HasAVX512] in {
  26. // A vector extract of the first f32/f64 position is a subregister copy
  27. def : Pat<(f16 (extractelt (v8f16 VR128X:$src), (iPTR 0))),
  28. (COPY_TO_REGCLASS (v8f16 VR128X:$src), FR16X)>;
  29. def : Pat<(f32 (extractelt (v4f32 VR128X:$src), (iPTR 0))),
  30. (COPY_TO_REGCLASS (v4f32 VR128X:$src), FR32X)>;
  31. def : Pat<(f64 (extractelt (v2f64 VR128X:$src), (iPTR 0))),
  32. (COPY_TO_REGCLASS (v2f64 VR128X:$src), FR64X)>;
  33. }
  34. let Predicates = [NoVLX] in {
  35. def : Pat<(v8f16 (scalar_to_vector FR16:$src)),
  36. (COPY_TO_REGCLASS FR16:$src, VR128)>;
  37. // Implicitly promote a 32-bit scalar to a vector.
  38. def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
  39. (COPY_TO_REGCLASS FR32:$src, VR128)>;
  40. // Implicitly promote a 64-bit scalar to a vector.
  41. def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
  42. (COPY_TO_REGCLASS FR64:$src, VR128)>;
  43. }
  44. let Predicates = [HasVLX] in {
  45. def : Pat<(v8f16 (scalar_to_vector FR16X:$src)),
  46. (COPY_TO_REGCLASS FR16X:$src, VR128X)>;
  47. // Implicitly promote a 32-bit scalar to a vector.
  48. def : Pat<(v4f32 (scalar_to_vector FR32X:$src)),
  49. (COPY_TO_REGCLASS FR32X:$src, VR128X)>;
  50. // Implicitly promote a 64-bit scalar to a vector.
  51. def : Pat<(v2f64 (scalar_to_vector FR64X:$src)),
  52. (COPY_TO_REGCLASS FR64X:$src, VR128X)>;
  53. }
  54. //===----------------------------------------------------------------------===//
  55. // Subvector tricks
  56. //===----------------------------------------------------------------------===//
  57. // Patterns for insert_subvector/extract_subvector to/from index=0
  58. multiclass subvector_subreg_lowering<RegisterClass subRC, ValueType subVT,
  59. RegisterClass RC, ValueType VT,
  60. SubRegIndex subIdx> {
  61. def : Pat<(subVT (extract_subvector (VT RC:$src), (iPTR 0))),
  62. (subVT (EXTRACT_SUBREG RC:$src, subIdx))>;
  63. def : Pat<(VT (insert_subvector undef_or_freeze_undef, subRC:$src, (iPTR 0))),
  64. (VT (INSERT_SUBREG (IMPLICIT_DEF), subRC:$src, subIdx))>;
  65. }
  66. // A 128-bit subvector extract from the first 256-bit vector position is a
  67. // subregister copy that needs no instruction. Likewise, a 128-bit subvector
  68. // insert to the first 256-bit vector position is a subregister copy that needs
  69. // no instruction.
  70. defm : subvector_subreg_lowering<VR128, v4i32, VR256, v8i32, sub_xmm>;
  71. defm : subvector_subreg_lowering<VR128, v4f32, VR256, v8f32, sub_xmm>;
  72. defm : subvector_subreg_lowering<VR128, v2i64, VR256, v4i64, sub_xmm>;
  73. defm : subvector_subreg_lowering<VR128, v2f64, VR256, v4f64, sub_xmm>;
  74. defm : subvector_subreg_lowering<VR128, v8i16, VR256, v16i16, sub_xmm>;
  75. defm : subvector_subreg_lowering<VR128, v16i8, VR256, v32i8, sub_xmm>;
  76. defm : subvector_subreg_lowering<VR128, v8f16, VR256, v16f16, sub_xmm>;
  77. // A 128-bit subvector extract from the first 512-bit vector position is a
  78. // subregister copy that needs no instruction. Likewise, a 128-bit subvector
  79. // insert to the first 512-bit vector position is a subregister copy that needs
  80. // no instruction.
  81. defm : subvector_subreg_lowering<VR128, v4i32, VR512, v16i32, sub_xmm>;
  82. defm : subvector_subreg_lowering<VR128, v4f32, VR512, v16f32, sub_xmm>;
  83. defm : subvector_subreg_lowering<VR128, v2i64, VR512, v8i64, sub_xmm>;
  84. defm : subvector_subreg_lowering<VR128, v2f64, VR512, v8f64, sub_xmm>;
  85. defm : subvector_subreg_lowering<VR128, v8i16, VR512, v32i16, sub_xmm>;
  86. defm : subvector_subreg_lowering<VR128, v16i8, VR512, v64i8, sub_xmm>;
  87. defm : subvector_subreg_lowering<VR128, v8f16, VR512, v32f16, sub_xmm>;
  88. // A 128-bit subvector extract from the first 512-bit vector position is a
  89. // subregister copy that needs no instruction. Likewise, a 128-bit subvector
  90. // insert to the first 512-bit vector position is a subregister copy that needs
  91. // no instruction.
  92. defm : subvector_subreg_lowering<VR256, v8i32, VR512, v16i32, sub_ymm>;
  93. defm : subvector_subreg_lowering<VR256, v8f32, VR512, v16f32, sub_ymm>;
  94. defm : subvector_subreg_lowering<VR256, v4i64, VR512, v8i64, sub_ymm>;
  95. defm : subvector_subreg_lowering<VR256, v4f64, VR512, v8f64, sub_ymm>;
  96. defm : subvector_subreg_lowering<VR256, v16i16, VR512, v32i16, sub_ymm>;
  97. defm : subvector_subreg_lowering<VR256, v32i8, VR512, v64i8, sub_ymm>;
  98. defm : subvector_subreg_lowering<VR256, v16f16, VR512, v32f16, sub_ymm>;
  99. // If we're inserting into an all zeros vector, just use a plain move which
  100. // will zero the upper bits. A post-isel hook will take care of removing
  101. // any moves that we can prove are unnecessary.
  102. multiclass subvec_zero_lowering<string MoveStr,
  103. RegisterClass RC, ValueType DstTy,
  104. ValueType SrcTy, SubRegIndex SubIdx> {
  105. def : Pat<(DstTy (insert_subvector immAllZerosV,
  106. (SrcTy RC:$src), (iPTR 0))),
  107. (SUBREG_TO_REG (i64 0),
  108. (SrcTy (!cast<Instruction>("VMOV"#MoveStr#"rr") RC:$src)), SubIdx)>;
  109. }
  110. let Predicates = [HasAVX, NoVLX] in {
  111. defm : subvec_zero_lowering<"APD", VR128, v4f64, v2f64, sub_xmm>;
  112. defm : subvec_zero_lowering<"APS", VR128, v8f32, v4f32, sub_xmm>;
  113. defm : subvec_zero_lowering<"DQA", VR128, v4i64, v2i64, sub_xmm>;
  114. defm : subvec_zero_lowering<"DQA", VR128, v8i32, v4i32, sub_xmm>;
  115. defm : subvec_zero_lowering<"DQA", VR128, v16i16, v8i16, sub_xmm>;
  116. defm : subvec_zero_lowering<"DQA", VR128, v32i8, v16i8, sub_xmm>;
  117. }
  118. let Predicates = [HasVLX] in {
  119. defm : subvec_zero_lowering<"APDZ128", VR128X, v4f64, v2f64, sub_xmm>;
  120. defm : subvec_zero_lowering<"APSZ128", VR128X, v8f32, v4f32, sub_xmm>;
  121. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v4i64, v2i64, sub_xmm>;
  122. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v8i32, v4i32, sub_xmm>;
  123. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v16i16, v8i16, sub_xmm>;
  124. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v32i8, v16i8, sub_xmm>;
  125. defm : subvec_zero_lowering<"APDZ128", VR128X, v8f64, v2f64, sub_xmm>;
  126. defm : subvec_zero_lowering<"APSZ128", VR128X, v16f32, v4f32, sub_xmm>;
  127. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v8i64, v2i64, sub_xmm>;
  128. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v16i32, v4i32, sub_xmm>;
  129. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v32i16, v8i16, sub_xmm>;
  130. defm : subvec_zero_lowering<"DQA64Z128", VR128X, v64i8, v16i8, sub_xmm>;
  131. defm : subvec_zero_lowering<"APDZ256", VR256X, v8f64, v4f64, sub_ymm>;
  132. defm : subvec_zero_lowering<"APSZ256", VR256X, v16f32, v8f32, sub_ymm>;
  133. defm : subvec_zero_lowering<"DQA64Z256", VR256X, v8i64, v4i64, sub_ymm>;
  134. defm : subvec_zero_lowering<"DQA64Z256", VR256X, v16i32, v8i32, sub_ymm>;
  135. defm : subvec_zero_lowering<"DQA64Z256", VR256X, v32i16, v16i16, sub_ymm>;
  136. defm : subvec_zero_lowering<"DQA64Z256", VR256X, v64i8, v32i8, sub_ymm>;
  137. }
  138. let Predicates = [HasAVX512, NoVLX] in {
  139. defm : subvec_zero_lowering<"APD", VR128, v8f64, v2f64, sub_xmm>;
  140. defm : subvec_zero_lowering<"APS", VR128, v16f32, v4f32, sub_xmm>;
  141. defm : subvec_zero_lowering<"DQA", VR128, v8i64, v2i64, sub_xmm>;
  142. defm : subvec_zero_lowering<"DQA", VR128, v16i32, v4i32, sub_xmm>;
  143. defm : subvec_zero_lowering<"DQA", VR128, v32i16, v8i16, sub_xmm>;
  144. defm : subvec_zero_lowering<"DQA", VR128, v64i8, v16i8, sub_xmm>;
  145. defm : subvec_zero_lowering<"APDY", VR256, v8f64, v4f64, sub_ymm>;
  146. defm : subvec_zero_lowering<"APSY", VR256, v16f32, v8f32, sub_ymm>;
  147. defm : subvec_zero_lowering<"DQAY", VR256, v8i64, v4i64, sub_ymm>;
  148. defm : subvec_zero_lowering<"DQAY", VR256, v16i32, v8i32, sub_ymm>;
  149. defm : subvec_zero_lowering<"DQAY", VR256, v32i16, v16i16, sub_ymm>;
  150. defm : subvec_zero_lowering<"DQAY", VR256, v64i8, v32i8, sub_ymm>;
  151. }
  152. let Predicates = [HasFP16, HasVLX] in {
  153. defm : subvec_zero_lowering<"APSZ128", VR128X, v16f16, v8f16, sub_xmm>;
  154. defm : subvec_zero_lowering<"APSZ128", VR128X, v32f16, v8f16, sub_xmm>;
  155. defm : subvec_zero_lowering<"APSZ256", VR256X, v32f16, v16f16, sub_ymm>;
  156. }
  157. class maskzeroupper<ValueType vt, RegisterClass RC> :
  158. PatLeaf<(vt RC:$src), [{
  159. return isMaskZeroExtended(N);
  160. }]>;
  161. def maskzeroupperv1i1 : maskzeroupper<v1i1, VK1>;
  162. def maskzeroupperv2i1 : maskzeroupper<v2i1, VK2>;
  163. def maskzeroupperv4i1 : maskzeroupper<v4i1, VK4>;
  164. def maskzeroupperv8i1 : maskzeroupper<v8i1, VK8>;
  165. def maskzeroupperv16i1 : maskzeroupper<v16i1, VK16>;
  166. def maskzeroupperv32i1 : maskzeroupper<v32i1, VK32>;
  167. // The patterns determine if we can depend on the upper bits of a mask register
  168. // being zeroed by the previous operation so that we can skip explicit
  169. // zeroing.
  170. let Predicates = [HasBWI] in {
  171. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  172. maskzeroupperv1i1:$src, (iPTR 0))),
  173. (COPY_TO_REGCLASS VK1:$src, VK32)>;
  174. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  175. maskzeroupperv8i1:$src, (iPTR 0))),
  176. (COPY_TO_REGCLASS VK8:$src, VK32)>;
  177. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  178. maskzeroupperv16i1:$src, (iPTR 0))),
  179. (COPY_TO_REGCLASS VK16:$src, VK32)>;
  180. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  181. maskzeroupperv1i1:$src, (iPTR 0))),
  182. (COPY_TO_REGCLASS VK1:$src, VK64)>;
  183. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  184. maskzeroupperv8i1:$src, (iPTR 0))),
  185. (COPY_TO_REGCLASS VK8:$src, VK64)>;
  186. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  187. maskzeroupperv16i1:$src, (iPTR 0))),
  188. (COPY_TO_REGCLASS VK16:$src, VK64)>;
  189. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  190. maskzeroupperv32i1:$src, (iPTR 0))),
  191. (COPY_TO_REGCLASS VK32:$src, VK64)>;
  192. }
  193. let Predicates = [HasAVX512] in {
  194. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  195. maskzeroupperv1i1:$src, (iPTR 0))),
  196. (COPY_TO_REGCLASS VK1:$src, VK16)>;
  197. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  198. maskzeroupperv8i1:$src, (iPTR 0))),
  199. (COPY_TO_REGCLASS VK8:$src, VK16)>;
  200. }
  201. let Predicates = [HasDQI] in {
  202. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  203. maskzeroupperv1i1:$src, (iPTR 0))),
  204. (COPY_TO_REGCLASS VK1:$src, VK8)>;
  205. }
  206. let Predicates = [HasVLX, HasDQI] in {
  207. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  208. maskzeroupperv2i1:$src, (iPTR 0))),
  209. (COPY_TO_REGCLASS VK2:$src, VK8)>;
  210. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  211. maskzeroupperv4i1:$src, (iPTR 0))),
  212. (COPY_TO_REGCLASS VK4:$src, VK8)>;
  213. }
  214. let Predicates = [HasVLX] in {
  215. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  216. maskzeroupperv2i1:$src, (iPTR 0))),
  217. (COPY_TO_REGCLASS VK2:$src, VK16)>;
  218. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  219. maskzeroupperv4i1:$src, (iPTR 0))),
  220. (COPY_TO_REGCLASS VK4:$src, VK16)>;
  221. }
  222. let Predicates = [HasBWI, HasVLX] in {
  223. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  224. maskzeroupperv2i1:$src, (iPTR 0))),
  225. (COPY_TO_REGCLASS VK2:$src, VK32)>;
  226. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  227. maskzeroupperv4i1:$src, (iPTR 0))),
  228. (COPY_TO_REGCLASS VK4:$src, VK32)>;
  229. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  230. maskzeroupperv2i1:$src, (iPTR 0))),
  231. (COPY_TO_REGCLASS VK2:$src, VK64)>;
  232. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  233. maskzeroupperv4i1:$src, (iPTR 0))),
  234. (COPY_TO_REGCLASS VK4:$src, VK64)>;
  235. }
  236. // If the bits are not zero we have to fall back to explicitly zeroing by
  237. // using shifts.
  238. let Predicates = [HasAVX512] in {
  239. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  240. (v1i1 VK1:$mask), (iPTR 0))),
  241. (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK1:$mask, VK16),
  242. (i8 15)), (i8 15))>;
  243. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  244. (v2i1 VK2:$mask), (iPTR 0))),
  245. (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK2:$mask, VK16),
  246. (i8 14)), (i8 14))>;
  247. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  248. (v4i1 VK4:$mask), (iPTR 0))),
  249. (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK4:$mask, VK16),
  250. (i8 12)), (i8 12))>;
  251. }
  252. let Predicates = [HasAVX512, NoDQI] in {
  253. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  254. (v8i1 VK8:$mask), (iPTR 0))),
  255. (KSHIFTRWri (KSHIFTLWri (COPY_TO_REGCLASS VK8:$mask, VK16),
  256. (i8 8)), (i8 8))>;
  257. }
  258. let Predicates = [HasDQI] in {
  259. def : Pat<(v16i1 (insert_subvector (v16i1 immAllZerosV),
  260. (v8i1 VK8:$mask), (iPTR 0))),
  261. (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK16)>;
  262. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  263. (v1i1 VK1:$mask), (iPTR 0))),
  264. (KSHIFTRBri (KSHIFTLBri (COPY_TO_REGCLASS VK1:$mask, VK8),
  265. (i8 7)), (i8 7))>;
  266. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  267. (v2i1 VK2:$mask), (iPTR 0))),
  268. (KSHIFTRBri (KSHIFTLBri (COPY_TO_REGCLASS VK2:$mask, VK8),
  269. (i8 6)), (i8 6))>;
  270. def : Pat<(v8i1 (insert_subvector (v8i1 immAllZerosV),
  271. (v4i1 VK4:$mask), (iPTR 0))),
  272. (KSHIFTRBri (KSHIFTLBri (COPY_TO_REGCLASS VK4:$mask, VK8),
  273. (i8 4)), (i8 4))>;
  274. }
  275. let Predicates = [HasBWI] in {
  276. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  277. (v16i1 VK16:$mask), (iPTR 0))),
  278. (COPY_TO_REGCLASS (KMOVWkk VK16:$mask), VK32)>;
  279. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  280. (v16i1 VK16:$mask), (iPTR 0))),
  281. (COPY_TO_REGCLASS (KMOVWkk VK16:$mask), VK64)>;
  282. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  283. (v32i1 VK32:$mask), (iPTR 0))),
  284. (COPY_TO_REGCLASS (KMOVDkk VK32:$mask), VK64)>;
  285. }
  286. let Predicates = [HasBWI, NoDQI] in {
  287. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  288. (v8i1 VK8:$mask), (iPTR 0))),
  289. (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK8:$mask, VK32),
  290. (i8 24)), (i8 24))>;
  291. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  292. (v8i1 VK8:$mask), (iPTR 0))),
  293. (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK8:$mask, VK64),
  294. (i8 56)), (i8 56))>;
  295. }
  296. let Predicates = [HasBWI, HasDQI] in {
  297. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  298. (v8i1 VK8:$mask), (iPTR 0))),
  299. (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK32)>;
  300. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  301. (v8i1 VK8:$mask), (iPTR 0))),
  302. (COPY_TO_REGCLASS (KMOVBkk VK8:$mask), VK64)>;
  303. }
  304. let Predicates = [HasBWI] in {
  305. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  306. (v1i1 VK1:$mask), (iPTR 0))),
  307. (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK1:$mask, VK32),
  308. (i8 31)), (i8 31))>;
  309. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  310. (v2i1 VK2:$mask), (iPTR 0))),
  311. (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK2:$mask, VK32),
  312. (i8 30)), (i8 30))>;
  313. def : Pat<(v32i1 (insert_subvector (v32i1 immAllZerosV),
  314. (v4i1 VK4:$mask), (iPTR 0))),
  315. (KSHIFTRDri (KSHIFTLDri (COPY_TO_REGCLASS VK4:$mask, VK32),
  316. (i8 28)), (i8 28))>;
  317. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  318. (v1i1 VK1:$mask), (iPTR 0))),
  319. (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK1:$mask, VK64),
  320. (i8 63)), (i8 63))>;
  321. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  322. (v2i1 VK2:$mask), (iPTR 0))),
  323. (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK2:$mask, VK64),
  324. (i8 62)), (i8 62))>;
  325. def : Pat<(v64i1 (insert_subvector (v64i1 immAllZerosV),
  326. (v4i1 VK4:$mask), (iPTR 0))),
  327. (KSHIFTRQri (KSHIFTLQri (COPY_TO_REGCLASS VK4:$mask, VK64),
  328. (i8 60)), (i8 60))>;
  329. }
  330. //===----------------------------------------------------------------------===//
  331. // Extra selection patterns for f128, f128mem
  332. // movaps is shorter than movdqa. movaps is in SSE and movdqa is in SSE2.
  333. let Predicates = [NoAVX] in {
  334. def : Pat<(alignedstore (f128 VR128:$src), addr:$dst),
  335. (MOVAPSmr addr:$dst, VR128:$src)>;
  336. def : Pat<(store (f128 VR128:$src), addr:$dst),
  337. (MOVUPSmr addr:$dst, VR128:$src)>;
  338. def : Pat<(alignedloadf128 addr:$src),
  339. (MOVAPSrm addr:$src)>;
  340. def : Pat<(loadf128 addr:$src),
  341. (MOVUPSrm addr:$src)>;
  342. }
  343. let Predicates = [HasAVX, NoVLX] in {
  344. def : Pat<(alignedstore (f128 VR128:$src), addr:$dst),
  345. (VMOVAPSmr addr:$dst, VR128:$src)>;
  346. def : Pat<(store (f128 VR128:$src), addr:$dst),
  347. (VMOVUPSmr addr:$dst, VR128:$src)>;
  348. def : Pat<(alignedloadf128 addr:$src),
  349. (VMOVAPSrm addr:$src)>;
  350. def : Pat<(loadf128 addr:$src),
  351. (VMOVUPSrm addr:$src)>;
  352. }
  353. let Predicates = [HasVLX] in {
  354. def : Pat<(alignedstore (f128 VR128X:$src), addr:$dst),
  355. (VMOVAPSZ128mr addr:$dst, VR128X:$src)>;
  356. def : Pat<(store (f128 VR128X:$src), addr:$dst),
  357. (VMOVUPSZ128mr addr:$dst, VR128X:$src)>;
  358. def : Pat<(alignedloadf128 addr:$src),
  359. (VMOVAPSZ128rm addr:$src)>;
  360. def : Pat<(loadf128 addr:$src),
  361. (VMOVUPSZ128rm addr:$src)>;
  362. }
  363. let Predicates = [UseSSE1] in {
  364. // andps is shorter than andpd or pand. andps is SSE and andpd/pand are in SSE2
  365. def : Pat<(f128 (X86fand VR128:$src1, (memopf128 addr:$src2))),
  366. (ANDPSrm VR128:$src1, f128mem:$src2)>;
  367. def : Pat<(f128 (X86fand VR128:$src1, VR128:$src2)),
  368. (ANDPSrr VR128:$src1, VR128:$src2)>;
  369. def : Pat<(f128 (X86for VR128:$src1, (memopf128 addr:$src2))),
  370. (ORPSrm VR128:$src1, f128mem:$src2)>;
  371. def : Pat<(f128 (X86for VR128:$src1, VR128:$src2)),
  372. (ORPSrr VR128:$src1, VR128:$src2)>;
  373. def : Pat<(f128 (X86fxor VR128:$src1, (memopf128 addr:$src2))),
  374. (XORPSrm VR128:$src1, f128mem:$src2)>;
  375. def : Pat<(f128 (X86fxor VR128:$src1, VR128:$src2)),
  376. (XORPSrr VR128:$src1, VR128:$src2)>;
  377. }
  378. let Predicates = [HasAVX, NoVLX] in {
  379. // andps is shorter than andpd or pand. andps is SSE and andpd/pand are in SSE2
  380. def : Pat<(f128 (X86fand VR128:$src1, (loadf128 addr:$src2))),
  381. (VANDPSrm VR128:$src1, f128mem:$src2)>;
  382. def : Pat<(f128 (X86fand VR128:$src1, VR128:$src2)),
  383. (VANDPSrr VR128:$src1, VR128:$src2)>;
  384. def : Pat<(f128 (X86for VR128:$src1, (loadf128 addr:$src2))),
  385. (VORPSrm VR128:$src1, f128mem:$src2)>;
  386. def : Pat<(f128 (X86for VR128:$src1, VR128:$src2)),
  387. (VORPSrr VR128:$src1, VR128:$src2)>;
  388. def : Pat<(f128 (X86fxor VR128:$src1, (loadf128 addr:$src2))),
  389. (VXORPSrm VR128:$src1, f128mem:$src2)>;
  390. def : Pat<(f128 (X86fxor VR128:$src1, VR128:$src2)),
  391. (VXORPSrr VR128:$src1, VR128:$src2)>;
  392. }
  393. let Predicates = [HasVLX] in {
  394. // andps is shorter than andpd or pand. andps is SSE and andpd/pand are in SSE2
  395. def : Pat<(f128 (X86fand VR128X:$src1, (loadf128 addr:$src2))),
  396. (VANDPSZ128rm VR128X:$src1, f128mem:$src2)>;
  397. def : Pat<(f128 (X86fand VR128X:$src1, VR128X:$src2)),
  398. (VANDPSZ128rr VR128X:$src1, VR128X:$src2)>;
  399. def : Pat<(f128 (X86for VR128X:$src1, (loadf128 addr:$src2))),
  400. (VORPSZ128rm VR128X:$src1, f128mem:$src2)>;
  401. def : Pat<(f128 (X86for VR128X:$src1, VR128X:$src2)),
  402. (VORPSZ128rr VR128X:$src1, VR128X:$src2)>;
  403. def : Pat<(f128 (X86fxor VR128X:$src1, (loadf128 addr:$src2))),
  404. (VXORPSZ128rm VR128X:$src1, f128mem:$src2)>;
  405. def : Pat<(f128 (X86fxor VR128X:$src1, VR128X:$src2)),
  406. (VXORPSZ128rr VR128X:$src1, VR128X:$src2)>;
  407. }