[SDAG] Clarify behavior of scalable demanded/undef elts in isSplatValue [nfc]
authorPhilip Reames <preames@rivosinc.com>
Tue, 11 Oct 2022 14:26:44 +0000 (07:26 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 11 Oct 2022 14:28:34 +0000 (07:28 -0700)
Update comment, and add an assertion to check property expected by sole (non-test) caller.  Remove tests which appear to have been copied from fixed vector tests, and whose demanded bits don't correspond to the way this interface is otherwise used.

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp

index f93794f..219d58a 100644 (file)
@@ -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.
index 9417100..428309b 100644 (file)
@@ -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) {