Skip to content

Commit 096b25a

Browse files
committed
[CodeGen] Use SPLAT_VECTOR for zeroinitialiser with scalable types
Summary: When generating code for the LLVM IR zeroinitialiser operation, if the vector type is scalable we should be using SPLAT_VECTOR instead of BUILD_VECTOR. Differential Revision: https://reviews.llvm.org/D78636
1 parent 8c8aae8 commit 096b25a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,6 +4240,8 @@ static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT,
42404240
SelectionDAG &DAG) {
42414241
int NumOps = Ops.size();
42424242
assert(NumOps != 0 && "Can't build an empty vector!");
4243+
assert(!VT.isScalableVector() &&
4244+
"BUILD_VECTOR cannot be used with scalable types");
42434245
assert(VT.getVectorNumElements() == (unsigned)NumOps &&
42444246
"Incorrect element count in BUILD_VECTOR!");
42454247

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,16 +1552,17 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
15521552
return DAG.getBlockAddress(BA, VT);
15531553

15541554
VectorType *VecTy = cast<VectorType>(V->getType());
1555-
unsigned NumElements = VecTy->getNumElements();
15561555

15571556
// Now that we know the number and type of the elements, get that number of
15581557
// elements into the Ops array based on what kind of constant it is.
1559-
SmallVector<SDValue, 16> Ops;
15601558
if (const ConstantVector *CV = dyn_cast<ConstantVector>(C)) {
1559+
SmallVector<SDValue, 16> Ops;
1560+
unsigned NumElements = cast<FixedVectorType>(VecTy)->getNumElements();
15611561
for (unsigned i = 0; i != NumElements; ++i)
15621562
Ops.push_back(getValue(CV->getOperand(i)));
1563-
} else {
1564-
assert(isa<ConstantAggregateZero>(C) && "Unknown vector constant!");
1563+
1564+
return NodeMap[V] = DAG.getBuildVector(VT, getCurSDLoc(), Ops);
1565+
} else if (isa<ConstantAggregateZero>(C)) {
15651566
EVT EltVT =
15661567
TLI.getValueType(DAG.getDataLayout(), VecTy->getElementType());
15671568

@@ -1570,11 +1571,16 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
15701571
Op = DAG.getConstantFP(0, getCurSDLoc(), EltVT);
15711572
else
15721573
Op = DAG.getConstant(0, getCurSDLoc(), EltVT);
1573-
Ops.assign(NumElements, Op);
1574-
}
15751574

1576-
// Create a BUILD_VECTOR node.
1577-
return NodeMap[V] = DAG.getBuildVector(VT, getCurSDLoc(), Ops);
1575+
if (isa<ScalableVectorType>(VecTy))
1576+
return NodeMap[V] = DAG.getSplatVector(VT, getCurSDLoc(), Op);
1577+
else {
1578+
SmallVector<SDValue, 16> Ops;
1579+
Ops.assign(cast<FixedVectorType>(VecTy)->getNumElements(), Op);
1580+
return NodeMap[V] = DAG.getBuildVector(VT, getCurSDLoc(), Ops);
1581+
}
1582+
}
1583+
llvm_unreachable("Unknown vector constant");
15781584
}
15791585

15801586
// If this is a static alloca, generate it as the frameindex instead of

0 commit comments

Comments
 (0)