Skip to content

Commit c95febc

Browse files
committed
[X86] LowerBITREVERSE - add handling for all legal 128/256/512-bit vector types, not just vXi8
Move the BITREVERSE(BSWAP(X)) expansion into LowerBITREVERSE to help simplify #81764
1 parent 9d9c012 commit c95febc

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
12411241
setOperationAction(ISD::ABS, MVT::v16i8, Legal);
12421242
setOperationAction(ISD::ABS, MVT::v8i16, Legal);
12431243
setOperationAction(ISD::ABS, MVT::v4i32, Legal);
1244-
setOperationAction(ISD::BITREVERSE, MVT::v16i8, Custom);
1245-
setOperationAction(ISD::CTLZ, MVT::v16i8, Custom);
1246-
setOperationAction(ISD::CTLZ, MVT::v8i16, Custom);
1247-
setOperationAction(ISD::CTLZ, MVT::v4i32, Custom);
1248-
setOperationAction(ISD::CTLZ, MVT::v2i64, Custom);
1244+
1245+
for (auto VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64}) {
1246+
setOperationAction(ISD::BITREVERSE, VT, Custom);
1247+
setOperationAction(ISD::CTLZ, VT, Custom);
1248+
}
12491249

12501250
// These might be better off as horizontal vector ops.
12511251
setOperationAction(ISD::ADD, MVT::i16, Custom);
@@ -1341,10 +1341,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
13411341
// XOP can efficiently perform BITREVERSE with VPPERM.
13421342
for (auto VT : { MVT::i8, MVT::i16, MVT::i32, MVT::i64 })
13431343
setOperationAction(ISD::BITREVERSE, VT, Custom);
1344-
1345-
for (auto VT : { MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64,
1346-
MVT::v32i8, MVT::v16i16, MVT::v8i32, MVT::v4i64 })
1347-
setOperationAction(ISD::BITREVERSE, VT, Custom);
13481344
}
13491345

13501346
if (!Subtarget.useSoftFloat() && Subtarget.hasAVX()) {
@@ -1461,12 +1457,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
14611457
setOperationAction(ISD::TRUNCATE, MVT::v32i32, Custom);
14621458
setOperationAction(ISD::TRUNCATE, MVT::v32i64, Custom);
14631459

1464-
setOperationAction(ISD::BITREVERSE, MVT::v32i8, Custom);
1465-
14661460
for (auto VT : { MVT::v32i8, MVT::v16i16, MVT::v8i32, MVT::v4i64 }) {
14671461
setOperationAction(ISD::SETCC, VT, Custom);
14681462
setOperationAction(ISD::CTPOP, VT, Custom);
14691463
setOperationAction(ISD::CTLZ, VT, Custom);
1464+
setOperationAction(ISD::BITREVERSE, VT, Custom);
14701465

14711466
// The condition codes aren't legal in SSE/AVX and under AVX512 we use
14721467
// setcc all the way to isel and prefer SETGT in some isel patterns.
@@ -1841,8 +1836,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
18411836
setOperationAction(ISD::SMULO, MVT::v64i8, Custom);
18421837
setOperationAction(ISD::UMULO, MVT::v64i8, Custom);
18431838

1844-
setOperationAction(ISD::BITREVERSE, MVT::v64i8, Custom);
1845-
18461839
for (auto VT : { MVT::v64i8, MVT::v32i16, MVT::v16i32, MVT::v8i64 }) {
18471840
setOperationAction(ISD::SRL, VT, Custom);
18481841
setOperationAction(ISD::SHL, VT, Custom);
@@ -1852,6 +1845,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
18521845
setOperationAction(ISD::SETCC, VT, Custom);
18531846
setOperationAction(ISD::ABDS, VT, Custom);
18541847
setOperationAction(ISD::ABDU, VT, Custom);
1848+
setOperationAction(ISD::BITREVERSE, VT, Custom);
18551849

18561850
// The condition codes aren't legal in SSE/AVX and under AVX512 we use
18571851
// setcc all the way to isel and prefer SETGT in some isel patterns.
@@ -31180,17 +31174,25 @@ static SDValue LowerBITREVERSE(SDValue Op, const X86Subtarget &Subtarget,
3118031174
SDValue In = Op.getOperand(0);
3118131175
SDLoc DL(Op);
3118231176

31183-
assert(VT.getScalarType() == MVT::i8 &&
31184-
"Only byte vector BITREVERSE supported");
31185-
31186-
// Split v64i8 without BWI so that we can still use the PSHUFB lowering.
31187-
if (VT == MVT::v64i8 && !Subtarget.hasBWI())
31177+
// Split 512-bit ops without BWI so that we can still use the PSHUFB lowering.
31178+
if (VT.is512BitVector() && !Subtarget.hasBWI())
3118831179
return splitVectorIntUnary(Op, DAG);
3118931180

3119031181
// Decompose 256-bit ops into smaller 128-bit ops on pre-AVX2.
31191-
if (VT == MVT::v32i8 && !Subtarget.hasInt256())
31182+
if (VT.is256BitVector() && !Subtarget.hasInt256())
3119231183
return splitVectorIntUnary(Op, DAG);
3119331184

31185+
// Lower vXi16/vXi32/vXi64 as BSWAP + vXi8 BITREVERSE.
31186+
if (VT.getScalarType() != MVT::i8) {
31187+
MVT ByteVT = MVT::getVectorVT(MVT::i8, VT.getSizeInBits() / 8);
31188+
SDValue Res = DAG.getNode(ISD::BSWAP, DL, VT, In);
31189+
Res = DAG.getBitcast(ByteVT, Res);
31190+
Res = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Res);
31191+
return DAG.getBitcast(VT, Res);
31192+
}
31193+
assert(VT.isVector() && VT.getScalarType() == MVT::i8 &&
31194+
"Only byte vector BITREVERSE supported");
31195+
3119431196
unsigned NumElts = VT.getVectorNumElements();
3119531197

3119631198
// If we have GFNI, we can use GF2P8AFFINEQB to reverse the bits.

0 commit comments

Comments
 (0)