xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1e8d8bef9SDimitry Andric//===- HexagonPatternsHVX.td - Selection Patterns for HVX --*- tablegen -*-===//
2e8d8bef9SDimitry Andric//
3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric//
7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric
904eeddc0SDimitry Andricdef HQ8:    PatLeaf<(VecQ8   HvxQR:$R)>;
1004eeddc0SDimitry Andricdef HQ16:   PatLeaf<(VecQ16  HvxQR:$R)>;
1104eeddc0SDimitry Andricdef HQ32:   PatLeaf<(VecQ32  HvxQR:$R)>;
1204eeddc0SDimitry Andric
1304eeddc0SDimitry Andricdef HVI8:   PatLeaf<(VecI8   HvxVR:$R)>;
1404eeddc0SDimitry Andricdef HVI16:  PatLeaf<(VecI16  HvxVR:$R)>;
1504eeddc0SDimitry Andricdef HVI32:  PatLeaf<(VecI32  HvxVR:$R)>;
1604eeddc0SDimitry Andricdef HVF16:  PatLeaf<(VecF16  HvxVR:$R)>;
1704eeddc0SDimitry Andricdef HVF32:  PatLeaf<(VecF32  HvxVR:$R)>;
1804eeddc0SDimitry Andric
1904eeddc0SDimitry Andricdef HWI8:   PatLeaf<(VecPI8  HvxWR:$R)>;
2004eeddc0SDimitry Andricdef HWI16:  PatLeaf<(VecPI16 HvxWR:$R)>;
2104eeddc0SDimitry Andricdef HWI32:  PatLeaf<(VecPI32 HvxWR:$R)>;
2204eeddc0SDimitry Andricdef HWF16:  PatLeaf<(VecPF16 HvxWR:$R)>;
2304eeddc0SDimitry Andricdef HWF32:  PatLeaf<(VecPF32 HvxWR:$R)>;
24e8d8bef9SDimitry Andric
25e8d8bef9SDimitry Andricdef SDTVecUnaryOp:
26e8d8bef9SDimitry Andric  SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
27e8d8bef9SDimitry Andric
280b57cec5SDimitry Andricdef SDTVecBinOp:
290b57cec5SDimitry Andric  SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<1,2>]>;
300b57cec5SDimitry Andric
310b57cec5SDimitry Andricdef SDTHexagonVEXTRACTW: SDTypeProfile<1, 2,
320b57cec5SDimitry Andric  [SDTCisVT<0, i32>, SDTCisVec<1>, SDTCisVT<2, i32>]>;
330b57cec5SDimitry Andricdef HexagonVEXTRACTW : SDNode<"HexagonISD::VEXTRACTW", SDTHexagonVEXTRACTW>;
340b57cec5SDimitry Andric
350b57cec5SDimitry Andricdef SDTHexagonVINSERTW0: SDTypeProfile<1, 2,
360b57cec5SDimitry Andric  [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, i32>]>;
370b57cec5SDimitry Andricdef HexagonVINSERTW0: SDNode<"HexagonISD::VINSERTW0", SDTHexagonVINSERTW0>;
380b57cec5SDimitry Andric
390b57cec5SDimitry Andricdef HwLen2: SDNodeXForm<imm, [{
4081ad6265SDimitry Andric  const auto &ST = CurDAG->getSubtarget<HexagonSubtarget>();
410b57cec5SDimitry Andric  return CurDAG->getTargetConstant(ST.getVectorLength()/2, SDLoc(N), MVT::i32);
420b57cec5SDimitry Andric}]>;
430b57cec5SDimitry Andric
44*bdd1243dSDimitry Andricdef Q2V: OutPatFrag<(ops node:$Qs), (V6_vandqrt $Qs, (ToI32 -1))>;
450b57cec5SDimitry Andric
460b57cec5SDimitry Andricdef Combinev: OutPatFrag<(ops node:$Vs, node:$Vt),
470b57cec5SDimitry Andric  (REG_SEQUENCE HvxWR, $Vs, vsub_hi, $Vt, vsub_lo)>;
480b57cec5SDimitry Andric
490b57cec5SDimitry Andricdef Combineq: OutPatFrag<(ops node:$Qs, node:$Qt),
500b57cec5SDimitry Andric  (V6_vandvrt
510b57cec5SDimitry Andric    (V6_vor
520b57cec5SDimitry Andric      (V6_vror (V6_vpackeb (V6_vd0), (Q2V $Qs)),
53*bdd1243dSDimitry Andric               (ToI32 (HwLen2 (i32 0)))),  // Half the vector length
540b57cec5SDimitry Andric      (V6_vpackeb (V6_vd0), (Q2V $Qt))),
55*bdd1243dSDimitry Andric    (ToI32 -1))>;
560b57cec5SDimitry Andric
570b57cec5SDimitry Andricdef LoVec: OutPatFrag<(ops node:$Vs), (EXTRACT_SUBREG $Vs, vsub_lo)>;
580b57cec5SDimitry Andricdef HiVec: OutPatFrag<(ops node:$Vs), (EXTRACT_SUBREG $Vs, vsub_hi)>;
590b57cec5SDimitry Andric
600b57cec5SDimitry Andricdef HexagonQCAT:       SDNode<"HexagonISD::QCAT",       SDTVecBinOp>;
610b57cec5SDimitry Andricdef HexagonQTRUE:      SDNode<"HexagonISD::QTRUE",      SDTVecLeaf>;
620b57cec5SDimitry Andricdef HexagonQFALSE:     SDNode<"HexagonISD::QFALSE",     SDTVecLeaf>;
630b57cec5SDimitry Andric
6404eeddc0SDimitry Andricdef vzero:  PatFrags<(ops), [(splat_vector (i32 0)), (splat_vector (f32zero))]>;
650b57cec5SDimitry Andricdef qtrue:  PatFrag<(ops), (HexagonQTRUE)>;
660b57cec5SDimitry Andricdef qfalse: PatFrag<(ops), (HexagonQFALSE)>;
670b57cec5SDimitry Andricdef qcat:   PatFrag<(ops node:$Qs, node:$Qt),
680b57cec5SDimitry Andric                    (HexagonQCAT node:$Qs, node:$Qt)>;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andricdef qnot:     PatFrag<(ops node:$Qs), (xor node:$Qs, qtrue)>;
710b57cec5SDimitry Andric
720b57cec5SDimitry Andricdef VSxtb: OutPatFrag<(ops node:$Vs), (V6_vunpackb  $Vs)>;
730b57cec5SDimitry Andricdef VSxth: OutPatFrag<(ops node:$Vs), (V6_vunpackh  $Vs)>;
740b57cec5SDimitry Andricdef VZxtb: OutPatFrag<(ops node:$Vs), (V6_vunpackub $Vs)>;
750b57cec5SDimitry Andricdef VZxth: OutPatFrag<(ops node:$Vs), (V6_vunpackuh $Vs)>;
760b57cec5SDimitry Andric
77*bdd1243dSDimitry Andricclass VSubi<InstHexagon VSub, InstHexagon VSplati>:
78*bdd1243dSDimitry Andric  OutPatFrag<(ops node:$Imm, node:$Vs), (VSub (VSplati (i32 $Imm)), $Vs)>;
79*bdd1243dSDimitry Andric
80*bdd1243dSDimitry Andricdef VSubib: VSubi<V6_vsubb, PS_vsplatib>;
81*bdd1243dSDimitry Andricdef VSubih: VSubi<V6_vsubh, PS_vsplatih>;
82*bdd1243dSDimitry Andricdef VSubiw: VSubi<V6_vsubw, PS_vsplatiw>;
83*bdd1243dSDimitry Andric
84*bdd1243dSDimitry Andricdef VNegb: OutPatFrag<(ops node:$Vs), (VSubib 0, $Vs)>;
85*bdd1243dSDimitry Andricdef VNegh: OutPatFrag<(ops node:$Vs), (VSubih 0, $Vs)>;
86*bdd1243dSDimitry Andricdef VNegw: OutPatFrag<(ops node:$Vs), (VSubiw 0, $Vs)>;
87*bdd1243dSDimitry Andric
88*bdd1243dSDimitry Andricclass pf3<SDNode Op>: PatFrag<(ops node:$a, node:$b, node:$c),
89*bdd1243dSDimitry Andric                              (Op node:$a, node:$b, node:$c)>;
90*bdd1243dSDimitry Andric
91*bdd1243dSDimitry Andricdef Mfshl: pf3<HexagonMFSHL>;
92*bdd1243dSDimitry Andricdef Mfshr: pf3<HexagonMFSHR>;
93*bdd1243dSDimitry Andric
940b57cec5SDimitry Andricdef IsVecOff : PatLeaf<(i32 imm), [{
950b57cec5SDimitry Andric  int32_t V = N->getSExtValue();
960b57cec5SDimitry Andric  int32_t VecSize = HRI->getSpillSize(Hexagon::HvxVRRegClass);
970b57cec5SDimitry Andric  assert(isPowerOf2_32(VecSize));
980b57cec5SDimitry Andric  if ((uint32_t(V) & (uint32_t(VecSize)-1)) != 0)
990b57cec5SDimitry Andric    return false;
1000b57cec5SDimitry Andric  int32_t L = Log2_32(VecSize);
1010b57cec5SDimitry Andric  return isInt<4>(V >> L);
1020b57cec5SDimitry Andric}]>;
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andricdef alignedload: PatFrag<(ops node:$a), (load $a), [{
10681ad6265SDimitry Andric  return isAlignedMemNode(cast<MemSDNode>(N));
1070b57cec5SDimitry Andric}]>;
1080b57cec5SDimitry Andric
1090b57cec5SDimitry Andricdef unalignedload: PatFrag<(ops node:$a), (load $a), [{
11081ad6265SDimitry Andric  return !isAlignedMemNode(cast<MemSDNode>(N));
1110b57cec5SDimitry Andric}]>;
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andricdef alignedstore: PatFrag<(ops node:$v, node:$a), (store $v, $a), [{
11481ad6265SDimitry Andric  return isAlignedMemNode(cast<MemSDNode>(N));
1150b57cec5SDimitry Andric}]>;
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andricdef unalignedstore: PatFrag<(ops node:$v, node:$a), (store $v, $a), [{
11881ad6265SDimitry Andric  return !isAlignedMemNode(cast<MemSDNode>(N));
1190b57cec5SDimitry Andric}]>;
1200b57cec5SDimitry Andric
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andric// HVX loads
1230b57cec5SDimitry Andric
124fe6060f1SDimitry Andricmulticlass HvxLdfi_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
1250b57cec5SDimitry Andric                       PatFrag ImmPred> {
126fe6060f1SDimitry Andric  def: Pat<(ResType (Load (add (i32 AddrFI:$fi), ImmPred:$Off))),
127fe6060f1SDimitry Andric           (MI AddrFI:$fi, imm:$Off)>;
128fe6060f1SDimitry Andric  def: Pat<(ResType (Load (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off))),
129fe6060f1SDimitry Andric           (MI AddrFI:$fi, imm:$Off)>;
130fe6060f1SDimitry Andric  def: Pat<(ResType (Load AddrFI:$fi)), (ResType (MI AddrFI:$fi, 0))>;
131fe6060f1SDimitry Andric}
132fe6060f1SDimitry Andric
133fe6060f1SDimitry Andricmulticlass HvxLdgi_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
134fe6060f1SDimitry Andric                     PatFrag ImmPred> {
135fe6060f1SDimitry Andric  def: Pat<(ResType (Load (add I32:$Rt, ImmPred:$Off))),
136fe6060f1SDimitry Andric           (MI I32:$Rt, imm:$Off)>;
1370b57cec5SDimitry Andric  def: Pat<(ResType (Load I32:$Rt)),
1380b57cec5SDimitry Andric           (MI I32:$Rt, 0)>;
139fe6060f1SDimitry Andric}
140fe6060f1SDimitry Andric
141fe6060f1SDimitry Andricmulticlass HvxLdc_pat<InstHexagon MI, PatFrag Load, ValueType ResType> {
1420b57cec5SDimitry Andric  // The HVX selection code for shuffles can generate vector constants.
1430b57cec5SDimitry Andric  // Calling "Select" on the resulting loads from CP fails without these
1440b57cec5SDimitry Andric  // patterns.
145fe6060f1SDimitry Andric  def: Pat<(ResType (Load (HexagonCP tconstpool:$Addr))),
146*bdd1243dSDimitry Andric           (MI (ToI32 imm:$Addr), 0)>;
147fe6060f1SDimitry Andric  def: Pat<(ResType (Load (HexagonAtPcrel tconstpool:$Addr))),
148fe6060f1SDimitry Andric           (MI (C4_addipc imm:$Addr), 0)>;
1490b57cec5SDimitry Andric}
1500b57cec5SDimitry Andric
151fe6060f1SDimitry Andricmulticlass HvxLd_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
152fe6060f1SDimitry Andric                     PatFrag ImmPred> {
153fe6060f1SDimitry Andric  defm: HvxLdfi_pat<MI, Load, ResType, ImmPred>;
154fe6060f1SDimitry Andric  defm: HvxLdgi_pat<MI, Load, ResType, ImmPred>;
155fe6060f1SDimitry Andric  defm: HvxLdc_pat <MI, Load, ResType>;
156fe6060f1SDimitry Andric}
157fe6060f1SDimitry Andric
158fe6060f1SDimitry Andric// Aligned loads: everything, plus loads with valignaddr node.
1590b57cec5SDimitry Andricmulticlass HvxLda_pat<InstHexagon MI, PatFrag Load, ValueType ResType,
1600b57cec5SDimitry Andric                      PatFrag ImmPred> {
1610b57cec5SDimitry Andric  let AddedComplexity = 50 in {
1620b57cec5SDimitry Andric    def: Pat<(ResType (Load (valignaddr I32:$Rt))),
1630b57cec5SDimitry Andric             (MI I32:$Rt, 0)>;
1640b57cec5SDimitry Andric    def: Pat<(ResType (Load (add (valignaddr I32:$Rt), ImmPred:$Off))),
1650b57cec5SDimitry Andric             (MI I32:$Rt, imm:$Off)>;
1660b57cec5SDimitry Andric  }
1670b57cec5SDimitry Andric  defm: HvxLd_pat<MI, Load, ResType, ImmPred>;
1680b57cec5SDimitry Andric}
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
171fe6060f1SDimitry Andric  // alignedload will match a non-temporal load as well, so try non-temporal
172fe6060f1SDimitry Andric  // first.
1730b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI8,  IsVecOff>;
1740b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI16, IsVecOff>;
1750b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecI32, IsVecOff>;
1760b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai,               alignedload, VecI8,  IsVecOff>;
1770b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai,               alignedload, VecI16, IsVecOff>;
1780b57cec5SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai,               alignedload, VecI32, IsVecOff>;
1790b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,             unalignedload, VecI8,  IsVecOff>;
1800b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,             unalignedload, VecI16, IsVecOff>;
1810b57cec5SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,             unalignedload, VecI32, IsVecOff>;
1820b57cec5SDimitry Andric}
1830b57cec5SDimitry Andric
18404eeddc0SDimitry Andriclet Predicates = [UseHVXV68] in {
18504eeddc0SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecF16, IsVecOff>;
18604eeddc0SDimitry Andric  defm: HvxLda_pat<V6_vL32b_nt_ai, alignednontemporalload, VecF32, IsVecOff>;
18704eeddc0SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai,               alignedload, VecF16, IsVecOff>;
18804eeddc0SDimitry Andric  defm: HvxLda_pat<V6_vL32b_ai,               alignedload, VecF32, IsVecOff>;
18904eeddc0SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,             unalignedload, VecF16, IsVecOff>;
19004eeddc0SDimitry Andric  defm: HvxLd_pat<V6_vL32Ub_ai,             unalignedload, VecF32, IsVecOff>;
19104eeddc0SDimitry Andric}
192fe6060f1SDimitry Andric
1930b57cec5SDimitry Andric// HVX stores
1940b57cec5SDimitry Andric
195fe6060f1SDimitry Andricmulticlass HvxStfi_pat<InstHexagon MI, PatFrag Store, PatFrag Value,
196fe6060f1SDimitry Andric                       PatFrag ImmPred> {
197fe6060f1SDimitry Andric  def: Pat<(Store Value:$Vs, (add (i32 AddrFI:$fi), ImmPred:$Off)),
198fe6060f1SDimitry Andric           (MI AddrFI:$fi, imm:$Off, Value:$Vs)>;
199fe6060f1SDimitry Andric  def: Pat<(Store Value:$Vs, (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off)),
200fe6060f1SDimitry Andric           (MI AddrFI:$fi, imm:$Off, Value:$Vs)>;
201fe6060f1SDimitry Andric  def: Pat<(Store Value:$Vs, AddrFI:$fi),
202fe6060f1SDimitry Andric           (MI AddrFI:$fi, 0, Value:$Vs)>;
203fe6060f1SDimitry Andric}
204fe6060f1SDimitry Andric
205fe6060f1SDimitry Andricmulticlass HvxStgi_pat<InstHexagon MI, PatFrag Store, PatFrag Value,
206fe6060f1SDimitry Andric                       PatFrag ImmPred> {
207fe6060f1SDimitry Andric  def: Pat<(Store Value:$Vs, (add I32:$Rt, ImmPred:$Off)),
208fe6060f1SDimitry Andric           (MI I32:$Rt, imm:$Off, Value:$Vs)>;
209fe6060f1SDimitry Andric  def: Pat<(Store Value:$Vs, (IsOrAdd I32:$Rt, ImmPred:$Off)),
210fe6060f1SDimitry Andric           (MI I32:$Rt, imm:$Off, Value:$Vs)>;
2110b57cec5SDimitry Andric  def: Pat<(Store Value:$Vs, I32:$Rt),
2120b57cec5SDimitry Andric           (MI I32:$Rt, 0, Value:$Vs)>;
213fe6060f1SDimitry Andric}
214fe6060f1SDimitry Andric
215fe6060f1SDimitry Andricmulticlass HvxSt_pat<InstHexagon MI, PatFrag Store, PatFrag Value,
216fe6060f1SDimitry Andric                     PatFrag ImmPred> {
217fe6060f1SDimitry Andric  defm: HvxStfi_pat<MI, Store, Value, ImmPred>;
218fe6060f1SDimitry Andric  defm: HvxStgi_pat<MI, Store, Value, ImmPred>;
2190b57cec5SDimitry Andric}
2200b57cec5SDimitry Andric
2210b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
222fe6060f1SDimitry Andric  // alignedstore will match a non-temporal store as well, so try non-temporal
223fe6060f1SDimitry Andric  // first.
224fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore,  HVI8, IsVecOff>;
225fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, HVI16, IsVecOff>;
226fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, HVI32, IsVecOff>;
227fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai,               alignedstore,  HVI8, IsVecOff>;
228fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai,               alignedstore, HVI16, IsVecOff>;
229fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai,               alignedstore, HVI32, IsVecOff>;
230fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai,            unalignedstore,  HVI8, IsVecOff>;
231fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai,            unalignedstore, HVI16, IsVecOff>;
232fe6060f1SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai,            unalignedstore, HVI32, IsVecOff>;
2330b57cec5SDimitry Andric}
2340b57cec5SDimitry Andric
23504eeddc0SDimitry Andriclet Predicates = [UseHVXV68] in {
23604eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, HVF16, IsVecOff>;
23704eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32b_nt_ai, alignednontemporalstore, HVF32, IsVecOff>;
23804eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai,               alignedstore, HVF16, IsVecOff>;
23904eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32b_ai,               alignedstore, HVF32, IsVecOff>;
24004eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai,            unalignedstore, HVF16, IsVecOff>;
24104eeddc0SDimitry Andric  defm: HvxSt_pat<V6_vS32Ub_ai,            unalignedstore, HVF32, IsVecOff>;
24204eeddc0SDimitry Andric}
24304eeddc0SDimitry Andric
2440b57cec5SDimitry Andric// Bitcasts between same-size vector types are no-ops, except for the
2450b57cec5SDimitry Andric// actual type change.
2460b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
2478bcb0991SDimitry Andric  defm: NopCast_pat<VecI8,   VecI16,  HvxVR>;
2488bcb0991SDimitry Andric  defm: NopCast_pat<VecI8,   VecI32,  HvxVR>;
2498bcb0991SDimitry Andric  defm: NopCast_pat<VecI16,  VecI32,  HvxVR>;
2500b57cec5SDimitry Andric
2518bcb0991SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPI16, HvxWR>;
2528bcb0991SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPI32, HvxWR>;
2538bcb0991SDimitry Andric  defm: NopCast_pat<VecPI16, VecPI32, HvxWR>;
2540b57cec5SDimitry Andric}
2550b57cec5SDimitry Andric
25604eeddc0SDimitry Andriclet Predicates = [UseHVX, UseHVXFloatingPoint] in {
25704eeddc0SDimitry Andric  defm: NopCast_pat<VecI8,   VecF16,  HvxVR>;
25804eeddc0SDimitry Andric  defm: NopCast_pat<VecI8,   VecF32,  HvxVR>;
25904eeddc0SDimitry Andric  defm: NopCast_pat<VecI16,  VecF16,  HvxVR>;
26004eeddc0SDimitry Andric  defm: NopCast_pat<VecI16,  VecF32,  HvxVR>;
26104eeddc0SDimitry Andric  defm: NopCast_pat<VecI32,  VecF16,  HvxVR>;
26204eeddc0SDimitry Andric  defm: NopCast_pat<VecI32,  VecF32,  HvxVR>;
26304eeddc0SDimitry Andric  defm: NopCast_pat<VecF16,  VecF32,  HvxVR>;
26404eeddc0SDimitry Andric
26504eeddc0SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPF16, HvxWR>;
26604eeddc0SDimitry Andric  defm: NopCast_pat<VecPI8,  VecPF32, HvxWR>;
26704eeddc0SDimitry Andric  defm: NopCast_pat<VecPI16, VecPF16, HvxWR>;
26804eeddc0SDimitry Andric  defm: NopCast_pat<VecPI16, VecPF32, HvxWR>;
26904eeddc0SDimitry Andric  defm: NopCast_pat<VecPI32, VecPF16, HvxWR>;
27004eeddc0SDimitry Andric  defm: NopCast_pat<VecPI32, VecPF32, HvxWR>;
27104eeddc0SDimitry Andric  defm: NopCast_pat<VecPF16, VecPF32, HvxWR>;
27204eeddc0SDimitry Andric}
27304eeddc0SDimitry Andric
2740b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
275e8d8bef9SDimitry Andric  let AddedComplexity = 100 in {
276e8d8bef9SDimitry Andric    // These should be preferred over a vsplat of 0.
2770b57cec5SDimitry Andric    def: Pat<(VecI8   vzero), (V6_vd0)>;
2780b57cec5SDimitry Andric    def: Pat<(VecI16  vzero), (V6_vd0)>;
2790b57cec5SDimitry Andric    def: Pat<(VecI32  vzero), (V6_vd0)>;
2800b57cec5SDimitry Andric    def: Pat<(VecPI8  vzero), (PS_vdd0)>;
2810b57cec5SDimitry Andric    def: Pat<(VecPI16 vzero), (PS_vdd0)>;
2820b57cec5SDimitry Andric    def: Pat<(VecPI32 vzero), (PS_vdd0)>;
28304eeddc0SDimitry Andric    def: Pat<(VecPF32 vzero), (PS_vdd0)>;
2840b57cec5SDimitry Andric
2850b57cec5SDimitry Andric    def: Pat<(concat_vectors  (VecI8 vzero),  (VecI8 vzero)), (PS_vdd0)>;
2860b57cec5SDimitry Andric    def: Pat<(concat_vectors (VecI16 vzero), (VecI16 vzero)), (PS_vdd0)>;
2870b57cec5SDimitry Andric    def: Pat<(concat_vectors (VecI32 vzero), (VecI32 vzero)), (PS_vdd0)>;
288e8d8bef9SDimitry Andric  }
2890b57cec5SDimitry Andric
2900b57cec5SDimitry Andric  def: Pat<(VecPI8 (concat_vectors HVI8:$Vs, HVI8:$Vt)),
2910b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
2920b57cec5SDimitry Andric  def: Pat<(VecPI16 (concat_vectors HVI16:$Vs, HVI16:$Vt)),
2930b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
2940b57cec5SDimitry Andric  def: Pat<(VecPI32 (concat_vectors HVI32:$Vs, HVI32:$Vt)),
2950b57cec5SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric  def: Pat<(VecQ8  (qcat HQ16:$Qs, HQ16:$Qt)), (Combineq $Qt, $Qs)>;
2980b57cec5SDimitry Andric  def: Pat<(VecQ16 (qcat HQ32:$Qs, HQ32:$Qt)), (Combineq $Qt, $Qs)>;
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI8:$Vu, I32:$Rs),
3010b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
3020b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI16:$Vu, I32:$Rs),
3030b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
3040b57cec5SDimitry Andric  def: Pat<(HexagonVEXTRACTW HVI32:$Vu, I32:$Rs),
3050b57cec5SDimitry Andric           (V6_extractw HvxVR:$Vu, I32:$Rs)>;
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI8:$Vu,  I32:$Rt),
3080b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
3090b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI16:$Vu, I32:$Rt),
3100b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
3110b57cec5SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVI32:$Vu, I32:$Rt),
3120b57cec5SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
3130b57cec5SDimitry Andric}
3140b57cec5SDimitry Andric
31504eeddc0SDimitry Andriclet Predicates = [UseHVX, UseHVXFloatingPoint] in {
31604eeddc0SDimitry Andric  let AddedComplexity = 100 in {
31704eeddc0SDimitry Andric    def: Pat<(VecF16  vzero), (V6_vd0)>;
31804eeddc0SDimitry Andric    def: Pat<(VecF32  vzero), (V6_vd0)>;
31904eeddc0SDimitry Andric    def: Pat<(VecPF16 vzero), (PS_vdd0)>;
32004eeddc0SDimitry Andric    def: Pat<(VecPF32 vzero), (PS_vdd0)>;
32104eeddc0SDimitry Andric
32204eeddc0SDimitry Andric    def: Pat<(concat_vectors (VecF16 vzero), (VecF16 vzero)), (PS_vdd0)>;
32304eeddc0SDimitry Andric    def: Pat<(concat_vectors (VecF32 vzero), (VecF32 vzero)), (PS_vdd0)>;
32404eeddc0SDimitry Andric  }
32504eeddc0SDimitry Andric
32604eeddc0SDimitry Andric  def: Pat<(VecPF16 (concat_vectors HVF16:$Vs, HVF16:$Vt)),
32704eeddc0SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
32804eeddc0SDimitry Andric  def: Pat<(VecPF32 (concat_vectors HVF32:$Vs, HVF32:$Vt)),
32904eeddc0SDimitry Andric           (Combinev HvxVR:$Vt, HvxVR:$Vs)>;
33004eeddc0SDimitry Andric
33104eeddc0SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVF16:$Vu, I32:$Rt),
33204eeddc0SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
33304eeddc0SDimitry Andric  def: Pat<(HexagonVINSERTW0 HVF32:$Vu, I32:$Rt),
33404eeddc0SDimitry Andric           (V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
33504eeddc0SDimitry Andric}
33604eeddc0SDimitry Andric
3370b57cec5SDimitry Andricdef Rep: OutPatFrag<(ops node:$N), (Combinev $N, $N)>;
3380b57cec5SDimitry Andric
339*bdd1243dSDimitry Andriclet Predicates = [UseHVX] in {
3400b57cec5SDimitry Andric  let AddedComplexity = 10 in {
341*bdd1243dSDimitry Andric    def: Pat<(VecI8   (splat_vector u8_0ImmPred:$V)),  (PS_vsplatib imm:$V)>;
342*bdd1243dSDimitry Andric    def: Pat<(VecI16  (splat_vector u16_0ImmPred:$V)), (PS_vsplatih imm:$V)>;
343*bdd1243dSDimitry Andric    def: Pat<(VecI32  (splat_vector anyimm:$V)),       (PS_vsplatiw imm:$V)>;
344*bdd1243dSDimitry Andric    def: Pat<(VecPI8  (splat_vector u8_0ImmPred:$V)),  (Rep (PS_vsplatib imm:$V))>;
345*bdd1243dSDimitry Andric    def: Pat<(VecPI16 (splat_vector u16_0ImmPred:$V)), (Rep (PS_vsplatih imm:$V))>;
346*bdd1243dSDimitry Andric    def: Pat<(VecPI32 (splat_vector anyimm:$V)),       (Rep (PS_vsplatiw imm:$V))>;
3470b57cec5SDimitry Andric  }
348*bdd1243dSDimitry Andric  def: Pat<(VecI8   (splat_vector I32:$Rs)), (PS_vsplatrb $Rs)>;
349*bdd1243dSDimitry Andric  def: Pat<(VecI16  (splat_vector I32:$Rs)), (PS_vsplatrh $Rs)>;
350*bdd1243dSDimitry Andric  def: Pat<(VecI32  (splat_vector I32:$Rs)), (PS_vsplatrw $Rs)>;
351*bdd1243dSDimitry Andric  def: Pat<(VecPI8  (splat_vector I32:$Rs)), (Rep (PS_vsplatrb $Rs))>;
352*bdd1243dSDimitry Andric  def: Pat<(VecPI16 (splat_vector I32:$Rs)), (Rep (PS_vsplatrh $Rs))>;
353*bdd1243dSDimitry Andric  def: Pat<(VecPI32 (splat_vector I32:$Rs)), (Rep (PS_vsplatrw $Rs))>;
3540b57cec5SDimitry Andric}
35504eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVXFloatingPoint] in {
35604eeddc0SDimitry Andric  let AddedComplexity = 30 in {
357*bdd1243dSDimitry Andric    def: Pat<(VecF16  (splat_vector u16_0ImmPred:$V)), (PS_vsplatih imm:$V)>;
358*bdd1243dSDimitry Andric    def: Pat<(VecF32  (splat_vector anyint:$V)),       (PS_vsplatiw imm:$V)>;
359*bdd1243dSDimitry Andric    def: Pat<(VecF32  (splat_vector f32ImmPred:$V)),   (PS_vsplatiw (ftoi $V))>;
36004eeddc0SDimitry Andric  }
36104eeddc0SDimitry Andric  let AddedComplexity = 20 in {
362*bdd1243dSDimitry Andric    def: Pat<(VecF16  (splat_vector I32:$Rs)), (PS_vsplatrh $Rs)>;
363*bdd1243dSDimitry Andric    def: Pat<(VecF32  (splat_vector I32:$Rs)), (PS_vsplatrw $Rs)>;
364*bdd1243dSDimitry Andric    def: Pat<(VecF32  (splat_vector F32:$Rs)), (PS_vsplatrw $Rs)>;
36504eeddc0SDimitry Andric  }
36604eeddc0SDimitry Andric}
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andricclass Vneg1<ValueType VecTy>
369e8d8bef9SDimitry Andric  : PatFrag<(ops), (VecTy (splat_vector (i32 -1)))>;
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andricclass Vnot<ValueType VecTy>
3720b57cec5SDimitry Andric  : PatFrag<(ops node:$Vs), (xor $Vs, Vneg1<VecTy>)>;
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
3750b57cec5SDimitry Andric  let AddedComplexity = 200 in {
3760b57cec5SDimitry Andric    def: Pat<(Vnot<VecI8>   HVI8:$Vs), (V6_vnot HvxVR:$Vs)>;
3770b57cec5SDimitry Andric    def: Pat<(Vnot<VecI16> HVI16:$Vs), (V6_vnot HvxVR:$Vs)>;
3780b57cec5SDimitry Andric    def: Pat<(Vnot<VecI32> HVI32:$Vs), (V6_vnot HvxVR:$Vs)>;
3790b57cec5SDimitry Andric  }
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddb,    Add,   VecI8,  HVI8>;
3820b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddh,    Add,  VecI16, HVI16>;
3830b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddw,    Add,  VecI32, HVI32>;
3840b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddb_dv, Add,  VecPI8,  HWI8>;
3850b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddh_dv, Add, VecPI16, HWI16>;
3860b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vaddw_dv, Add, VecPI32, HWI32>;
3870b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubb,    Sub,   VecI8,  HVI8>;
3880b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubh,    Sub,  VecI16, HVI16>;
3890b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubw,    Sub,  VecI32, HVI32>;
3900b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubb_dv, Sub,  VecPI8,  HWI8>;
3910b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubh_dv, Sub, VecPI16, HWI16>;
3920b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vsubw_dv, Sub, VecPI32, HWI32>;
3930b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,   VecI8,  HVI8>;
3940b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,  VecI16, HVI16>;
3950b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vand,     And,  VecI32, HVI32>;
3960b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,   VecI8,  HVI8>;
3970b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,  VecI16, HVI16>;
3980b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vor,       Or,  VecI32, HVI32>;
3990b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,   VecI8,  HVI8>;
4000b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,  VecI16, HVI16>;
4010b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vxor,     Xor,  VecI32, HVI32>;
4020b57cec5SDimitry Andric
403e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminb,   Smin,   VecI8,  HVI8>;
404e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxb,   Smax,   VecI8,  HVI8>;
405e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminub,  Umin,   VecI8,  HVI8>;
406e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxub,  Umax,   VecI8,  HVI8>;
407e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminh,   Smin,  VecI16, HVI16>;
408e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxh,   Smax,  VecI16, HVI16>;
409e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminuh,  Umin,  VecI16, HVI16>;
410e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxuh,  Umax,  VecI16, HVI16>;
411e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vminw,   Smin,  VecI32, HVI32>;
412e8d8bef9SDimitry Andric  def: OpR_RR_pat<V6_vmaxw,   Smax,  VecI32, HVI32>;
413e8d8bef9SDimitry Andric
4140b57cec5SDimitry Andric  def: Pat<(vselect HQ8:$Qu, HVI8:$Vs, HVI8:$Vt),
4150b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
4160b57cec5SDimitry Andric  def: Pat<(vselect HQ16:$Qu, HVI16:$Vs, HVI16:$Vt),
4170b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
4180b57cec5SDimitry Andric  def: Pat<(vselect HQ32:$Qu, HVI32:$Vs, HVI32:$Vt),
4190b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
4200b57cec5SDimitry Andric
4210b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ8:$Qu), HVI8:$Vs, HVI8:$Vt),
4220b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
4230b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ16:$Qu), HVI16:$Vs, HVI16:$Vt),
4240b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
4250b57cec5SDimitry Andric  def: Pat<(vselect (qnot HQ32:$Qu), HVI32:$Vs, HVI32:$Vt),
4260b57cec5SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
4270b57cec5SDimitry Andric}
4280b57cec5SDimitry Andric
42904eeddc0SDimitry Andric// For now, we always deal with vector floating point in SF mode.
43004eeddc0SDimitry Andricclass OpR_RR_pat_conv<InstHexagon MI, PatFrag Op, ValueType ResType,
43104eeddc0SDimitry Andric                      PatFrag RsPred, PatFrag RtPred = RsPred>
43204eeddc0SDimitry Andric  : Pat<(ResType (Op RsPred:$Rs, RtPred:$Rt)),
43304eeddc0SDimitry Andric        (V6_vconv_sf_qf32 (VecF32 (MI RsPred:$Rs, RtPred:$Rt)))>;
43404eeddc0SDimitry Andric
43504eeddc0SDimitry Andricclass OpR_RR_pat_conv_hf<InstHexagon MI, PatFrag Op, ValueType ResType,
43604eeddc0SDimitry Andric                      PatFrag RsPred, PatFrag RtPred = RsPred>
43704eeddc0SDimitry Andric  : Pat<(ResType (Op RsPred:$Rs, RtPred:$Rt)),
43804eeddc0SDimitry Andric        (V6_vconv_hf_qf16 (VecF16 (MI RsPred:$Rs, RtPred:$Rt)))>;
43904eeddc0SDimitry Andric
44004eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVXQFloat] in {
44104eeddc0SDimitry Andric  def: OpR_RR_pat_conv_hf<V6_vsub_hf,        pf2<fsub>,  VecF16, HVF16>;
44204eeddc0SDimitry Andric  def: OpR_RR_pat_conv_hf<V6_vadd_hf,        pf2<fadd>,  VecF16, HVF16>;
44304eeddc0SDimitry Andric  def: OpR_RR_pat_conv_hf<V6_vmpy_qf16_hf,   pf2<fmul>,  VecF16, HVF16>;
44404eeddc0SDimitry Andric  def: OpR_RR_pat_conv<V6_vsub_sf,        pf2<fsub>,  VecF32, HVF32>;
44504eeddc0SDimitry Andric  def: OpR_RR_pat_conv<V6_vadd_sf,        pf2<fadd>,  VecF32, HVF32>;
44604eeddc0SDimitry Andric  def: OpR_RR_pat_conv<V6_vmpy_qf32_sf,   pf2<fmul>,  VecF32, HVF32>;
44704eeddc0SDimitry Andric
44804eeddc0SDimitry Andric  // For now we assume that the fp32 register is always coming in as IEEE float
44904eeddc0SDimitry Andric  // since the qfloat arithmetic instructions above always generate the
45004eeddc0SDimitry Andric  // accompanying conversions as part of their pattern
45104eeddc0SDimitry Andric  def: Pat<(VecF16 (pf1<fpround> HWF32:$Vuu)),
45204eeddc0SDimitry Andric           (V6_vdealh (V6_vconv_hf_qf32
45304eeddc0SDimitry Andric             (VecPF32 (Combinev (V6_vadd_sf (HiVec HvxWR:$Vuu), (V6_vd0)),
45404eeddc0SDimitry Andric                                (V6_vadd_sf (LoVec HvxWR:$Vuu), (V6_vd0))
45504eeddc0SDimitry Andric             ))))>;
45604eeddc0SDimitry Andric  // fpextend for QFloat is handled manually in HexagonISelLoweringHVX.cpp.
45704eeddc0SDimitry Andric}
45804eeddc0SDimitry Andric
45904eeddc0SDimitry Andric// HVX IEEE arithmetic Instructions
46004eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVXIEEEFP] in {
46104eeddc0SDimitry Andric  def: Pat<(fadd HVF16:$Rs, HVF16:$Rt),
46204eeddc0SDimitry Andric           (V6_vadd_hf_hf HVF16:$Rs, HVF16:$Rt)>;
46304eeddc0SDimitry Andric  def: Pat<(fadd HVF32:$Rs, HVF32:$Rt),
46404eeddc0SDimitry Andric           (V6_vadd_sf_sf HVF32:$Rs, HVF32:$Rt)>;
46504eeddc0SDimitry Andric  def: Pat<(fsub HVF16:$Rs, HVF16:$Rt),
46604eeddc0SDimitry Andric           (V6_vsub_hf_hf HVF16:$Rs, HVF16:$Rt)>;
46704eeddc0SDimitry Andric  def: Pat<(fsub HVF32:$Rs, HVF32:$Rt),
46804eeddc0SDimitry Andric           (V6_vsub_sf_sf HVF32:$Rs, HVF32:$Rt)>;
46904eeddc0SDimitry Andric  def: Pat<(fmul HVF16:$Rs, HVF16:$Rt),
47004eeddc0SDimitry Andric           (V6_vmpy_hf_hf HVF16:$Rs, HVF16:$Rt)>;
47104eeddc0SDimitry Andric  def: Pat<(fmul HVF32:$Rs, HVF32:$Rt),
47204eeddc0SDimitry Andric           (V6_vmpy_sf_sf HVF32:$Rs, HVF32:$Rt)>;
47304eeddc0SDimitry Andric
47404eeddc0SDimitry Andric  def: Pat<(VecF16 (pf1<fpround> HWF32:$Vuu)),
47504eeddc0SDimitry Andric           (V6_vdealh (V6_vcvt_hf_sf (HiVec HvxWR:$Vuu), (LoVec HvxWR:$Vuu)))>;
47604eeddc0SDimitry Andric  def: Pat<(VecPF32 (pf1<fpextend> HVF16:$Vu)),
47704eeddc0SDimitry Andric           (V6_vcvt_sf_hf (V6_vshuffh HvxVR:$Vu))>;
47804eeddc0SDimitry Andric
47904eeddc0SDimitry Andric  def: OpR_R_pat<V6_vcvt_h_hf,  Fptosi, VecI16, HVF16>;
48004eeddc0SDimitry Andric  def: OpR_R_pat<V6_vcvt_uh_hf, Fptoui, VecI16, HVF16>;
48104eeddc0SDimitry Andric  def: OpR_R_pat<V6_vcvt_hf_h,  Sitofp, VecF16, HVI16>;
48204eeddc0SDimitry Andric  def: OpR_R_pat<V6_vcvt_hf_uh, Uitofp, VecF16, HVI16>;
48304eeddc0SDimitry Andric
48404eeddc0SDimitry Andric  def: Pat<(VecI8 (Fptosi HWF16:$Vu)),
48504eeddc0SDimitry Andric           (V6_vcvt_b_hf (HiVec $Vu), (LoVec $Vu))>;
48604eeddc0SDimitry Andric  def: Pat<(VecI8 (Fptoui HWF16:$Vu)),
48704eeddc0SDimitry Andric           (V6_vcvt_ub_hf (HiVec $Vu), (LoVec $Vu))>;
48804eeddc0SDimitry Andric  def: Pat<(VecPF16 (Sitofp HVI8:$Vu)), (V6_vcvt_hf_b HvxVR:$Vu)>;
48904eeddc0SDimitry Andric  def: Pat<(VecPF16 (Uitofp HVI8:$Vu)), (V6_vcvt_hf_ub HvxVR:$Vu)>;
49004eeddc0SDimitry Andric}
49104eeddc0SDimitry Andric
49204eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVXFloatingPoint] in {
49304eeddc0SDimitry Andric  def: Pat<(vselect HQ16:$Qu, HVF16:$Vs, HVF16:$Vt),
49404eeddc0SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
49504eeddc0SDimitry Andric  def: Pat<(vselect (qnot HQ16:$Qu), HVF16:$Vs, HVF16:$Vt),
49604eeddc0SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
49704eeddc0SDimitry Andric
49804eeddc0SDimitry Andric  def: Pat<(vselect HQ32:$Qu, HVF32:$Vs, HVF32:$Vt),
49904eeddc0SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vs, HvxVR:$Vt)>;
50004eeddc0SDimitry Andric  def: Pat<(vselect (qnot HQ32:$Qu), HVF32:$Vs, HVF32:$Vt),
50104eeddc0SDimitry Andric           (V6_vmux HvxQR:$Qu, HvxVR:$Vt, HvxVR:$Vs)>;
50204eeddc0SDimitry Andric}
50304eeddc0SDimitry Andric
50404eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVX128B, UseHVXQFloat] in {
50504eeddc0SDimitry Andric  let AddedComplexity = 220 in {
50604eeddc0SDimitry Andric    defm: MinMax_pats<V6_vmin_hf, V6_vmax_hf, vselect,  setgt, VecQ16, HVF16>;
50704eeddc0SDimitry Andric    defm: MinMax_pats<V6_vmin_hf, V6_vmax_hf, vselect, setogt, VecQ16, HVF16>;
50804eeddc0SDimitry Andric    defm: MinMax_pats<V6_vmin_sf, V6_vmax_sf, vselect,  setgt, VecQ32, HVF32>;
50904eeddc0SDimitry Andric    defm: MinMax_pats<V6_vmin_sf, V6_vmax_sf, vselect, setogt, VecQ32, HVF32>;
51004eeddc0SDimitry Andric  }
51104eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vmin_hf, pf2<fminnum>, VecF16, HVF16>;
51204eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vmax_hf, pf2<fmaxnum>, VecF16, HVF16>;
51304eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vmin_sf, pf2<fminnum>, VecF32, HVF32>;
51404eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vmax_sf, pf2<fmaxnum>, VecF32, HVF32>;
51504eeddc0SDimitry Andric}
51604eeddc0SDimitry Andric
51704eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVX128B, UseHVXIEEEFP] in {
51804eeddc0SDimitry Andric  let AddedComplexity = 220 in {
51904eeddc0SDimitry Andric    defm: MinMax_pats<V6_vfmin_hf, V6_vfmax_hf, vselect,  setgt, VecQ16, HVF16>;
52004eeddc0SDimitry Andric    defm: MinMax_pats<V6_vfmin_hf, V6_vfmax_hf, vselect, setogt, VecQ16, HVF16>;
52104eeddc0SDimitry Andric    defm: MinMax_pats<V6_vfmin_sf, V6_vfmax_sf, vselect,  setgt, VecQ32, HVF32>;
52204eeddc0SDimitry Andric    defm: MinMax_pats<V6_vfmin_sf, V6_vfmax_sf, vselect, setogt, VecQ32, HVF32>;
52304eeddc0SDimitry Andric  }
52404eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vfmin_hf, pf2<fminnum>, VecF16, HVF16>;
52504eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vfmax_hf, pf2<fmaxnum>, VecF16, HVF16>;
52604eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vfmin_sf, pf2<fminnum>, VecF32, HVF32>;
52704eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vfmax_sf, pf2<fmaxnum>, VecF32, HVF32>;
52804eeddc0SDimitry Andric}
52904eeddc0SDimitry Andric
5300b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
531e8d8bef9SDimitry Andric  // For i8 vectors Vs = (a0, a1, ...), Vt = (b0, b1, ...),
532e8d8bef9SDimitry Andric  // V6_vmpybv Vs, Vt produces a pair of i16 vectors Hi:Lo,
533e8d8bef9SDimitry Andric  // where Lo = (a0*b0, a2*b2, ...), Hi = (a1*b1, a3*b3, ...).
534e8d8bef9SDimitry Andric  def: Pat<(mul HVI8:$Vs, HVI8:$Vt),
535e8d8bef9SDimitry Andric           (V6_vshuffeb (HiVec (V6_vmpybv HvxVR:$Vs, HvxVR:$Vt)),
536e8d8bef9SDimitry Andric                        (LoVec (V6_vmpybv HvxVR:$Vs, HvxVR:$Vt)))>;
537e8d8bef9SDimitry Andric  def: Pat<(mul HVI16:$Vs, HVI16:$Vt),
538e8d8bef9SDimitry Andric           (V6_vmpyih HvxVR:$Vs, HvxVR:$Vt)>;
539e8d8bef9SDimitry Andric  def: Pat<(mul HVI32:$Vs, HVI32:$Vt),
540e8d8bef9SDimitry Andric           (V6_vmpyiewuh_acc (V6_vmpyieoh HvxVR:$Vs, HvxVR:$Vt),
541e8d8bef9SDimitry Andric                             HvxVR:$Vs, HvxVR:$Vt)>;
542e8d8bef9SDimitry Andric}
543e8d8bef9SDimitry Andric
544e8d8bef9SDimitry Andriclet Predicates = [UseHVX] in {
5450b57cec5SDimitry Andric  def: Pat<(VecPI16 (sext HVI8:$Vs)),  (VSxtb $Vs)>;
5460b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext HVI16:$Vs)), (VSxth $Vs)>;
5470b57cec5SDimitry Andric  def: Pat<(VecPI16 (zext HVI8:$Vs)),  (VZxtb $Vs)>;
5480b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext HVI16:$Vs)), (VZxth $Vs)>;
5490b57cec5SDimitry Andric
5500b57cec5SDimitry Andric  def: Pat<(VecI16 (sext_invec HVI8:$Vs)),  (LoVec (VSxtb $Vs))>;
5510b57cec5SDimitry Andric  def: Pat<(VecI32 (sext_invec HVI16:$Vs)), (LoVec (VSxth $Vs))>;
5520b57cec5SDimitry Andric  def: Pat<(VecI32 (sext_invec HVI8:$Vs)),
5530b57cec5SDimitry Andric           (LoVec (VSxth (LoVec (VSxtb $Vs))))>;
5540b57cec5SDimitry Andric  def: Pat<(VecPI16 (sext_invec HWI8:$Vss)),  (VSxtb (LoVec $Vss))>;
5550b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext_invec HWI16:$Vss)), (VSxth (LoVec $Vss))>;
5560b57cec5SDimitry Andric  def: Pat<(VecPI32 (sext_invec HWI8:$Vss)),
5570b57cec5SDimitry Andric           (VSxth (LoVec (VSxtb (LoVec $Vss))))>;
5580b57cec5SDimitry Andric
5590b57cec5SDimitry Andric  def: Pat<(VecI16 (zext_invec HVI8:$Vs)),  (LoVec (VZxtb $Vs))>;
5600b57cec5SDimitry Andric  def: Pat<(VecI32 (zext_invec HVI16:$Vs)), (LoVec (VZxth $Vs))>;
5610b57cec5SDimitry Andric  def: Pat<(VecI32 (zext_invec HVI8:$Vs)),
5620b57cec5SDimitry Andric           (LoVec (VZxth (LoVec (VZxtb $Vs))))>;
5630b57cec5SDimitry Andric  def: Pat<(VecPI16 (zext_invec HWI8:$Vss)),  (VZxtb (LoVec $Vss))>;
5640b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext_invec HWI16:$Vss)), (VZxth (LoVec $Vss))>;
5650b57cec5SDimitry Andric  def: Pat<(VecPI32 (zext_invec HWI8:$Vss)),
5660b57cec5SDimitry Andric           (VZxth (LoVec (VZxtb (LoVec $Vss))))>;
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric  def: Pat<(VecI8 (trunc HWI16:$Vss)),
5690b57cec5SDimitry Andric           (V6_vpackeb (HiVec $Vss), (LoVec $Vss))>;
5700b57cec5SDimitry Andric  def: Pat<(VecI16 (trunc HWI32:$Vss)),
5710b57cec5SDimitry Andric           (V6_vpackeh (HiVec $Vss), (LoVec $Vss))>;
572*bdd1243dSDimitry Andric  // Pattern for (v32i8 (trunc v32i32:$Vs)) after widening:
573*bdd1243dSDimitry Andric  def: Pat<(VecI8 (trunc
574*bdd1243dSDimitry Andric              (concat_vectors
575*bdd1243dSDimitry Andric                (VecI16 (trunc (concat_vectors HVI32:$Vs, undef))),
576*bdd1243dSDimitry Andric                undef))),
577*bdd1243dSDimitry Andric           (V6_vdealb4w (IMPLICIT_DEF), HvxVR:$Vs)>;
5780b57cec5SDimitry Andric
5790b57cec5SDimitry Andric  def: Pat<(VecQ8 (trunc HVI8:$Vs)),
580*bdd1243dSDimitry Andric           (V6_vandvrt HvxVR:$Vs, (ToI32 0x01010101))>;
5810b57cec5SDimitry Andric  def: Pat<(VecQ16 (trunc HVI16:$Vs)),
582*bdd1243dSDimitry Andric           (V6_vandvrt HvxVR:$Vs, (ToI32 0x01010101))>;
5830b57cec5SDimitry Andric  def: Pat<(VecQ32 (trunc HVI32:$Vs)),
584*bdd1243dSDimitry Andric           (V6_vandvrt HvxVR:$Vs, (ToI32 0x01010101))>;
5850b57cec5SDimitry Andric}
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
5880b57cec5SDimitry Andric  // The "source" types are not legal, and there are no parameterized
5890b57cec5SDimitry Andric  // definitions for them, but they are length-specific.
5900b57cec5SDimitry Andric  let Predicates = [UseHVX,UseHVX64B] in {
5910b57cec5SDimitry Andric    def: Pat<(VecI16 (sext_inreg HVI16:$Vs, v32i8)),
592*bdd1243dSDimitry Andric             (V6_vasrh (V6_vaslh HVI16:$Vs, (ToI32 8)), (ToI32 8))>;
5930b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v16i8)),
594*bdd1243dSDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (ToI32 24)), (ToI32 24))>;
5950b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v16i16)),
596*bdd1243dSDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (ToI32 16)), (ToI32 16))>;
5970b57cec5SDimitry Andric  }
5980b57cec5SDimitry Andric  let Predicates = [UseHVX,UseHVX128B] in {
5990b57cec5SDimitry Andric    def: Pat<(VecI16 (sext_inreg HVI16:$Vs, v64i8)),
600*bdd1243dSDimitry Andric             (V6_vasrh (V6_vaslh HVI16:$Vs, (ToI32 8)), (ToI32 8))>;
6010b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v32i8)),
602*bdd1243dSDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (ToI32 24)), (ToI32 24))>;
6030b57cec5SDimitry Andric    def: Pat<(VecI32 (sext_inreg HVI32:$Vs, v32i16)),
604*bdd1243dSDimitry Andric             (V6_vasrw (V6_vaslw HVI32:$Vs, (ToI32 16)), (ToI32 16))>;
6050b57cec5SDimitry Andric  }
6060b57cec5SDimitry Andric
607e8d8bef9SDimitry Andric  // Take a pair of vectors Vt:Vs and shift them towards LSB by (Rt & HwLen).
608e8d8bef9SDimitry Andric  def: Pat<(VecI8 (valign HVI8:$Vt, HVI8:$Vs, I32:$Rt)),
609e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
610e8d8bef9SDimitry Andric  def: Pat<(VecI16 (valign HVI16:$Vt, HVI16:$Vs, I32:$Rt)),
611e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
612e8d8bef9SDimitry Andric  def: Pat<(VecI32 (valign HVI32:$Vt, HVI32:$Vs, I32:$Rt)),
613e8d8bef9SDimitry Andric           (LoVec (V6_valignb HvxVR:$Vt, HvxVR:$Vs, I32:$Rt))>;
614e8d8bef9SDimitry Andric
6150b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI8:$Vs, I32:$Rt),
616*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vaslh (HiVec (V6_vzb HvxVR:$Vs)), I32:$Rt),
617*bdd1243dSDimitry Andric                        (V6_vaslh (LoVec (V6_vzb HvxVR:$Vs)), I32:$Rt))>;
6180b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI8:$Vs, I32:$Rt),
619*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vasrh (HiVec (V6_vsb HvxVR:$Vs)), I32:$Rt),
620*bdd1243dSDimitry Andric                        (V6_vasrh (LoVec (V6_vsb HvxVR:$Vs)), I32:$Rt))>;
6210b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI8:$Vs, I32:$Rt),
622*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vlsrh (HiVec (V6_vzb HvxVR:$Vs)), I32:$Rt),
623*bdd1243dSDimitry Andric                        (V6_vlsrh (LoVec (V6_vzb HvxVR:$Vs)), I32:$Rt))>;
6240b57cec5SDimitry Andric
6250b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI16:$Vs, I32:$Rt), (V6_vaslh HvxVR:$Vs, I32:$Rt)>;
6260b57cec5SDimitry Andric  def: Pat<(HexagonVASL HVI32:$Vs, I32:$Rt), (V6_vaslw HvxVR:$Vs, I32:$Rt)>;
6270b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI16:$Vs, I32:$Rt), (V6_vasrh HvxVR:$Vs, I32:$Rt)>;
6280b57cec5SDimitry Andric  def: Pat<(HexagonVASR HVI32:$Vs, I32:$Rt), (V6_vasrw HvxVR:$Vs, I32:$Rt)>;
6290b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI16:$Vs, I32:$Rt), (V6_vlsrh HvxVR:$Vs, I32:$Rt)>;
6300b57cec5SDimitry Andric  def: Pat<(HexagonVLSR HVI32:$Vs, I32:$Rt), (V6_vlsrw HvxVR:$Vs, I32:$Rt)>;
6310b57cec5SDimitry Andric
6320b57cec5SDimitry Andric  def: Pat<(add HVI32:$Vx, (HexagonVASL HVI32:$Vu, I32:$Rt)),
6330b57cec5SDimitry Andric           (V6_vaslw_acc HvxVR:$Vx, HvxVR:$Vu, I32:$Rt)>;
6340b57cec5SDimitry Andric  def: Pat<(add HVI32:$Vx, (HexagonVASR HVI32:$Vu, I32:$Rt)),
6350b57cec5SDimitry Andric           (V6_vasrw_acc HvxVR:$Vx, HvxVR:$Vu, I32:$Rt)>;
6360b57cec5SDimitry Andric
637*bdd1243dSDimitry Andric  def: Pat<(shl HVI8:$Vs, HVI8:$Vt),
638*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vaslhv (HiVec (V6_vzb $Vs)), (HiVec (V6_vzb $Vt))),
639*bdd1243dSDimitry Andric                        (V6_vaslhv (LoVec (V6_vzb $Vs)), (LoVec (V6_vzb $Vt))))>;
640*bdd1243dSDimitry Andric  def: Pat<(sra HVI8:$Vs, HVI8:$Vt),
641*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vasrhv (HiVec (V6_vsb $Vs)), (HiVec (V6_vzb $Vt))),
642*bdd1243dSDimitry Andric                        (V6_vasrhv (LoVec (V6_vsb $Vs)), (LoVec (V6_vzb $Vt))))>;
643*bdd1243dSDimitry Andric  def: Pat<(srl HVI8:$Vs, HVI8:$Vt),
644*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vlsrhv (HiVec (V6_vzb $Vs)), (HiVec (V6_vzb $Vt))),
645*bdd1243dSDimitry Andric                        (V6_vlsrhv (LoVec (V6_vzb $Vs)), (LoVec (V6_vzb $Vt))))>;
646*bdd1243dSDimitry Andric
6470b57cec5SDimitry Andric  def: Pat<(shl HVI16:$Vs, HVI16:$Vt), (V6_vaslhv HvxVR:$Vs, HvxVR:$Vt)>;
6480b57cec5SDimitry Andric  def: Pat<(shl HVI32:$Vs, HVI32:$Vt), (V6_vaslwv HvxVR:$Vs, HvxVR:$Vt)>;
6490b57cec5SDimitry Andric  def: Pat<(sra HVI16:$Vs, HVI16:$Vt), (V6_vasrhv HvxVR:$Vs, HvxVR:$Vt)>;
6500b57cec5SDimitry Andric  def: Pat<(sra HVI32:$Vs, HVI32:$Vt), (V6_vasrwv HvxVR:$Vs, HvxVR:$Vt)>;
6510b57cec5SDimitry Andric  def: Pat<(srl HVI16:$Vs, HVI16:$Vt), (V6_vlsrhv HvxVR:$Vs, HvxVR:$Vt)>;
6520b57cec5SDimitry Andric  def: Pat<(srl HVI32:$Vs, HVI32:$Vt), (V6_vlsrwv HvxVR:$Vs, HvxVR:$Vt)>;
6530b57cec5SDimitry Andric
654*bdd1243dSDimitry Andric  // Mfshl hi, lo, amt
655*bdd1243dSDimitry Andric  def: Pat<(Mfshl HVI8:$Vu, HVI8:$Vv, HVI8:$Vs),
656*bdd1243dSDimitry Andric           (V6_vshuffob (V6_vaslhv (HiVec (V6_vshufoeb $Vu, $Vv)),
657*bdd1243dSDimitry Andric                                   (HiVec (V6_vzb $Vs))),
658*bdd1243dSDimitry Andric                        (V6_vaslhv (LoVec (V6_vshufoeb $Vu, $Vv)),
659*bdd1243dSDimitry Andric                                   (LoVec (V6_vzb $Vs))))>;
660e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV60] in {
661*bdd1243dSDimitry Andric    // V60 doesn't produce 0 on shifts by bitwidth, e.g. Vv.h << 16-0
662*bdd1243dSDimitry Andric    def: Pat<(Mfshl HVI16:$Vu, HVI16:$Vv, HVI16:$Vs),
663*bdd1243dSDimitry Andric             (V6_vmux (V6_veqh $Vs, (V6_vd0)),
664*bdd1243dSDimitry Andric                      $Vu,
665*bdd1243dSDimitry Andric                      (V6_vor (V6_vaslhv $Vu, $Vs),
666*bdd1243dSDimitry Andric                              (V6_vlsrhv $Vv, (VSubih 16, $Vs))))>;
667*bdd1243dSDimitry Andric    def: Pat<(Mfshl HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
668*bdd1243dSDimitry Andric             (V6_vmux (V6_veqw (V6_vand $Vs, (PS_vsplatiw (i32 31))), (V6_vd0)),
669*bdd1243dSDimitry Andric                      $Vu,
670*bdd1243dSDimitry Andric                      (V6_vor (V6_vaslwv $Vu, $Vs),
671*bdd1243dSDimitry Andric                              (V6_vlsrwv $Vv, (VSubiw 32, $Vs))))>;
672e8d8bef9SDimitry Andric  }
673e8d8bef9SDimitry Andric  let Predicates = [UseHVX,UseHVXV62], AddedComplexity = 10 in {
674*bdd1243dSDimitry Andric    // Do it as (Vu << Vs) | (Vv >> (BW-Vs)).
675*bdd1243dSDimitry Andric    // For Vs == 0 becomes Vu | (Vv >> -BW), since the shift amount is
676*bdd1243dSDimitry Andric    // sign-extended. Then this becomes Vu | (Vv << BW) == Vu.
677*bdd1243dSDimitry Andric    def: Pat<(Mfshl HVI16:$Vu, HVI16:$Vv, HVI16:$Vs),
678*bdd1243dSDimitry Andric             (V6_vor (V6_vaslhv $Vu, $Vs),
679*bdd1243dSDimitry Andric                     (V6_vlsrhv $Vv, (VSubih 16, $Vs)))>;
680*bdd1243dSDimitry Andric    def: Pat<(Mfshl HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
681*bdd1243dSDimitry Andric             (V6_vor (V6_vaslwv $Vu, $Vs),
682*bdd1243dSDimitry Andric                     (V6_vlsrwv $Vv, (VSubiw 32, $Vs)))>;
683*bdd1243dSDimitry Andric  }
684*bdd1243dSDimitry Andric  let Predicates = [UseHVX,UseHVXV66], AddedComplexity = 20 in {
685*bdd1243dSDimitry Andric    // Assume Vs > 0 (and within bit width)
686*bdd1243dSDimitry Andric    // Vx[1]:Vx[0] = V6_vasr_into Vx[0], Vv, Vs
687*bdd1243dSDimitry Andric    //   -->  (Vx[0]:Vx[0] & (ffffffff << -Vs)) | (Vv:00000000 << -Vs)
688*bdd1243dSDimitry Andric    // i.e. Vx[1] = insert ((Vv << -Vs) -> Vx[0])
689*bdd1243dSDimitry Andric    def: Pat<(Mfshl HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
690*bdd1243dSDimitry Andric             (HiVec (V6_vasr_into (Combinev (VecI32 (IMPLICIT_DEF)),
691*bdd1243dSDimitry Andric                                            (V6_vlsrwv $Vv, (VSubiw 32, $Vs))),
692*bdd1243dSDimitry Andric                                  $Vu,
693*bdd1243dSDimitry Andric                                  (V6_vsubw (V6_vd0), $Vs)))>;
694e8d8bef9SDimitry Andric  }
6950b57cec5SDimitry Andric
696*bdd1243dSDimitry Andric  // Mfshr hi, lo, amt
697*bdd1243dSDimitry Andric  def: Pat<(Mfshr HVI8:$Vu, HVI8:$Vv, HVI8:$Vs),
698*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vlsrhv (HiVec (V6_vshufoeb $Vu, $Vv)),
699*bdd1243dSDimitry Andric                                   (HiVec (V6_vzb $Vs))),
700*bdd1243dSDimitry Andric                        (V6_vlsrhv (LoVec (V6_vshufoeb $Vu, $Vv)),
701*bdd1243dSDimitry Andric                                   (LoVec (V6_vzb $Vs))))>;
702*bdd1243dSDimitry Andric  let Predicates = [UseHVX,UseHVXV60] in {
703*bdd1243dSDimitry Andric    def: Pat<(Mfshr HVI16:$Vu, HVI16:$Vv, HVI16:$Vs),
704*bdd1243dSDimitry Andric             (V6_vmux (V6_veqh $Vs, (V6_vd0)),
705*bdd1243dSDimitry Andric                      $Vv,
706*bdd1243dSDimitry Andric                      (V6_vor (V6_vaslhv $Vu, (VSubih 16, $Vs)),
707*bdd1243dSDimitry Andric                              (V6_vlsrhv $Vv, $Vs)))>;
708*bdd1243dSDimitry Andric    def: Pat<(Mfshr HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
709*bdd1243dSDimitry Andric             (V6_vmux (V6_veqw $Vs, (V6_vd0)),
710*bdd1243dSDimitry Andric                      $Vv,
711*bdd1243dSDimitry Andric                      (V6_vor (V6_vaslwv $Vu, (VSubiw 32, $Vs)),
712*bdd1243dSDimitry Andric                              (V6_vlsrwv $Vv, $Vs)))>;
713*bdd1243dSDimitry Andric  }
714*bdd1243dSDimitry Andric  let Predicates = [UseHVX,UseHVXV62], AddedComplexity = 10 in {
715*bdd1243dSDimitry Andric    // Do it as (Vu >> -(BW-Vs)) | (Vv >> Vs).
716*bdd1243dSDimitry Andric    // For Vs == 0 becomes (Vu << BW) | Vs == 0 | Vv
717*bdd1243dSDimitry Andric    def: Pat<(Mfshr HVI16:$Vu, HVI16:$Vv, HVI16:$Vs),
718*bdd1243dSDimitry Andric             (V6_vor (V6_vlsrhv $Vu, (V6_vsubh $Vs, (PS_vsplatih (i32 16)))),
719*bdd1243dSDimitry Andric                     (V6_vlsrhv $Vv, $Vs))>;
720*bdd1243dSDimitry Andric    def: Pat<(Mfshr HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
721*bdd1243dSDimitry Andric             (V6_vor (V6_vlsrwv $Vu, (V6_vsubw $Vs, (PS_vsplatiw (i32 32)))),
722*bdd1243dSDimitry Andric                     (V6_vlsrwv $Vv, $Vs))>;
723*bdd1243dSDimitry Andric  }
724*bdd1243dSDimitry Andric  let Predicates = [UseHVX,UseHVXV66], AddedComplexity = 20 in {
725*bdd1243dSDimitry Andric    // Assume Vs > 0 (and within bit width)
726*bdd1243dSDimitry Andric    // Vx[1]:Vx[0] = V6_vasr_into Vx[0], Vv, Vs
727*bdd1243dSDimitry Andric    //   -->  (Vx[0]:Vx[0] & (ffffffff >> Vs)) | (Vv:00000000 >> Vs)
728*bdd1243dSDimitry Andric    // i.e. Vx[0] = insert ((Vv >> Vs) -> Vx[0])
729*bdd1243dSDimitry Andric    def: Pat<(Mfshr HVI32:$Vu, HVI32:$Vv, HVI32:$Vs),
730*bdd1243dSDimitry Andric             (LoVec (V6_vasr_into (Combinev (VecI32 (IMPLICIT_DEF)),
731*bdd1243dSDimitry Andric                                            (V6_vlsrwv $Vv, $Vs)),
732*bdd1243dSDimitry Andric                                  $Vu,
733*bdd1243dSDimitry Andric                                  $Vs))>;
734*bdd1243dSDimitry Andric  }
735*bdd1243dSDimitry Andric
736*bdd1243dSDimitry Andric  def: Pat<(VecI16 (bswap HVI16:$Vs)),
737*bdd1243dSDimitry Andric           (V6_vdelta HvxVR:$Vs, (PS_vsplatib (i32 0x01)))>;
738*bdd1243dSDimitry Andric  def: Pat<(VecI32 (bswap HVI32:$Vs)),
739*bdd1243dSDimitry Andric           (V6_vdelta HvxVR:$Vs, (PS_vsplatib (i32 0x03)))>;
740*bdd1243dSDimitry Andric
7410b57cec5SDimitry Andric  def: Pat<(VecI8 (ctpop HVI8:$Vs)),
742*bdd1243dSDimitry Andric           (V6_vshuffeb (V6_vpopcounth (HiVec (V6_vzb HvxVR:$Vs))),
743*bdd1243dSDimitry Andric                        (V6_vpopcounth (LoVec (V6_vzb HvxVR:$Vs))))>;
7440b57cec5SDimitry Andric  def: Pat<(VecI16 (ctpop HVI16:$Vs)), (V6_vpopcounth HvxVR:$Vs)>;
7450b57cec5SDimitry Andric  def: Pat<(VecI32 (ctpop HVI32:$Vs)),
7460b57cec5SDimitry Andric           (V6_vaddw (LoVec (V6_vzh (V6_vpopcounth HvxVR:$Vs))),
7470b57cec5SDimitry Andric                     (HiVec (V6_vzh (V6_vpopcounth HvxVR:$Vs))))>;
7480b57cec5SDimitry Andric
7490b57cec5SDimitry Andric  def: Pat<(VecI8 (ctlz HVI8:$Vs)),
750*bdd1243dSDimitry Andric           (V6_vsubb (V6_vshuffeb (V6_vcl0h (HiVec (V6_vzb HvxVR:$Vs))),
751*bdd1243dSDimitry Andric                                  (V6_vcl0h (LoVec (V6_vzb HvxVR:$Vs)))),
752*bdd1243dSDimitry Andric                     (PS_vsplatib (i32 0x08)))>;
753e8d8bef9SDimitry Andric
7540b57cec5SDimitry Andric  def: Pat<(VecI16 (ctlz HVI16:$Vs)), (V6_vcl0h HvxVR:$Vs)>;
7550b57cec5SDimitry Andric  def: Pat<(VecI32 (ctlz HVI32:$Vs)), (V6_vcl0w HvxVR:$Vs)>;
7560b57cec5SDimitry Andric}
7570b57cec5SDimitry Andric
7580b57cec5SDimitry Andricclass HvxSel_pat<InstHexagon MI, PatFrag RegPred>
7590b57cec5SDimitry Andric  : Pat<(select I1:$Pu, RegPred:$Vs, RegPred:$Vt),
7600b57cec5SDimitry Andric        (MI I1:$Pu, RegPred:$Vs, RegPred:$Vt)>;
7610b57cec5SDimitry Andric
7620b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
7630b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI8>;
7640b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI16>;
7650b57cec5SDimitry Andric  def: HvxSel_pat<PS_vselect, HVI32>;
7660b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI8>;
7670b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI16>;
7680b57cec5SDimitry Andric  def: HvxSel_pat<PS_wselect, HWI32>;
7690b57cec5SDimitry Andric}
7700b57cec5SDimitry Andric
771*bdd1243dSDimitry Andricdef V2Q: OutPatFrag<(ops node:$Vs), (V6_vandvrt $Vs, (ToI32 -1))>;
77204eeddc0SDimitry Andric
77381ad6265SDimitry Andriclet Predicates = [UseHVX] in {
77481ad6265SDimitry Andric  def: Pat<(select I1:$Pu, VecQ8:$Qs, VecQ8:$Qt),
77504eeddc0SDimitry Andric           (V2Q (PS_vselect $Pu, (Q2V $Qs), (Q2V $Qt)))>;
77681ad6265SDimitry Andric  def: Pat<(select I1:$Pu, VecQ16:$Qs, VecQ16:$Qt),
77781ad6265SDimitry Andric           (V2Q (PS_vselect $Pu, (Q2V $Qs), (Q2V $Qt)))>;
77881ad6265SDimitry Andric  def: Pat<(select I1:$Pu, VecQ32:$Qs, VecQ32:$Qt),
77981ad6265SDimitry Andric           (V2Q (PS_vselect $Pu, (Q2V $Qs), (Q2V $Qt)))>;
78081ad6265SDimitry Andric}
78104eeddc0SDimitry Andric
7820b57cec5SDimitry Andriclet Predicates = [UseHVX] in {
7830b57cec5SDimitry Andric  def: Pat<(VecQ8   (qtrue)), (PS_qtrue)>;
7840b57cec5SDimitry Andric  def: Pat<(VecQ16  (qtrue)), (PS_qtrue)>;
7850b57cec5SDimitry Andric  def: Pat<(VecQ32  (qtrue)), (PS_qtrue)>;
7860b57cec5SDimitry Andric  def: Pat<(VecQ8  (qfalse)), (PS_qfalse)>;
7870b57cec5SDimitry Andric  def: Pat<(VecQ16 (qfalse)), (PS_qfalse)>;
7880b57cec5SDimitry Andric  def: Pat<(VecQ32 (qfalse)), (PS_qfalse)>;
7890b57cec5SDimitry Andric
7900b57cec5SDimitry Andric  def: Pat<(vnot  HQ8:$Qs), (V6_pred_not HvxQR:$Qs)>;
7910b57cec5SDimitry Andric  def: Pat<(vnot HQ16:$Qs), (V6_pred_not HvxQR:$Qs)>;
7920b57cec5SDimitry Andric  def: Pat<(vnot HQ32:$Qs), (V6_pred_not HvxQR:$Qs)>;
7930b57cec5SDimitry Andric  def: Pat<(qnot  HQ8:$Qs), (V6_pred_not HvxQR:$Qs)>;
7940b57cec5SDimitry Andric  def: Pat<(qnot HQ16:$Qs), (V6_pred_not HvxQR:$Qs)>;
7950b57cec5SDimitry Andric  def: Pat<(qnot HQ32:$Qs), (V6_pred_not HvxQR:$Qs)>;
7960b57cec5SDimitry Andric
7970b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,  And,  VecQ8,   HQ8>;
7980b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,  And, VecQ16,  HQ16>;
7990b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_and,  And, VecQ32,  HQ32>;
8000b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,    Or,  VecQ8,   HQ8>;
8010b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,    Or, VecQ16,  HQ16>;
8020b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_or,    Or, VecQ32,  HQ32>;
8030b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,  Xor,  VecQ8,   HQ8>;
8040b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,  Xor, VecQ16,  HQ16>;
8050b57cec5SDimitry Andric  def: OpR_RR_pat<V6_pred_xor,  Xor, VecQ32,  HQ32>;
8060b57cec5SDimitry Andric
807fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n,  VNot2<And, qnot>,  VecQ8,   HQ8>;
808fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n,  VNot2<And, qnot>, VecQ16,  HQ16>;
809fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_and_n,  VNot2<And, qnot>, VecQ32,  HQ32>;
810fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,    VNot2<Or, qnot>,  VecQ8,   HQ8>;
811fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,    VNot2<Or, qnot>, VecQ16,  HQ16>;
812fe6060f1SDimitry Andric  def: OpR_RR_pat<V6_pred_or_n,    VNot2<Or, qnot>, VecQ32,  HQ32>;
8130b57cec5SDimitry Andric
8140b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqb,      seteq,  VecQ8,  HVI8>;
8150b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqh,      seteq, VecQ16, HVI16>;
8160b57cec5SDimitry Andric  def: OpR_RR_pat<V6_veqw,      seteq, VecQ32, HVI32>;
8170b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtb,      setgt,  VecQ8,  HVI8>;
8180b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgth,      setgt, VecQ16, HVI16>;
8190b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtw,      setgt, VecQ32, HVI32>;
8200b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtub,    setugt,  VecQ8,  HVI8>;
8210b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtuh,    setugt, VecQ16, HVI16>;
8220b57cec5SDimitry Andric  def: OpR_RR_pat<V6_vgtuw,    setugt, VecQ32, HVI32>;
8230b57cec5SDimitry Andric
8240b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_and,    And,  seteq,    HQ8,  HVI8,  HVI8>;
8250b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_or,      Or,  seteq,    HQ8,  HVI8,  HVI8>;
8260b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqb_xor,    Xor,  seteq,    HQ8,  HVI8,  HVI8>;
8270b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_and,    And,  seteq,   HQ16, HVI16, HVI16>;
8280b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_or,      Or,  seteq,   HQ16, HVI16, HVI16>;
8290b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqh_xor,    Xor,  seteq,   HQ16, HVI16, HVI16>;
8300b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_and,    And,  seteq,   HQ32, HVI32, HVI32>;
8310b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_or,      Or,  seteq,   HQ32, HVI32, HVI32>;
8320b57cec5SDimitry Andric  def: AccRRR_pat<V6_veqw_xor,    Xor,  seteq,   HQ32, HVI32, HVI32>;
8330b57cec5SDimitry Andric
8340b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_and,    And,  setgt,    HQ8,  HVI8,  HVI8>;
8350b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_or,      Or,  setgt,    HQ8,  HVI8,  HVI8>;
8360b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtb_xor,    Xor,  setgt,    HQ8,  HVI8,  HVI8>;
8370b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_and,    And,  setgt,   HQ16, HVI16, HVI16>;
8380b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_or,      Or,  setgt,   HQ16, HVI16, HVI16>;
8390b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgth_xor,    Xor,  setgt,   HQ16, HVI16, HVI16>;
8400b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_and,    And,  setgt,   HQ32, HVI32, HVI32>;
8410b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_or,      Or,  setgt,   HQ32, HVI32, HVI32>;
8420b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtw_xor,    Xor,  setgt,   HQ32, HVI32, HVI32>;
8430b57cec5SDimitry Andric
8440b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_and,   And, setugt,    HQ8,  HVI8,  HVI8>;
8450b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_or,     Or, setugt,    HQ8,  HVI8,  HVI8>;
8460b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtub_xor,   Xor, setugt,    HQ8,  HVI8,  HVI8>;
8470b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_and,   And, setugt,   HQ16, HVI16, HVI16>;
8480b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_or,     Or, setugt,   HQ16, HVI16, HVI16>;
8490b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuh_xor,   Xor, setugt,   HQ16, HVI16, HVI16>;
8500b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_and,   And, setugt,   HQ32, HVI32, HVI32>;
8510b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_or,     Or, setugt,   HQ32, HVI32, HVI32>;
8520b57cec5SDimitry Andric  def: AccRRR_pat<V6_vgtuw_xor,   Xor, setugt,   HQ32, HVI32, HVI32>;
8530b57cec5SDimitry Andric}
85404eeddc0SDimitry Andric
85504eeddc0SDimitry Andriclet Predicates = [UseHVXV68, UseHVXFloatingPoint] in {
85604eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqh,              seteq,  VecQ16, HVF16>;
85704eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqh,             setoeq,  VecQ16, HVF16>;
85804eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqh,             setueq,  VecQ16, HVF16>;
85904eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgthf,             setgt,  VecQ16, HVF16>;
86004eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgthf,            setogt,  VecQ16, HVF16>;
86104eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgthf,            setugt,  VecQ16, HVF16>;
86204eeddc0SDimitry Andric
86304eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqw,              seteq,  VecQ32, HVF32>;
86404eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqw,             setoeq,  VecQ32, HVF32>;
86504eeddc0SDimitry Andric  def: OpR_RR_pat<V6_veqw,             setueq,  VecQ32, HVF32>;
86604eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgtsf,             setgt,  VecQ32, HVF32>;
86704eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgtsf,            setogt,  VecQ32, HVF32>;
86804eeddc0SDimitry Andric  def: OpR_RR_pat<V6_vgtsf,            setugt,  VecQ32, HVF32>;
86904eeddc0SDimitry Andric
87004eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_and,    And,          seteq,  HQ16, HVF16, HVF16>;
87104eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_or,      Or,          seteq,  HQ16, HVF16, HVF16>;
87204eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_xor,    Xor,          seteq,  HQ16, HVF16, HVF16>;
87304eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_and,    And,         setoeq,  HQ16, HVF16, HVF16>;
87404eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_or,      Or,         setoeq,  HQ16, HVF16, HVF16>;
87504eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_xor,    Xor,         setoeq,  HQ16, HVF16, HVF16>;
87604eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_and,    And,         setueq,  HQ16, HVF16, HVF16>;
87704eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_or,      Or,         setueq,  HQ16, HVF16, HVF16>;
87804eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqh_xor,    Xor,         setueq,  HQ16, HVF16, HVF16>;
87904eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_and,   And,          setgt,  HQ16, HVF16, HVF16>;
88004eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_or,     Or,          setgt,  HQ16, HVF16, HVF16>;
88104eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_xor,   Xor,          setgt,  HQ16, HVF16, HVF16>;
88204eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_and,   And,         setogt,  HQ16, HVF16, HVF16>;
88304eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_or,     Or,         setogt,  HQ16, HVF16, HVF16>;
88404eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_xor,   Xor,         setogt,  HQ16, HVF16, HVF16>;
88504eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_and,   And,         setugt,  HQ16, HVF16, HVF16>;
88604eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_or,     Or,         setugt,  HQ16, HVF16, HVF16>;
88704eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgthf_xor,   Xor,         setugt,  HQ16, HVF16, HVF16>;
88804eeddc0SDimitry Andric
88904eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_and,    And,          seteq,  HQ32, HVF32, HVF32>;
89004eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_or,      Or,          seteq,  HQ32, HVF32, HVF32>;
89104eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_xor,    Xor,          seteq,  HQ32, HVF32, HVF32>;
89204eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_and,    And,         setoeq,  HQ32, HVF32, HVF32>;
89304eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_or,      Or,         setoeq,  HQ32, HVF32, HVF32>;
89404eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_xor,    Xor,         setoeq,  HQ32, HVF32, HVF32>;
89504eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_and,    And,         setueq,  HQ32, HVF32, HVF32>;
89604eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_or,      Or,         setueq,  HQ32, HVF32, HVF32>;
89704eeddc0SDimitry Andric  def: AccRRR_pat<V6_veqw_xor,    Xor,         setueq,  HQ32, HVF32, HVF32>;
89804eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_and,   And,          setgt,  HQ32, HVF32, HVF32>;
89904eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_or,     Or,          setgt,  HQ32, HVF32, HVF32>;
90004eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_xor,   Xor,          setgt,  HQ32, HVF32, HVF32>;
90104eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_and,   And,         setogt,  HQ32, HVF32, HVF32>;
90204eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_or,     Or,         setogt,  HQ32, HVF32, HVF32>;
90304eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_xor,   Xor,         setogt,  HQ32, HVF32, HVF32>;
90404eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_and,   And,         setugt,  HQ32, HVF32, HVF32>;
90504eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_or,     Or,         setugt,  HQ32, HVF32, HVF32>;
90604eeddc0SDimitry Andric  def: AccRRR_pat<V6_vgtsf_xor,   Xor,         setugt,  HQ32, HVF32, HVF32>;
90704eeddc0SDimitry Andric
90804eeddc0SDimitry Andric  def: Pat<(VecQ16 (setone HVF16:$Vt, HVF16:$Vu)),
90904eeddc0SDimitry Andric           (V6_pred_not (V6_veqh HvxVR:$Vt, HvxVR:$Vu))>;
91004eeddc0SDimitry Andric
91104eeddc0SDimitry Andric  def: Pat<(VecQ32 (setone HVF32:$Vt, HVF32:$Vu)),
91204eeddc0SDimitry Andric           (V6_pred_not (V6_veqw HvxVR:$Vt, HvxVR:$Vu))>;
91304eeddc0SDimitry Andric}
914*bdd1243dSDimitry Andric
915*bdd1243dSDimitry Andric// Multiply high for non-i32 types
916*bdd1243dSDimitry Andricdef: Pat<(VecI8  (mulhs  HVI8:$Vu,  HVI8:$Vv)),
917*bdd1243dSDimitry Andric         (V6_vshuffob (HiVec (V6_vmpybv $Vu, $Vv)),
918*bdd1243dSDimitry Andric                      (LoVec (V6_vmpybv $Vu, $Vv)))>;
919*bdd1243dSDimitry Andricdef: Pat<(VecI16 (mulhs HVI16:$Vu, HVI16:$Vv)),
920*bdd1243dSDimitry Andric         (V6_vshufoh (HiVec (V6_vmpyhv $Vu, $Vv)),
921*bdd1243dSDimitry Andric                     (LoVec (V6_vmpyhv $Vu, $Vv)))>;
922*bdd1243dSDimitry Andricdef: Pat<(VecI8  (mulhu  HVI8:$Vu,  HVI8:$Vv)),
923*bdd1243dSDimitry Andric         (V6_vshuffob (HiVec (V6_vmpyubv $Vu, $Vv)),
924*bdd1243dSDimitry Andric                      (LoVec (V6_vmpyubv $Vu, $Vv)))>;
925*bdd1243dSDimitry Andricdef: Pat<(VecI16 (mulhu HVI16:$Vu, HVI16:$Vv)),
926*bdd1243dSDimitry Andric         (V6_vshufoh (HiVec (V6_vmpyuhv $Vu, $Vv)),
927*bdd1243dSDimitry Andric                     (LoVec (V6_vmpyuhv $Vu, $Vv)))>;
928*bdd1243dSDimitry Andriclet Predicates = [UseHVXV69], AddedComplexity = 20 in {
929*bdd1243dSDimitry Andric  def: Pat<(VecI16 (mulhu HVI16:$Vu, HVI16:$Vv)),
930*bdd1243dSDimitry Andric           (V6_vmpyuhvs $Vu, $Vv)>;
931*bdd1243dSDimitry Andric}
932*bdd1243dSDimitry Andric
933*bdd1243dSDimitry Andriclet Predicates = [UseHVXV60] in {
934*bdd1243dSDimitry Andric  // V60 doesn't have vabsb or byte shifts.
935*bdd1243dSDimitry Andric  // Do the "mask = x >> width-1; abs = (x + mask) ^ mask" trick.
936*bdd1243dSDimitry Andric  // v31:30.h = vsxt(Inp.b)             ; generate masks in odd bytes in
937*bdd1243dSDimitry Andric  //                                    ; interleaved half-words
938*bdd1243dSDimitry Andric  // v29:28.b = vshuffoe(v31.b,v30.b)   ; collect odd/even bytes, masks = v29
939*bdd1243dSDimitry Andric  // v27.b    = vadd(Inp.b,v29.b)       ; x + masks
940*bdd1243dSDimitry Andric  // Abs      = vxor(v27,v29)           ;   ^ masks
941*bdd1243dSDimitry Andric  def: Pat<(VecI8 (abs HVI8:$Vs)),
942*bdd1243dSDimitry Andric    (V6_vxor HvxVR:$Vs,
943*bdd1243dSDimitry Andric      (V6_vaddb HvxVR:$Vs,
944*bdd1243dSDimitry Andric        (HiVec
945*bdd1243dSDimitry Andric          (V6_vshufoeb
946*bdd1243dSDimitry Andric            (HiVec (V6_vsb HvxVR:$Vs)),
947*bdd1243dSDimitry Andric            (LoVec (V6_vsb HvxVR:$Vs))))))>;
948*bdd1243dSDimitry Andric}
949*bdd1243dSDimitry Andric
950*bdd1243dSDimitry Andriclet Predicates = [UseHVXV62], AddedComplexity = 20 in {
951*bdd1243dSDimitry Andric  def: Pat<(VecI8 (abs HVI8:$Vs)), (V6_vabsb HvxVR:$Vs)>;
952*bdd1243dSDimitry Andric}
953*bdd1243dSDimitry Andric
954*bdd1243dSDimitry Andricdef: Pat<(VecI16 (abs HVI16:$Vs)), (V6_vabsh HvxVR:$Vs)>;
955*bdd1243dSDimitry Andricdef: Pat<(VecI32 (abs HVI32:$Vs)), (V6_vabsw HvxVR:$Vs)>;
956*bdd1243dSDimitry Andric
957*bdd1243dSDimitry Andric// If a node takes an MVT type as a parameter, the argument must be
958*bdd1243dSDimitry Andric// a name of a member of MVT.
959*bdd1243dSDimitry Andricmulticlass Saturates<ValueType HvxTy_i8, ValueType HvxTy_i16> {
960*bdd1243dSDimitry Andric  def: Pat<(VecI8 (ssat HWI16:$Vss, HvxTy_i8)),
961*bdd1243dSDimitry Andric           (V6_vpackhb_sat (HiVec $Vss), (LoVec $Vss))>;
962*bdd1243dSDimitry Andric  def: Pat<(VecI8 (ssat (concat_vectors HWI32:$Vss, HWI32:$Vtt), HvxTy_i8)),
963*bdd1243dSDimitry Andric           (V6_vpackhb_sat (V6_vpackwh_sat (HiVec $Vtt), (LoVec $Vtt)),
964*bdd1243dSDimitry Andric                           (V6_vpackwh_sat (HiVec $Vss), (LoVec $Vss)))>;
965*bdd1243dSDimitry Andric  def: Pat<(VecI16 (ssat HWI32:$Vss, HvxTy_i16)),
966*bdd1243dSDimitry Andric           (V6_vpackwh_sat (HiVec $Vss), (LoVec $Vss))>;
967*bdd1243dSDimitry Andric
968*bdd1243dSDimitry Andric  def: Pat<(VecI8 (usat HWI16:$Vss, HvxTy_i8)),
969*bdd1243dSDimitry Andric           (V6_vpackhub_sat (HiVec $Vss), (LoVec $Vss))>;
970*bdd1243dSDimitry Andric  def: Pat<(VecI8 (usat (concat_vectors HWI32:$Vss, HWI32:$Vtt), HvxTy_i8)),
971*bdd1243dSDimitry Andric           (V6_vpackhub_sat (V6_vpackwuh_sat (HiVec $Vtt), (LoVec $Vtt)),
972*bdd1243dSDimitry Andric                            (V6_vpackwuh_sat (HiVec $Vss), (LoVec $Vss)))>;
973*bdd1243dSDimitry Andric  def: Pat<(VecI16 (usat HWI32:$Vss, HvxTy_i16)),
974*bdd1243dSDimitry Andric           (V6_vpackwuh_sat (HiVec $Vss), (LoVec $Vss))>;
975*bdd1243dSDimitry Andric}
976*bdd1243dSDimitry Andriclet Predicates = [UseHVX64B] in {
977*bdd1243dSDimitry Andric  defm: Saturates<v64i8, v32i16>;
978*bdd1243dSDimitry Andric}
979*bdd1243dSDimitry Andriclet Predicates = [UseHVX128B] in {
980*bdd1243dSDimitry Andric  defm: Saturates<v128i8, v64i16>;
981*bdd1243dSDimitry Andric}
982