}
/// isSplatValue - Return true if the vector V has the same value
-/// across all DemandedElts. For scalable vectors it does not make
-/// sense to specify which elements are demanded, therefore they are
-/// simply ignored. For undef elts this means either all lanes are
-/// undef, or no lanes are known undef.
+/// across all DemandedElts. For scalable vectors, we don't know the
+/// number of lanes at compile time. Instead, we use a 1 bit APInt
+/// to represent a conservative value for all lanes; that is, that
+/// one bit value is implicitly splatted across all lanes.
bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts,
APInt &UndefElts, unsigned Depth) const {
unsigned Opcode = V.getOpcode();
assert((!VT.isScalableVector() || DemandedElts.getBitWidth() == 1) &&
"scalable demanded bits are ignored");
- if (!VT.isScalableVector() && !DemandedElts)
+ if (!DemandedElts)
return false; // No demanded elts, better to assume we don't know anything.
if (Depth >= MaxRecursionDepth)
assert(VT.isVector() && "Vector type expected");
APInt UndefElts;
- APInt DemandedElts;
-
- // For now we don't support this with scalable vectors.
- if (!VT.isScalableVector())
- DemandedElts = APInt::getAllOnes(VT.getVectorNumElements());
+ // Since the number of lanes in a scalable vector is unknown at compile time,
+ // we track one bit which is implicitly broadcast to all lanes. This means
+ // that all lanes in a scalable vector are considered demanded.
+ APInt DemandedElts
+ = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
return isSplatValue(V, DemandedElts, UndefElts) &&
(AllowUndefs || !UndefElts);
}
switch (Opcode) {
default: {
APInt UndefElts;
- APInt DemandedElts;
-
- if (!VT.isScalableVector())
- DemandedElts = APInt::getAllOnes(VT.getVectorNumElements());
+ // Since the number of lanes in a scalable vector is unknown at compile time,
+ // we track one bit which is implicitly broadcast to all lanes. This means
+ // that all lanes in a scalable vector are considered demanded.
+ APInt DemandedElts
+ = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
if (isSplatValue(V, DemandedElts, UndefElts)) {
if (VT.isScalableVector()) {
EXPECT_TRUE(DAG->isSplatValue(Op, /*AllowUndefs=*/false));
APInt UndefElts;
- APInt DemandedElts;
+ APInt DemandedElts(1,1);
EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts));
}
EXPECT_TRUE(DAG->isSplatValue(Op, /*AllowUndefs=*/false));
APInt UndefElts;
- APInt DemandedElts;
+ APInt DemandedElts(1, 1);
EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts));
}