xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1*e8d8bef9SDimitry Andric//===- HexagonPatternsHVX.td - Selection Patterns for HVX --*- tablegen -*-===//
2*e8d8bef9SDimitry Andric//
3*e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5*e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e8d8bef9SDimitry Andric//
7*e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
8*e8d8bef9SDimitry Andric
9*e8d8bef9SDimitry Andric
10*e8d8bef9SDimitry Andricdef SDTVecUnaryOp:
11*e8d8bef9SDimitry Andric  SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
12*e8d8bef9SDimitry Andric
130b57cec5SDimitry Andricdef SDTVecBinOp:
140b57cec5SDimitry Andric  SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<1,2>]>;
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricdef SDTHexagonVEXTRACTW: SDTypeProfile<1, 2,
170b57cec5SDimitry Andric  [SDTCisVT<0, i32>, SDTCisVec<1>, SDTCisVT<2, i32>]>;
180b57cec5SDimitry Andricdef HexagonVEXTRACTW : SDNode<"HexagonISD::VEXTRACTW", SDTHexagonVEXTRACTW>;
190b57cec5SDimitry Andric
200b57cec5SDimitry Andricdef SDTHexagonVINSERTW0: SDTypeProfile<1, 2,
210b57cec5SDimitry Andric  [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, i32>]>;
220b57cec5SDimitry Andricdef HexagonVINSERTW0: SDNode<"HexagonISD::VINSERTW0", SDTHexagonVINSERTW0>;
230b57cec5SDimitry Andric
240b57cec5SDimitry Andricdef HwLen2: SDNodeXForm<imm, [{
250b57cec5SDimitry Andric  const auto &ST = static_cast<const HexagonSubtarget&>(CurDAG->getSubtarget());
260b57cec5SDimitry Andric  return CurDAG->getTargetConstant(ST.getVectorLength()/2, SDLoc(N), MVT::i32);
270b57cec5SDimitry Andric}]>;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andricdef Q2V: OutPatFrag<(ops node:$Qs), (V6_vandqrt $Qs, (A2_tfrsi -1))>;
300b57cec5SDimitry Andric
310b57cec5SDimitry Andricdef Combinev: OutPatFrag<(ops node:$Vs, node:$Vt),
320b57cec5SDimitry Andric  (REG_SEQUENCE HvxWR, $Vs, vsub_hi, $Vt, vsub_lo)>;
330b57cec5SDimitry Andric
340b57cec5SDimitry Andricdef Combineq: OutPatFrag<(ops node:$Qs, node:$Qt),
350b57cec5SDimitry Andric  (V6_vandvrt
360b57cec5SDimitry Andric    (V6_vor
370b57cec5SDimitry Andric      (V6_vror (V6_vpackeb (V6_vd0), (Q2V $Qs)),
380b57cec5SDimitry Andric               (A2_tfrsi (HwLen2 (i32 0)))),  // Half the vector length
390b57cec5SDimitry Andric      (V6_vpackeb (V6_vd0), (Q2V $Qt))),
400b57cec5SDimitry Andric    (A2_tfrsi -1))>;
410b57cec5SDimitry Andric
420b57cec5SDimitry Andricdef LoVec: OutPatFrag<(ops node:$Vs), (EXTRACT_SUBREG $Vs, vsub_lo)>;
430b57cec5SDimitry Andricdef HiVec: OutPatFrag<(ops node:$Vs), (EXTRACT_SUBREG $Vs, vsub_hi)>;
440b57cec5SDimitry Andric
450b57cec5SDimitry Andricdef HexagonQCAT:       SDNode<"HexagonISD::QCAT",       SDTVecBinOp>;
460b57cec5SDimitry Andricdef HexagonQTRUE:      SDNode<"HexagonISD::QTRUE",      SDTVecLeaf>;
470b57cec5SDimitry Andricdef HexagonQFALSE:     SDNode<"HexagonISD::QFALSE",     SDTVecLeaf>;
48*e8d8bef9SDimitry Andricdef HexagonVPACKL:     SDNode<"HexagonISD::VPACKL",     SDTVecUnaryOp>;
49*e8d8bef9SDimitry Andricdef HexagonVUNPACK:    SDNode<"HexagonISD::VUNPACK",    SDTVecUnaryOp>;
50*e8d8bef9SDimitry Andricdef HexagonVUNPACKU:   SDNode<"HexagonISD::VUNPACKU",   SDTVecUnaryOp>;
510b57cec5SDimitry Andric
52*e8d8bef9SDimitry Andricdef vzero:  PatFrag<(ops), (splat_vector (i32 0))>;
530b57cec5SDimitry Andricdef qtrue:  PatFrag<(ops), (HexagonQTRUE)>;
540b57cec5SDimitry Andricdef qfalse: PatFrag<(ops), (HexagonQFALSE)>;
550b57cec5SDimitry Andricdef qcat:   PatFrag<(ops node:$Qs, node:$Qt),
560b57cec5SDimitry Andric                    (HexagonQCAT node:$Qs, node:$Qt)>;
570b57cec5SDimitry Andric
580b57cec5SDimitry Andricdef qnot:     PatFrag<(ops node:$Qs), (xor node:$Qs, qtrue)>;
59*e8d8bef9SDimitry Andricdef vpackl:   PatFrag<(ops node:$Vs), (HexagonVPACKL node:$Vs)>;
60*e8d8bef9SDimitry Andricdef vunpack:  PatFrag<(ops node:$Vs), (HexagonVUNPACK node:$Vs)>;
61*e8d8bef9SDimitry Andricdef vunpacku: PatFrag<(ops node:$Vs), (HexagonVUNPACKU node:$Vs)>;
620b57cec5SDimitry Andric
630b57cec5SDimitry Andricdef VSxtb: OutPatFrag<(ops node:$Vs), (V6_vunpackb  $Vs)>;
640b57cec5SDimitry Andricdef VSxth: OutPatFrag<(ops node:$Vs), (V6_vunpackh  $Vs)>;
650b57cec5SDimitry Andricdef VZxtb: OutPatFrag<(ops node:$Vs), (V6_vunpackub $Vs)>;
660b57cec5SDimitry Andricdef VZxth: OutPatFrag<(ops node:$Vs), (V6_vunpackuh $Vs)>;
670b57cec5SDimitry Andric
680b57cec5SDimitry Andricdef IsVecOff : PatLeaf<(i32 imm), [{
690b57cec5SDimitry Andric  int32_t V = N->getSExtValue();
700b57cec5SDimitry Andric  int32_t VecSize = HRI->getSpillSize(Hexagon::HvxVRRegClass);
710b57cec5SDimitry Andric  assert(isPowerOf2_32(VecSize));
720b57cec5SDimitry Andric  if ((uint32_t(V) & (uint32_t(VecSize)-1)) != 0)
730b57cec5SDimitry Andric    return false;
740b57cec5SDimitry Andric  int32_t L = Log2_32(VecSize);
750b57cec5SDimitry Andric  return isInt<4>(V >> L);
760b57cec5SDimitry Andric}]>;
770b57cec5SDimitry Andric
780b57cec5SDimitry Andric
790b57cec5SDimitry Andricdef alignedload: PatFrag<(ops node:$a), (load $a), [{
800b57cec5SDimitry Andric  return isAlignedMemNode(dyn_cast<MemSDNode>(N));
810b57cec5SDimitry Andric}]>;
820b57cec5SDimitry Andric
830b57cec5SDimitry Andricdef unalignedload: PatFrag<(ops node:$a), (load $a), [{
840b57cec5SDimitry Andric  return !isAlignedMemNode(dyn_cast<MemSDNode>(N));
850b57cec5SDimitry Andric}]>;
860b57cec5SDimitry Andric
870b57cec5SDimitry Andricdef alignedstore: PatFrag<(ops node:$v, node:$a), (store $v, $a), [{
880b57cec5SDimitry Andric  return isAlignedMemNode(dyn_cast<MemSDNode>(N));
890b57cec5SDimitry Andric}]>;
900b57cec5SDimitry Andric
910b57cec5SDimitry Andricdef unalignedstore: PatFrag<(ops node:$v, node:$a), (store $v, $a), [{
920b57cec5SDimitry Andric  return !isAlignedMemNode(dyn_cast<MemSDNode>(N));
930b57cec5SDimitry Andric}]>;
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric
960b57cec5SDimitry Andric// HVX loads
970b57cec5SDimitry Andric
980b57cec5SDimitry Andricmulticlass HvxLd_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
990b57cec5SDimitry Andric                     PatFrag ImmPred> {
1000b57cec5SDimitry Andric  def: Pat<(ResType (Load I32:$Rt)),
1010b57cec5SDimitry Andric           (MI I32:$Rt, 0)>;
1020b57cec5SDimitry Andric  def: Pat<(ResType (Load (add I32:$Rt, ImmPred:$s))),
1030b57cec5SDimitry Andric           (MI I32:$Rt, imm:$s)>;
1040b57cec5SDimitry Andric  // The HVX selection code for shuffles can generate vector constants.
1050b57cec5SDimitry Andric  // Calling "Select" on the resulting loads from CP fails without these
1060b57cec5SDimitry Andric  // patterns.
1070b57cec5SDimitry Andric  def: Pat<(ResType (Load (HexagonCP tconstpool:$A))),
1080b57cec5SDimitry Andric           (MI (A2_tfrsi imm:$A), 0)>;
1090b57cec5SDimitry Andric  def: Pat<(ResType (Load (HexagonAtPcrel tconstpool:$A))),
1100b57cec5SDimitry Andric           (MI (C4_addipc imm:$A), 0)>;
1110b57cec5SDimitry Andric}
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andricmulticlass HvxLda_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
1140b57cec5SDimitry Andric                      PatFrag ImmPred> {
1150b57cec5SDimitry Andric  let AddedComplexity = 50 in {
1160b57cec5SDimitry Andric    def: Pat<(ResType (Load (valignaddr I32:$Rt))),
1170b57cec5SDimitry Andric             (MI I32:$Rt, 0)>;
1180b57cec5SDimitry Andric    def: Pat<(ResType (Load (add (valignaddr I32:$Rt), ImmPred:$Off))),
1190b57cec5SDimitry Andric             (MI I32:$Rt, imm:$Off)>;
1200b57cec5SDimitry Andric  }
1210b57cec5SDimitry Andric  defm: HvxLd_pat<MI, Load, ResType, ImmPred>;
1220b57cec5SDimitry Andric}
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
1250b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI8,  IsVecOff>;
1260b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI16, IsVecOff>;
1270b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI32, IsVecOff>;
1280b57cec5SDimitry Andric
1290b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai, alignedload, VecI8,  IsVecOff>;
1300b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai, alignedload, VecI16, IsVecOff>;
1310b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai, alignedload, VecI32, IsVecOff>;
1320b57cec5SDimitry Andric
1330b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,  unalignedload, VecI8,  IsVecOff>;
1340b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,  unalignedload, VecI16, IsVecOff>;
1350b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,  unalignedload, VecI32, IsVecOff>;
1360b57cec5SDimitry Andric}
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andric// HVX stores
1390b57cec5SDimitry Andric
1400b57cec5SDimitry Andricmulticlass HvxSt_pat<InstHexagon MI, PatFrag Store, PatFrag ImmPred,
1410b57cec5SDimitry Andric                     PatFrag Value> {
1420b57cec5SDimitry Andric  def: Pat<(Store Value:$Vs, I32:$Rt),
1430b57cec5SDimitry Andric           (MI I32:$Rt, 0, Value:$Vs)>;
1440b57cec5SDimitry Andric  def: Pat<(Store Value:$Vs, (add I32:$Rt, ImmPred:$s)),
1450b57cec5SDimitry Andric           (MI I32:$Rt, imm:$s, Value:$Vs)>;
1460b57cec5SDimitry Andric}
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
1490b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, IsVecOff, HVI8>;
1500b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, IsVecOff, HVI16>;
1510b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, IsVecOff, HVI32>;
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai, alignedstore, IsVecOff, HVI8>;
1540b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai, alignedstore, IsVecOff, HVI16>;
1550b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai, alignedstore, IsVecOff, HVI32>;
1560b57cec5SDimitry Andric
1570b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai, unalignedstore, IsVecOff, HVI8>;
1580b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai, unalignedstore, IsVecOff, HVI16>;
1590b57cec5SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai, unalignedstore, IsVecOff, HVI32>;
1600b57cec5SDimitry Andric}
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric// Bitcasts between same-size vector types are no-ops, except for the
1630b57cec5SDimitry Andric// actual type change.
1640b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
1658bcb0991SDimitry Andric  defm: NopCast_pat<VecI8,   VecI16,  HvxVR>;
1668bcb0991SDimitry Andric  defm: NopCast_pat<VecI8,   VecI32,  HvxVR>;
1678bcb0991SDimitry Andric  defm: NopCast_pat<VecI16,  VecI32,  HvxVR>;
1680b57cec5SDimitry Andric
1698bcb0991SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPI16, HvxWR>;
1708bcb0991SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPI32, HvxWR>;
1718bcb0991SDimitry Andric  defm: NopCast_pat<VecPI16, VecPI32, HvxWR>;
1720b57cec5SDimitry Andric}
1730b57cec5SDimitry Andric
1740b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
175*e8d8bef9SDimitry Andric  let AddedComplexity = 100 in {
176*e8d8bef9SDimitry Andric    // These should be preferred over a vsplat of 0.
1770b57cec5SDimitry Andric    def: Pat<(VecI8   vzero), (V6_vd0)>;
1780b57cec5SDimitry Andric    def: Pat<(VecI16  vzero), (V6_vd0)>;
1790b57cec5SDimitry Andric    def: Pat<(VecI32  vzero), (V6_vd0)>;
1800b57cec5SDimitry Andric    def: Pat<(VecPI8  vzero), (PS_vdd0)>;
1810b57cec5SDimitry Andric    def: Pat<(VecPI16 vzero), (PS_vdd0)>;
1820b57cec5SDimitry Andric    def: Pat<(VecPI32 vzero), (PS_vdd0)>;
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric    def: Pat<(concat_vectors  (VecI8 vzero),  (VecI8 vzero)), (PS_vdd0)>;
1850b57cec5SDimitry Andric    def: Pat<(concat_vectors (VecI16 vzero), (VecI16 vzero)), (PS_vdd0)>;
1860b57cec5SDimitry Andric    def: Pat<(concat_vectors (VecI32 vzero), (VecI32 vzero)), (PS_vdd0)>;
187*e8d8bef9SDimitry Andric  }
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andric  def: Pat<(VecPI8 (concat_vectors HVI8:$Vs, HVI8:$Vt)),
1900b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
1910b57cec5SDimitry Andric  def: Pat<(VecPI16 (concat_vectors HVI16:$Vs, HVI16:$Vt)),
1920b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
1930b57cec5SDimitry Andric  def: Pat<(VecPI32 (concat_vectors HVI32:$Vs, HVI32:$Vt)),
1940b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric  def: Pat<(VecQ8  (qcat HQ16:$Qs, HQ16:$Qt)), (Combineq $Qt, $Qs)>;
1970b57cec5SDimitry Andric  def: Pat<(VecQ16 (qcat HQ32:$Qs, HQ32:$Qt)), (Combineq $Qt, $Qs)>;
1980b57cec5SDimitry Andric
1990b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI8:$Vu, I32:$Rs),
2000b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
2010b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI16:$Vu, I32:$Rs),
2020b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
2030b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI32:$Vu, I32:$Rs),
2040b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
2050b57cec5SDimitry Andric
2060b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI8:$Vu,  I32:$Rt),
2070b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
2080b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI16:$Vu, I32:$Rt),
2090b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
2100b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI32:$Vu, I32:$Rt),
2110b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
2120b57cec5SDimitry Andric}
2130b57cec5SDimitry Andric
214*e8d8bef9SDimitry Andric// Splats for HvxV60
215*e8d8bef9SDimitry Andricdef V60splatib: OutPatFrag<(ops node:$V),  (V6_lvsplatw (ToI32 (SplatB $V)))>;
216*e8d8bef9SDimitry Andricdef V60splatih: OutPatFrag<(ops node:$V),  (V6_lvsplatw (ToI32 (SplatH $V)))>;
217*e8d8bef9SDimitry Andricdef V60splatiw: OutPatFrag<(ops node:$V),  (V6_lvsplatw (ToI32 $V))>;
218*e8d8bef9SDimitry Andricdef V60splatrb: OutPatFrag<(ops node:$Rs), (V6_lvsplatw (S2_vsplatrb $Rs))>;
219*e8d8bef9SDimitry Andricdef V60splatrh: OutPatFrag<(ops node:$Rs),
2200b57cec5SDimitry Andric                           (V6_lvsplatw (A2_combine_ll $Rs, $Rs))>;
221*e8d8bef9SDimitry Andricdef V60splatrw: OutPatFrag<(ops node:$Rs), (V6_lvsplatw $Rs)>;
222*e8d8bef9SDimitry Andric
223*e8d8bef9SDimitry Andric// Splats for HvxV62+
224*e8d8bef9SDimitry Andricdef V62splatib: OutPatFrag<(ops node:$V),  (V6_lvsplatb (ToI32 $V))>;
225*e8d8bef9SDimitry Andricdef V62splatih: OutPatFrag<(ops node:$V),  (V6_lvsplath (ToI32 $V))>;
226*e8d8bef9SDimitry Andricdef V62splatiw: OutPatFrag<(ops node:$V),  (V6_lvsplatw (ToI32 $V))>;
227*e8d8bef9SDimitry Andricdef V62splatrb: OutPatFrag<(ops node:$Rs), (V6_lvsplatb $Rs)>;
228*e8d8bef9SDimitry Andricdef V62splatrh: OutPatFrag<(ops node:$Rs), (V6_lvsplath $Rs)>;
229*e8d8bef9SDimitry Andricdef V62splatrw: OutPatFrag<(ops node:$Rs), (V6_lvsplatw $Rs)>;
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andricdef Rep: OutPatFrag<(ops node:$N), (Combinev $N, $N)>;
2320b57cec5SDimitry Andric
233*e8d8bef9SDimitry Andriclet Predicates = [UseHVX,UseHVXV60] in {
2340b57cec5SDimitry Andric  let AddedComplexity = 10 in {
235*e8d8bef9SDimitry Andric    def: Pat<(VecI8   (splat_vector u8_0ImmPred:$V)),  (V60splatib $V)>;
236*e8d8bef9SDimitry Andric    def: Pat<(VecI16  (splat_vector u16_0ImmPred:$V)), (V60splatih $V)>;
237*e8d8bef9SDimitry Andric    def: Pat<(VecI32  (splat_vector anyimm:$V)),       (V60splatiw $V)>;
238*e8d8bef9SDimitry Andric    def: Pat<(VecPI8  (splat_vector u8_0ImmPred:$V)),  (Rep (V60splatib $V))>;
239*e8d8bef9SDimitry Andric    def: Pat<(VecPI16 (splat_vector u16_0ImmPred:$V)), (Rep (V60splatih $V))>;
240*e8d8bef9SDimitry Andric    def: Pat<(VecPI32 (splat_vector anyimm:$V)),       (Rep (V60splatiw $V))>;
2410b57cec5SDimitry Andric  }
242*e8d8bef9SDimitry Andric  def: Pat<(VecI8   (splat_vector I32:$Rs)), (V60splatrb $Rs)>;
243*e8d8bef9SDimitry Andric  def: Pat<(VecI16  (splat_vector I32:$Rs)), (V60splatrh $Rs)>;
244*e8d8bef9SDimitry Andric  def: Pat<(VecI32  (splat_vector I32:$Rs)), (V60splatrw $Rs)>;
245*e8d8bef9SDimitry Andric  def: Pat<(VecPI8  (splat_vector I32:$Rs)), (Rep (V60splatrb $Rs))>;
246*e8d8bef9SDimitry Andric  def: Pat<(VecPI16 (splat_vector I32:$Rs)), (Rep (V60splatrh $Rs))>;
247*e8d8bef9SDimitry Andric  def: Pat<(VecPI32 (splat_vector I32:$Rs)), (Rep (V60splatrw $Rs))>;
248*e8d8bef9SDimitry Andric}
249*e8d8bef9SDimitry Andriclet Predicates = [UseHVX,UseHVXV62] in {
250*e8d8bef9SDimitry Andric  let AddedComplexity = 30 in {
251*e8d8bef9SDimitry Andric    def: Pat<(VecI8   (splat_vector u8_0ImmPred:$V)),  (V62splatib imm:$V)>;
252*e8d8bef9SDimitry Andric    def: Pat<(VecI16  (splat_vector u16_0ImmPred:$V)), (V62splatih imm:$V)>;
253*e8d8bef9SDimitry Andric    def: Pat<(VecI32  (splat_vector anyimm:$V)),       (V62splatiw imm:$V)>;
254*e8d8bef9SDimitry Andric    def: Pat<(VecPI8  (splat_vector u8_0ImmPred:$V)),
255*e8d8bef9SDimitry Andric             (Rep (V62splatib imm:$V))>;
256*e8d8bef9SDimitry Andric    def: Pat<(VecPI16 (splat_vector u16_0ImmPred:$V)),
257*e8d8bef9SDimitry Andric             (Rep (V62splatih imm:$V))>;
258*e8d8bef9SDimitry Andric    def: Pat<(VecPI32 (splat_vector anyimm:$V)),
259*e8d8bef9SDimitry Andric             (Rep (V62splatiw imm:$V))>;
260*e8d8bef9SDimitry Andric  }
261*e8d8bef9SDimitry Andric  let AddedComplexity = 20 in {
262*e8d8bef9SDimitry Andric    def: Pat<(VecI8   (splat_vector I32:$Rs)), (V62splatrb $Rs)>;
263*e8d8bef9SDimitry Andric    def: Pat<(VecI16  (splat_vector I32:$Rs)), (V62splatrh $Rs)>;
264*e8d8bef9SDimitry Andric    def: Pat<(VecI32  (splat_vector I32:$Rs)), (V62splatrw $Rs)>;
265*e8d8bef9SDimitry Andric    def: Pat<(VecPI8  (splat_vector I32:$Rs)), (Rep (V62splatrb $Rs))>;
266*e8d8bef9SDimitry Andric    def: Pat<(VecPI16 (splat_vector I32:$Rs)), (Rep (V62splatrh $Rs))>;
267*e8d8bef9SDimitry Andric    def: Pat<(VecPI32 (splat_vector I32:$Rs)), (Rep (V62splatrw $Rs))>;
268*e8d8bef9SDimitry Andric  }
2690b57cec5SDimitry Andric}
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andricclass Vneg1<ValueType VecTy>
272*e8d8bef9SDimitry Andric  : PatFrag<(ops), (VecTy (splat_vector (i32 -1)))>;
2730b57cec5SDimitry Andric
2740b57cec5SDimitry Andricclass Vnot<ValueType VecTy>
2750b57cec5SDimitry Andric  : PatFrag<(ops node:$Vs), (xor $Vs, Vneg1<VecTy>)>;
2760b57cec5SDimitry Andric
2770b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
2780b57cec5SDimitry Andric  let AddedComplexity = 200 in {
2790b57cec5SDimitry Andric    def: Pat<(Vnot<VecI8>   HVI8:$Vs), (V6_vnot HvxVR:$Vs)>;
2800b57cec5SDimitry Andric    def: Pat<(Vnot<VecI16> HVI16:$Vs), (V6_vnot HvxVR:$Vs)>;
2810b57cec5SDimitry Andric    def: Pat<(Vnot<VecI32> HVI32:$Vs), (V6_vnot HvxVR:$Vs)>;
2820b57cec5SDimitry Andric  }
2830b57cec5SDimitry Andric
2840b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddb,    Add,   VecI8,  HVI8>;
2850b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddh,    Add,  VecI16, HVI16>;
2860b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddw,    Add,  VecI32, HVI32>;
2870b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddb_dv, Add,  VecPI8,  HWI8>;
2880b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddh_dv, Add, VecPI16, HWI16>;
2890b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddw_dv, Add, VecPI32, HWI32>;
2900b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubb,    Sub,   VecI8,  HVI8>;
2910b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubh,    Sub,  VecI16, HVI16>;
2920b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubw,    Sub,  VecI32, HVI32>;
2930b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubb_dv, Sub,  VecPI8,  HWI8>;
2940b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubh_dv, Sub, VecPI16, HWI16>;
2950b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubw_dv, Sub, VecPI32, HWI32>;
2960b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,   VecI8,  HVI8>;
2970b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,  VecI16, HVI16>;
2980b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,  VecI32, HVI32>;
2990b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,   VecI8,  HVI8>;
3000b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,  VecI16, HVI16>;
3010b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,  VecI32, HVI32>;
3020b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,   VecI8,  HVI8>;
3030b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,  VecI16, HVI16>;
3040b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,  VecI32, HVI32>;
3050b57cec5SDimitry Andric
306*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminb,   Smin,   VecI8,  HVI8>;
307*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxb,   Smax,   VecI8,  HVI8>;
308*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminub,  Umin,   VecI8,  HVI8>;
309*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxub,  Umax,   VecI8,  HVI8>;
310*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminh,   Smin,  VecI16, HVI16>;
311*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxh,   Smax,  VecI16, HVI16>;
312*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminuh,  Umin,  VecI16, HVI16>;
313*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxuh,  Umax,  VecI16, HVI16>;
314*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminw,   Smin,  VecI32, HVI32>;
315*e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxw,   Smax,  VecI32, HVI32>;
316*e8d8bef9SDimitry Andric
3170b57cec5SDimitry Andric  def: Pat<(vselect HQ8:$Qu, HVI8:$Vs, HVI8:$Vt),
3180b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
3190b57cec5SDimitry Andric  def: Pat<(vselect HQ16:$Qu, HVI16:$Vs, HVI16:$Vt),
3200b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
3210b57cec5SDimitry Andric  def: Pat<(vselect HQ32:$Qu, HVI32:$Vs, HVI32:$Vt),
3220b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
3230b57cec5SDimitry Andric
3240b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ8:$Qu), HVI8:$Vs, HVI8:$Vt),
3250b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
3260b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ16:$Qu), HVI16:$Vs, HVI16:$Vt),
3270b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
3280b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ32:$Qu), HVI32:$Vs, HVI32:$Vt),
3290b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
3300b57cec5SDimitry Andric}
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
333*e8d8bef9SDimitry Andric  // For i8 vectors Vs = (a0, a1, ...), Vt = (b0, b1, ...),
334*e8d8bef9SDimitry Andric  // V6_vmpybv Vs, Vt produces a pair of i16 vectors Hi:Lo,
335*e8d8bef9SDimitry Andric  // where Lo = (a0*b0, a2*b2, ...), Hi = (a1*b1, a3*b3, ...).
336*e8d8bef9SDimitry Andric  def: Pat<(mul HVI8:$Vs, HVI8:$Vt),
337*e8d8bef9SDimitry Andric           (V6_vshuffeb (HiVec (V6_vmpybv HvxVR:$Vs, HvxVR:$Vt)),
338*e8d8bef9SDimitry Andric                        (LoVec (V6_vmpybv HvxVR:$Vs, HvxVR:$Vt)))>;
339*e8d8bef9SDimitry Andric  def: Pat<(mul HVI16:$Vs, HVI16:$Vt),
340*e8d8bef9SDimitry Andric           (V6_vmpyih HvxVR:$Vs, HvxVR:$Vt)>;
341*e8d8bef9SDimitry Andric  def: Pat<(mul HVI32:$Vs, HVI32:$Vt),
342*e8d8bef9SDimitry Andric           (V6_vmpyiewuh_acc (V6_vmpyieoh HvxVR:$Vs, HvxVR:$Vt),
343*e8d8bef9SDimitry Andric                             HvxVR:$Vs, HvxVR:$Vt)>;
344*e8d8bef9SDimitry Andric}
345*e8d8bef9SDimitry Andric
346*e8d8bef9SDimitry Andriclet Predicates = [UseHVX] in {
3470b57cec5SDimitry Andric  def: Pat<(VecPI16 (sext HVI8:$Vs)),  (VSxtb $Vs)>;
3480b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext HVI16:$Vs)), (VSxth $Vs)>;
3490b57cec5SDimitry Andric  def: Pat<(VecPI16 (zext HVI8:$Vs)),  (VZxtb $Vs)>;
3500b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext HVI16:$Vs)), (VZxth $Vs)>;
3510b57cec5SDimitry Andric
3520b57cec5SDimitry Andric  def: Pat<(VecI16 (sext_invec HVI8:$Vs)),  (LoVec (VSxtb $Vs))>;
3530b57cec5SDimitry Andric  def: Pat<(VecI32 (sext_invec HVI16:$Vs)), (LoVec (VSxth $Vs))>;
3540b57cec5SDimitry Andric  def: Pat<(VecI32 (sext_invec HVI8:$Vs)),
3550b57cec5SDimitry Andric           (LoVec (VSxth (LoVec (VSxtb $Vs))))>;
3560b57cec5SDimitry Andric  def: Pat<(VecPI16 (sext_invec HWI8:$Vss)),  (VSxtb (LoVec $Vss))>;
3570b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext_invec HWI16:$Vss)), (VSxth (LoVec $Vss))>;
3580b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext_invec HWI8:$Vss)),
3590b57cec5SDimitry Andric           (VSxth (LoVec (VSxtb (LoVec $Vss))))>;
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andric  def: Pat<(VecI16 (zext_invec HVI8:$Vs)),  (LoVec (VZxtb $Vs))>;
3620b57cec5SDimitry Andric  def: Pat<(VecI32 (zext_invec HVI16:$Vs)), (LoVec (VZxth $Vs))>;
3630b57cec5SDimitry Andric  def: Pat<(VecI32 (zext_invec HVI8:$Vs)),
3640b57cec5SDimitry Andric           (LoVec (VZxth (LoVec (VZxtb $Vs))))>;
3650b57cec5SDimitry Andric  def: Pat<(VecPI16 (zext_invec HWI8:$Vss)),  (VZxtb (LoVec $Vss))>;
3660b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext_invec HWI16:$Vss)), (VZxth (LoVec $Vss))>;
3670b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext_invec HWI8:$Vss)),
3680b57cec5SDimitry Andric           (VZxth (LoVec (VZxtb (LoVec $Vss))))>;
3690b57cec5SDimitry Andric
3700b57cec5SDimitry Andric  def: Pat<(VecI8 (trunc HWI16:$Vss)),
3710b57cec5SDimitry Andric           (V6_vpackeb (HiVec $Vss), (LoVec $Vss))>;
3720b57cec5SDimitry Andric  def: Pat<(VecI16 (trunc HWI32:$Vss)),
3730b57cec5SDimitry Andric           (V6_vpackeh (HiVec $Vss), (LoVec $Vss))>;
3740b57cec5SDimitry Andric
3750b57cec5SDimitry Andric  def: Pat<(VecQ8 (trunc HVI8:$Vs)),
3760b57cec5SDimitry Andric           (V6_vandvrt HvxVR:$Vs, (A2_tfrsi 0x01010101))>;
3770b57cec5SDimitry Andric  def: Pat<(VecQ16 (trunc HVI16:$Vs)),
3780b57cec5SDimitry Andric           (V6_vandvrt HvxVR:$Vs, (A2_tfrsi 0x01010101))>;
3790b57cec5SDimitry Andric  def: Pat<(VecQ32 (trunc HVI32:$Vs)),
3800b57cec5SDimitry Andric           (V6_vandvrt HvxVR:$Vs, (A2_tfrsi 0x01010101))>;
3810b57cec5SDimitry Andric}
3820b57cec5SDimitry Andric
3830b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
3840b57cec5SDimitry Andric  // The "source" types are not legal, and there are no parameterized
3850b57cec5SDimitry Andric  // definitions for them, but they are length-specific.
3860b57cec5SDimitry Andric  let Predicates = [UseHVX,UseHVX64B] in {
3870b57cec5SDimitry Andric    def: Pat<(VecI16 (sext_inreg HVI16:$Vs, v32i8)),
3880b57cec5SDimitry Andric             (V6_vasrh (V6_vaslh HVI16:$Vs, (A2_tfrsi 8)), (A2_tfrsi 8))>;
3890b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v16i8)),
3900b57cec5SDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (A2_tfrsi 24)), (A2_tfrsi 24))>;
3910b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v16i16)),
3920b57cec5SDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (A2_tfrsi 16)), (A2_tfrsi 16))>;
3930b57cec5SDimitry Andric  }
3940b57cec5SDimitry Andric  let Predicates = [UseHVX,UseHVX128B] in {
3950b57cec5SDimitry Andric    def: Pat<(VecI16 (sext_inreg HVI16:$Vs, v64i8)),
3960b57cec5SDimitry Andric             (V6_vasrh (V6_vaslh HVI16:$Vs, (A2_tfrsi 8)), (A2_tfrsi 8))>;
3970b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v32i8)),
3980b57cec5SDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (A2_tfrsi 24)), (A2_tfrsi 24))>;
3990b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v32i16)),
4000b57cec5SDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (A2_tfrsi 16)), (A2_tfrsi 16))>;
4010b57cec5SDimitry Andric  }
4020b57cec5SDimitry Andric
403*e8d8bef9SDimitry Andric  // Take a pair of vectors Vt:Vs and shift them towards LSB by (Rt & HwLen).
404*e8d8bef9SDimitry Andric  def: Pat<(VecI8 (valign HVI8:$Vt, HVI8:$Vs, I32:$Rt)),
405*e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
406*e8d8bef9SDimitry Andric  def: Pat<(VecI16 (valign HVI16:$Vt, HVI16:$Vs, I32:$Rt)),
407*e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
408*e8d8bef9SDimitry Andric  def: Pat<(VecI32 (valign HVI32:$Vt, HVI32:$Vs, I32:$Rt)),
409*e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
410*e8d8bef9SDimitry Andric
4110b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI8:$Vs, I32:$Rt),
4120b57cec5SDimitry Andric           (V6_vpackeb (V6_vaslh (HiVec (VZxtb HvxVR:$Vs)), I32:$Rt),
4130b57cec5SDimitry Andric                       (V6_vaslh (LoVec (VZxtb HvxVR:$Vs)), I32:$Rt))>;
4140b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI8:$Vs, I32:$Rt),
4150b57cec5SDimitry Andric           (V6_vpackeb (V6_vasrh (HiVec (VSxtb HvxVR:$Vs)), I32:$Rt),
4160b57cec5SDimitry Andric                       (V6_vasrh (LoVec (VSxtb HvxVR:$Vs)), I32:$Rt))>;
4170b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI8:$Vs, I32:$Rt),
4180b57cec5SDimitry Andric           (V6_vpackeb (V6_vlsrh (HiVec (VZxtb HvxVR:$Vs)), I32:$Rt),
4190b57cec5SDimitry Andric                       (V6_vlsrh (LoVec (VZxtb HvxVR:$Vs)), I32:$Rt))>;
4200b57cec5SDimitry Andric
4210b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI16:$Vs, I32:$Rt), (V6_vaslh HvxVR:$Vs, I32:$Rt)>;
4220b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI32:$Vs, I32:$Rt), (V6_vaslw HvxVR:$Vs, I32:$Rt)>;
4230b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI16:$Vs, I32:$Rt), (V6_vasrh HvxVR:$Vs, I32:$Rt)>;
4240b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI32:$Vs, I32:$Rt), (V6_vasrw HvxVR:$Vs, I32:$Rt)>;
4250b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI16:$Vs, I32:$Rt), (V6_vlsrh HvxVR:$Vs, I32:$Rt)>;
4260b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI32:$Vs, I32:$Rt), (V6_vlsrw HvxVR:$Vs, I32:$Rt)>;
4270b57cec5SDimitry Andric
4280b57cec5SDimitry Andric  def: Pat<(add HVI32:$Vx, (HexagonVASL HVI32:$Vu, I32:$Rt)),
4290b57cec5SDimitry Andric           (V6_vaslw_acc HvxVR:$Vx, HvxVR:$Vu, I32:$Rt)>;
4300b57cec5SDimitry Andric  def: Pat<(add HVI32:$Vx, (HexagonVASR HVI32:$Vu, I32:$Rt)),
4310b57cec5SDimitry Andric           (V6_vasrw_acc HvxVR:$Vx, HvxVR:$Vu, I32:$Rt)>;
4320b57cec5SDimitry Andric
4330b57cec5SDimitry Andric  def: Pat<(shl HVI16:$Vs, HVI16:$Vt), (V6_vaslhv HvxVR:$Vs, HvxVR:$Vt)>;
4340b57cec5SDimitry Andric  def: Pat<(shl HVI32:$Vs, HVI32:$Vt), (V6_vaslwv HvxVR:$Vs, HvxVR:$Vt)>;
4350b57cec5SDimitry Andric  def: Pat<(sra HVI16:$Vs, HVI16:$Vt), (V6_vasrhv HvxVR:$Vs, HvxVR:$Vt)>;
4360b57cec5SDimitry Andric  def: Pat<(sra HVI32:$Vs, HVI32:$Vt), (V6_vasrwv HvxVR:$Vs, HvxVR:$Vt)>;
4370b57cec5SDimitry Andric  def: Pat<(srl HVI16:$Vs, HVI16:$Vt), (V6_vlsrhv HvxVR:$Vs, HvxVR:$Vt)>;
4380b57cec5SDimitry Andric  def: Pat<(srl HVI32:$Vs, HVI32:$Vt), (V6_vlsrwv HvxVR:$Vs, HvxVR:$Vt)>;
4390b57cec5SDimitry Andric
440*e8d8bef9SDimitry Andric  // Vpackl is a pseudo-op that is used when legalizing widened truncates.
441*e8d8bef9SDimitry Andric  // It should never be produced with a register pair in the output, but
442*e8d8bef9SDimitry Andric  // it can happen to have a pair as an input.
443*e8d8bef9SDimitry Andric  def: Pat<(VecI8  (vpackl HVI16:$Vs)), (V6_vdealb HvxVR:$Vs)>;
444*e8d8bef9SDimitry Andric  def: Pat<(VecI8  (vpackl HVI32:$Vs)), (V6_vdealb4w (IMPLICIT_DEF), HvxVR:$Vs)>;
445*e8d8bef9SDimitry Andric  def: Pat<(VecI16 (vpackl HVI32:$Vs)), (V6_vdealh HvxVR:$Vs)>;
446*e8d8bef9SDimitry Andric  def: Pat<(VecI8  (vpackl HWI16:$Vs)), (V6_vpackeb (HiVec $Vs), (LoVec $Vs))>;
447*e8d8bef9SDimitry Andric  def: Pat<(VecI8  (vpackl HWI32:$Vs)),
448*e8d8bef9SDimitry Andric           (V6_vpackeb (IMPLICIT_DEF), (V6_vpackeh (HiVec $Vs), (LoVec $Vs)))>;
449*e8d8bef9SDimitry Andric  def: Pat<(VecI16 (vpackl HWI32:$Vs)), (V6_vpackeh (HiVec $Vs), (LoVec $Vs))>;
450*e8d8bef9SDimitry Andric
451*e8d8bef9SDimitry Andric  def: Pat<(VecI16  (vunpack   HVI8:$Vs)), (LoVec (VSxtb $Vs))>;
452*e8d8bef9SDimitry Andric  def: Pat<(VecI32  (vunpack   HVI8:$Vs)), (LoVec (VSxth (LoVec (VSxtb $Vs))))>;
453*e8d8bef9SDimitry Andric  def: Pat<(VecI32  (vunpack  HVI16:$Vs)), (LoVec (VSxth $Vs))>;
454*e8d8bef9SDimitry Andric  def: Pat<(VecPI16 (vunpack   HVI8:$Vs)), (VSxtb $Vs)>;
455*e8d8bef9SDimitry Andric  def: Pat<(VecPI32 (vunpack   HVI8:$Vs)), (VSxth (LoVec (VSxtb $Vs)))>;
456*e8d8bef9SDimitry Andric  def: Pat<(VecPI32 (vunpack  HVI32:$Vs)), (VSxth $Vs)>;
457*e8d8bef9SDimitry Andric
458*e8d8bef9SDimitry Andric  def: Pat<(VecI16  (vunpacku  HVI8:$Vs)), (LoVec (VZxtb $Vs))>;
459*e8d8bef9SDimitry Andric  def: Pat<(VecI32  (vunpacku  HVI8:$Vs)), (LoVec (VZxth (LoVec (VZxtb $Vs))))>;
460*e8d8bef9SDimitry Andric  def: Pat<(VecI32  (vunpacku HVI16:$Vs)), (LoVec (VZxth $Vs))>;
461*e8d8bef9SDimitry Andric  def: Pat<(VecPI16 (vunpacku  HVI8:$Vs)), (VZxtb $Vs)>;
462*e8d8bef9SDimitry Andric  def: Pat<(VecPI32 (vunpacku  HVI8:$Vs)), (VZxth (LoVec (VZxtb $Vs)))>;
463*e8d8bef9SDimitry Andric  def: Pat<(VecPI32 (vunpacku HVI32:$Vs)), (VZxth $Vs)>;
464*e8d8bef9SDimitry Andric
465*e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV60] in {
4660b57cec5SDimitry Andric    def: Pat<(VecI16 (bswap HVI16:$Vs)),
467*e8d8bef9SDimitry Andric             (V6_vdelta HvxVR:$Vs, (V60splatib (i32 0x01)))>;
4680b57cec5SDimitry Andric    def: Pat<(VecI32 (bswap HVI32:$Vs)),
469*e8d8bef9SDimitry Andric             (V6_vdelta HvxVR:$Vs, (V60splatib (i32 0x03)))>;
470*e8d8bef9SDimitry Andric  }
471*e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV62], AddedComplexity = 10 in {
472*e8d8bef9SDimitry Andric    def: Pat<(VecI16 (bswap HVI16:$Vs)),
473*e8d8bef9SDimitry Andric             (V6_vdelta HvxVR:$Vs, (V62splatib (i32 0x01)))>;
474*e8d8bef9SDimitry Andric    def: Pat<(VecI32 (bswap HVI32:$Vs)),
475*e8d8bef9SDimitry Andric             (V6_vdelta HvxVR:$Vs, (V62splatib (i32 0x03)))>;
476*e8d8bef9SDimitry Andric  }
4770b57cec5SDimitry Andric
4780b57cec5SDimitry Andric  def: Pat<(VecI8 (ctpop HVI8:$Vs)),
4790b57cec5SDimitry Andric           (V6_vpackeb (V6_vpopcounth (HiVec (V6_vunpackub HvxVR:$Vs))),
4800b57cec5SDimitry Andric                       (V6_vpopcounth (LoVec (V6_vunpackub HvxVR:$Vs))))>;
4810b57cec5SDimitry Andric  def: Pat<(VecI16 (ctpop HVI16:$Vs)), (V6_vpopcounth HvxVR:$Vs)>;
4820b57cec5SDimitry Andric  def: Pat<(VecI32 (ctpop HVI32:$Vs)),
4830b57cec5SDimitry Andric           (V6_vaddw (LoVec (V6_vzh (V6_vpopcounth HvxVR:$Vs))),
4840b57cec5SDimitry Andric                     (HiVec (V6_vzh (V6_vpopcounth HvxVR:$Vs))))>;
4850b57cec5SDimitry Andric
486*e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV60] in
4870b57cec5SDimitry Andric  def: Pat<(VecI8 (ctlz HVI8:$Vs)),
4880b57cec5SDimitry Andric           (V6_vsubb (V6_vpackeb (V6_vcl0h (HiVec (V6_vunpackub HvxVR:$Vs))),
4890b57cec5SDimitry Andric                                 (V6_vcl0h (LoVec (V6_vunpackub HvxVR:$Vs)))),
490*e8d8bef9SDimitry Andric                     (V60splatib (i32 0x08)))>;
491*e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV62], AddedComplexity = 10 in
492*e8d8bef9SDimitry Andric  def: Pat<(VecI8 (ctlz HVI8:$Vs)),
493*e8d8bef9SDimitry Andric           (V6_vsubb (V6_vpackeb (V6_vcl0h (HiVec (V6_vunpackub HvxVR:$Vs))),
494*e8d8bef9SDimitry Andric                                 (V6_vcl0h (LoVec (V6_vunpackub HvxVR:$Vs)))),
495*e8d8bef9SDimitry Andric                     (V62splatib (i32 0x08)))>;
496*e8d8bef9SDimitry Andric
4970b57cec5SDimitry Andric  def: Pat<(VecI16 (ctlz HVI16:$Vs)), (V6_vcl0h HvxVR:$Vs)>;
4980b57cec5SDimitry Andric  def: Pat<(VecI32 (ctlz HVI32:$Vs)), (V6_vcl0w HvxVR:$Vs)>;
4990b57cec5SDimitry Andric}
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andricclass HvxSel_pat<InstHexagon MI, PatFrag RegPred>
5020b57cec5SDimitry Andric  : Pat<(select I1:$Pu, RegPred:$Vs, RegPred:$Vt),
5030b57cec5SDimitry Andric        (MI I1:$Pu, RegPred:$Vs, RegPred:$Vt)>;
5040b57cec5SDimitry Andric
5050b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
5060b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI8>;
5070b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI16>;
5080b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI32>;
5090b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI8>;
5100b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI16>;
5110b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI32>;
5120b57cec5SDimitry Andric}
5130b57cec5SDimitry Andric
5140b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
5150b57cec5SDimitry Andric  def: Pat<(VecQ8   (qtrue)), (PS_qtrue)>;
5160b57cec5SDimitry Andric  def: Pat<(VecQ16  (qtrue)), (PS_qtrue)>;
5170b57cec5SDimitry Andric  def: Pat<(VecQ32  (qtrue)), (PS_qtrue)>;
5180b57cec5SDimitry Andric  def: Pat<(VecQ8  (qfalse)), (PS_qfalse)>;
5190b57cec5SDimitry Andric  def: Pat<(VecQ16 (qfalse)), (PS_qfalse)>;
5200b57cec5SDimitry Andric  def: Pat<(VecQ32 (qfalse)), (PS_qfalse)>;
5210b57cec5SDimitry Andric
5220b57cec5SDimitry Andric  def: Pat<(vnot  HQ8:$Qs), (V6_pred_not HvxQR:$Qs)>;
5230b57cec5SDimitry Andric  def: Pat<(vnot HQ16:$Qs), (V6_pred_not HvxQR:$Qs)>;
5240b57cec5SDimitry Andric  def: Pat<(vnot HQ32:$Qs), (V6_pred_not HvxQR:$Qs)>;
5250b57cec5SDimitry Andric  def: Pat<(qnot  HQ8:$Qs), (V6_pred_not HvxQR:$Qs)>;
5260b57cec5SDimitry Andric  def: Pat<(qnot HQ16:$Qs), (V6_pred_not HvxQR:$Qs)>;
5270b57cec5SDimitry Andric  def: Pat<(qnot HQ32:$Qs), (V6_pred_not HvxQR:$Qs)>;
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,         And,  VecQ8,   HQ8>;
5300b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,         And, VecQ16,  HQ16>;
5310b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,         And, VecQ32,  HQ32>;
5320b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,           Or,  VecQ8,   HQ8>;
5330b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,           Or, VecQ16,  HQ16>;
5340b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,           Or, VecQ32,  HQ32>;
5350b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,         Xor,  VecQ8,   HQ8>;
5360b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,         Xor, VecQ16,  HQ16>;
5370b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,         Xor, VecQ32,  HQ32>;
5380b57cec5SDimitry Andric
5390b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n, Not2<And>,  VecQ8,   HQ8>;
5400b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n, Not2<And>, VecQ16,  HQ16>;
5410b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n, Not2<And>, VecQ32,  HQ32>;
5420b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,   Not2<Or>,  VecQ8,   HQ8>;
5430b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,   Not2<Or>, VecQ16,  HQ16>;
5440b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,   Not2<Or>, VecQ32,  HQ32>;
5450b57cec5SDimitry Andric
5460b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqb,              seteq,  VecQ8,  HVI8>;
5470b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqh,              seteq, VecQ16, HVI16>;
5480b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqw,              seteq, VecQ32, HVI32>;
5490b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtb,              setgt,  VecQ8,  HVI8>;
5500b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgth,              setgt, VecQ16, HVI16>;
5510b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtw,              setgt, VecQ32, HVI32>;
5520b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtub,            setugt,  VecQ8,  HVI8>;
5530b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtuh,            setugt, VecQ16, HVI16>;
5540b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtuw,            setugt, VecQ32, HVI32>;
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_and,    And,  seteq,    HQ8,  HVI8,  HVI8>;
5570b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_or,      Or,  seteq,    HQ8,  HVI8,  HVI8>;
5580b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_xor,    Xor,  seteq,    HQ8,  HVI8,  HVI8>;
5590b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_and,    And,  seteq,   HQ16, HVI16, HVI16>;
5600b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_or,      Or,  seteq,   HQ16, HVI16, HVI16>;
5610b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_xor,    Xor,  seteq,   HQ16, HVI16, HVI16>;
5620b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_and,    And,  seteq,   HQ32, HVI32, HVI32>;
5630b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_or,      Or,  seteq,   HQ32, HVI32, HVI32>;
5640b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_xor,    Xor,  seteq,   HQ32, HVI32, HVI32>;
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_and,    And,  setgt,    HQ8,  HVI8,  HVI8>;
5670b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_or,      Or,  setgt,    HQ8,  HVI8,  HVI8>;
5680b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_xor,    Xor,  setgt,    HQ8,  HVI8,  HVI8>;
5690b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_and,    And,  setgt,   HQ16, HVI16, HVI16>;
5700b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_or,      Or,  setgt,   HQ16, HVI16, HVI16>;
5710b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_xor,    Xor,  setgt,   HQ16, HVI16, HVI16>;
5720b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_and,    And,  setgt,   HQ32, HVI32, HVI32>;
5730b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_or,      Or,  setgt,   HQ32, HVI32, HVI32>;
5740b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_xor,    Xor,  setgt,   HQ32, HVI32, HVI32>;
5750b57cec5SDimitry Andric
5760b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_and,   And, setugt,    HQ8,  HVI8,  HVI8>;
5770b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_or,     Or, setugt,    HQ8,  HVI8,  HVI8>;
5780b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_xor,   Xor, setugt,    HQ8,  HVI8,  HVI8>;
5790b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_and,   And, setugt,   HQ16, HVI16, HVI16>;
5800b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_or,     Or, setugt,   HQ16, HVI16, HVI16>;
5810b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_xor,   Xor, setugt,   HQ16, HVI16, HVI16>;
5820b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_and,   And, setugt,   HQ32, HVI32, HVI32>;
5830b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_or,     Or, setugt,   HQ32, HVI32, HVI32>;
5840b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_xor,   Xor, setugt,   HQ32, HVI32, HVI32>;
5850b57cec5SDimitry Andric}
586