[llvm] c95febc - [X86] LowerBITREVERSE - add handling for all legal 128/256/512-bit vector types, not just vXi8
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 09:46:44 PST 2024
Author: Simon Pilgrim
Date: 2024-02-27T17:46:30Z
New Revision: c95febcb4008c40a2b514bd6e2b56e0aa17457a3
URL: https://github.com/llvm/llvm-project/commit/c95febcb4008c40a2b514bd6e2b56e0aa17457a3
DIFF: https://github.com/llvm/llvm-project/commit/c95febcb4008c40a2b514bd6e2b56e0aa17457a3.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index a134ca32c66bd3..0722c402348ee0 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -1241,11 +1241,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::ABS, MVT::v16i8, Legal);
setOperationAction(ISD::ABS, MVT::v8i16, Legal);
setOperationAction(ISD::ABS, MVT::v4i32, Legal);
- setOperationAction(ISD::BITREVERSE, MVT::v16i8, Custom);
- setOperationAction(ISD::CTLZ, MVT::v16i8, Custom);
- setOperationAction(ISD::CTLZ, MVT::v8i16, Custom);
- setOperationAction(ISD::CTLZ, MVT::v4i32, Custom);
- setOperationAction(ISD::CTLZ, MVT::v2i64, Custom);
+
+ for (auto VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64}) {
+ setOperationAction(ISD::BITREVERSE, VT, Custom);
+ setOperationAction(ISD::CTLZ, VT, Custom);
+ }
// These might be better off as horizontal vector ops.
setOperationAction(ISD::ADD, MVT::i16, Custom);
@@ -1341,10 +1341,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
// XOP can efficiently perform BITREVERSE with VPPERM.
for (auto VT : { MVT::i8, MVT::i16, MVT::i32, MVT::i64 })
setOperationAction(ISD::BITREVERSE, VT, Custom);
-
- for (auto VT : { MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64,
- MVT::v32i8, MVT::v16i16, MVT::v8i32, MVT::v4i64 })
- setOperationAction(ISD::BITREVERSE, VT, Custom);
}
if (!Subtarget.useSoftFloat() && Subtarget.hasAVX()) {
@@ -1461,12 +1457,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::TRUNCATE, MVT::v32i32, Custom);
setOperationAction(ISD::TRUNCATE, MVT::v32i64, Custom);
- setOperationAction(ISD::BITREVERSE, MVT::v32i8, Custom);
-
for (auto VT : { MVT::v32i8, MVT::v16i16, MVT::v8i32, MVT::v4i64 }) {
setOperationAction(ISD::SETCC, VT, Custom);
setOperationAction(ISD::CTPOP, VT, Custom);
setOperationAction(ISD::CTLZ, VT, Custom);
+ setOperationAction(ISD::BITREVERSE, VT, Custom);
// The condition codes aren't legal in SSE/AVX and under AVX512 we use
// setcc all the way to isel and prefer SETGT in some isel patterns.
@@ -1841,8 +1836,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::SMULO, MVT::v64i8, Custom);
setOperationAction(ISD::UMULO, MVT::v64i8, Custom);
- setOperationAction(ISD::BITREVERSE, MVT::v64i8, Custom);
-
for (auto VT : { MVT::v64i8, MVT::v32i16, MVT::v16i32, MVT::v8i64 }) {
setOperationAction(ISD::SRL, VT, Custom);
setOperationAction(ISD::SHL, VT, Custom);
@@ -1852,6 +1845,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::SETCC, VT, Custom);
setOperationAction(ISD::ABDS, VT, Custom);
setOperationAction(ISD::ABDU, VT, Custom);
+ setOperationAction(ISD::BITREVERSE, VT, Custom);
// The condition codes aren't legal in SSE/AVX and under AVX512 we use
// 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,
SDValue In = Op.getOperand(0);
SDLoc DL(Op);
- assert(VT.getScalarType() == MVT::i8 &&
- "Only byte vector BITREVERSE supported");
-
- // Split v64i8 without BWI so that we can still use the PSHUFB lowering.
- if (VT == MVT::v64i8 && !Subtarget.hasBWI())
+ // Split 512-bit ops without BWI so that we can still use the PSHUFB lowering.
+ if (VT.is512BitVector() && !Subtarget.hasBWI())
return splitVectorIntUnary(Op, DAG);
// Decompose 256-bit ops into smaller 128-bit ops on pre-AVX2.
- if (VT == MVT::v32i8 && !Subtarget.hasInt256())
+ if (VT.is256BitVector() && !Subtarget.hasInt256())
return splitVectorIntUnary(Op, DAG);
+ // Lower vXi16/vXi32/vXi64 as BSWAP + vXi8 BITREVERSE.
+ if (VT.getScalarType() != MVT::i8) {
+ MVT ByteVT = MVT::getVectorVT(MVT::i8, VT.getSizeInBits() / 8);
+ SDValue Res = DAG.getNode(ISD::BSWAP, DL, VT, In);
+ Res = DAG.getBitcast(ByteVT, Res);
+ Res = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Res);
+ return DAG.getBitcast(VT, Res);
+ }
+ assert(VT.isVector() && VT.getScalarType() == MVT::i8 &&
+ "Only byte vector BITREVERSE supported");
+
unsigned NumElts = VT.getVectorNumElements();
// If we have GFNI, we can use GF2P8AFFINEQB to reverse the bits.
More information about the llvm-commits
mailing list