Skip to content

Commit ada5458

Browse files
committed
[RISCV] Expand scalable vector bswap. Fix crash for bitreverse.
Fix LegalizeVectorOps to not try shuffle or unrolling expansions for scalable vectors. Differential Revision: https://reviews.llvm.org/D112236
1 parent 1a605f3 commit ada5458

File tree

4 files changed

+2339
-0
lines changed

4 files changed

+2339
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,10 @@ static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
10951095
SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) {
10961096
EVT VT = Node->getValueType(0);
10971097

1098+
// Scalable vectors can't use shuffle expansion.
1099+
if (VT.isScalableVector())
1100+
return TLI.expandBSWAP(Node, DAG);
1101+
10981102
// Generate a byte wise shuffle mask for the BSWAP.
10991103
SmallVector<int, 16> ShuffleMask;
11001104
createBSWAPShuffleMask(VT, ShuffleMask);
@@ -1124,6 +1128,12 @@ void VectorLegalizer::ExpandBITREVERSE(SDNode *Node,
11241128
SmallVectorImpl<SDValue> &Results) {
11251129
EVT VT = Node->getValueType(0);
11261130

1131+
// We can't unroll or use shuffles for scalable vectors.
1132+
if (VT.isScalableVector()) {
1133+
Results.push_back(TLI.expandBITREVERSE(Node, DAG));
1134+
return;
1135+
}
1136+
11271137
// If we have the scalar operation, it's probably cheaper to unroll it.
11281138
if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType())) {
11291139
SDValue Tmp = DAG.UnrollVectorOp(Node);

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
545545
setOperationAction(ISD::CTLZ, VT, Expand);
546546
setOperationAction(ISD::CTPOP, VT, Expand);
547547

548+
setOperationAction(ISD::BSWAP, VT, Expand);
549+
548550
// Custom-lower extensions and truncations from/to mask types.
549551
setOperationAction(ISD::ANY_EXTEND, VT, Custom);
550552
setOperationAction(ISD::SIGN_EXTEND, VT, Custom);

0 commit comments

Comments
 (0)