diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index f93794f05de0ec..219d58af6b44c6 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2543,13 +2543,16 @@ bool SelectionDAG::MaskedValueIsAllOnes(SDValue V, const APInt &Mask, /// 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 or undefined, therefore -/// they are simply ignored. +/// 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. bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts, unsigned Depth) const { unsigned Opcode = V.getOpcode(); EVT VT = V.getValueType(); assert(VT.isVector() && "Vector type expected"); + assert((!VT.isScalableVector() || DemandedElts.getBitWidth() == 1) && + "scalable demanded bits are ignored"); if (!VT.isScalableVector() && !DemandedElts) return false; // No demanded elts, better to assume we don't know anything. diff --git a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp index 94171001691fc8..428309b262a7ee 100644 --- a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp +++ b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp @@ -327,10 +327,6 @@ TEST_F(AArch64SelectionDAGTest, isSplatValue_Scalable_SPLAT_VECTOR) { APInt UndefElts; APInt DemandedElts; EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts)); - - // Width=16, Mask=3. These bits should be ignored. - DemandedElts = APInt(16, 3); - EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts)); } TEST_F(AArch64SelectionDAGTest, isSplatValue_Scalable_ADD_of_SPLAT_VECTOR) { @@ -351,10 +347,6 @@ TEST_F(AArch64SelectionDAGTest, isSplatValue_Scalable_ADD_of_SPLAT_VECTOR) { APInt UndefElts; APInt DemandedElts; EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts)); - - // Width=16, Mask=3. These bits should be ignored. - DemandedElts = APInt(16, 3); - EXPECT_TRUE(DAG->isSplatValue(Op, DemandedElts, UndefElts)); } TEST_F(AArch64SelectionDAGTest, getSplatSourceVector_Fixed_BUILD_VECTOR) {