Skip to content

Commit 094f771

Browse files
Krzysztof Parzyszektstellar
Krzysztof Parzyszek
authored andcommitted
[Hexagon] Add patterns for bspap/bitreverse for scalar vectors
Fixes llvm#62474 (cherry picked from commit c7b291a)
1 parent 07808f6 commit 094f771

File tree

3 files changed

+360
-102
lines changed

3 files changed

+360
-102
lines changed

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
16281628
ISD::UADDO, ISD::SSUBO, ISD::USUBO, ISD::SMUL_LOHI, ISD::UMUL_LOHI,
16291629
// Logical/bit:
16301630
ISD::AND, ISD::OR, ISD::XOR, ISD::ROTL, ISD::ROTR,
1631-
ISD::CTPOP, ISD::CTLZ, ISD::CTTZ,
1631+
ISD::CTPOP, ISD::CTLZ, ISD::CTTZ, ISD::BSWAP, ISD::BITREVERSE,
16321632
// Floating point arithmetic/math functions:
16331633
ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA, ISD::FDIV,
16341634
ISD::FREM, ISD::FNEG, ISD::FABS, ISD::FSQRT, ISD::FSIN,
@@ -1701,8 +1701,11 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
17011701
setOperationAction(ISD::OR, NativeVT, Legal);
17021702
setOperationAction(ISD::XOR, NativeVT, Legal);
17031703

1704-
if (NativeVT.getVectorElementType() != MVT::i1)
1704+
if (NativeVT.getVectorElementType() != MVT::i1) {
17051705
setOperationAction(ISD::SPLAT_VECTOR, NativeVT, Legal);
1706+
setOperationAction(ISD::BSWAP, NativeVT, Legal);
1707+
setOperationAction(ISD::BITREVERSE, NativeVT, Legal);
1708+
}
17061709
}
17071710

17081711
for (MVT VT : {MVT::v8i8, MVT::v4i16, MVT::v2i32}) {

llvm/lib/Target/Hexagon/HexagonPatterns.td

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def usat: PatFrag<(ops node:$V, node:$Ty), (HexagonUSAT node:$V, node:$Ty)>;
117117

118118
// Pattern fragments to extract the low and high subregisters from a
119119
// 64-bit value.
120-
def LoReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG (i64 $Rs), isub_lo)>;
121-
def HiReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG (i64 $Rs), isub_hi)>;
120+
def LoReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG $Rs, isub_lo)>;
121+
def HiReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG $Rs, isub_hi)>;
122122

123123
def IsOrAdd: PatFrag<(ops node:$A, node:$B), (or node:$A, node:$B), [{
124124
return isOrEquivalentToAdd(N);
@@ -1123,6 +1123,12 @@ def: Pat<(bswap I32:$Rs), (A2_swiz I32:$Rs)>;
11231123
def: Pat<(bswap I64:$Rss), (Combinew (A2_swiz (LoReg $Rss)),
11241124
(A2_swiz (HiReg $Rss)))>;
11251125

1126+
def: Pat<(bswap V2I16:$Rs), (A2_combine_lh (A2_swiz $Rs), (A2_swiz $Rs))>;
1127+
def: Pat<(bswap V2I32:$Rs), (Combinew (A2_swiz (HiReg $Rs)),
1128+
(A2_swiz (LoReg $Rs)))>;
1129+
def: Pat<(bswap V4I16:$Rs), (A2_orp (S2_lsr_i_vh $Rs, 8),
1130+
(S2_asl_i_vh $Rs, 8))>;
1131+
11261132
def: Pat<(shl s6_0ImmPred:$s6, I32:$Rt), (S4_lsli imm:$s6, I32:$Rt)>;
11271133
def: Pat<(shl I32:$Rs, (i32 16)), (A2_aslh I32:$Rs)>;
11281134
def: Pat<(sra I32:$Rs, (i32 16)), (A2_asrh I32:$Rs)>;
@@ -1854,6 +1860,20 @@ def: Pat<(i32 (ctpop I32:$Rs)), (S5_popcountp (A4_combineir 0, I32:$Rs))>;
18541860
def: Pat<(bitreverse I32:$Rs), (S2_brev I32:$Rs)>;
18551861
def: Pat<(bitreverse I64:$Rss), (S2_brevp I64:$Rss)>;
18561862

1863+
def: Pat<(bitreverse V4I8:$Rs), (A2_swiz (S2_brev $Rs))>;
1864+
def: Pat<(bitreverse V8I8:$Rs), (Combinew (A2_swiz (LoReg (S2_brevp $Rs))),
1865+
(A2_swiz (HiReg (S2_brevp $Rs))))>;
1866+
def: Pat<(bitreverse V2I16:$Rs), (A2_combine_lh (S2_brev $Rs),
1867+
(S2_brev $Rs))>;
1868+
def: Pat<(bitreverse V4I16:$Rs),
1869+
(Combinew (A2_combine_lh (LoReg (S2_brevp $Rs)),
1870+
(LoReg (S2_brevp $Rs))),
1871+
(A2_combine_lh (HiReg (S2_brevp $Rs)),
1872+
(HiReg (S2_brevp $Rs))))>;
1873+
def: Pat<(bitreverse V2I32:$Rs),
1874+
(Combinew (i32 (LoReg (S2_brevp $Rs))),
1875+
(i32 (HiReg (S2_brevp $Rs))))>;
1876+
18571877
let AddedComplexity = 20 in { // Complexity greater than and/or/xor
18581878
def: Pat<(and I32:$Rs, IsNPow2_32:$V),
18591879
(S2_clrbit_i IntRegs:$Rs, (LogN2_32 $V))>;

0 commit comments

Comments
 (0)