[llvm] 2cbc92f - [SLP] Strengthen internal invariant assertions slightly

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 14:56:48 PST 2022


Author: Philip Reames
Date: 2022-02-03T14:56:39-08:00
New Revision: 2cbc92fb11823c1f4bf2715607f1323a8acd8d42

URL: https://github.com/llvm/llvm-project/commit/2cbc92fb11823c1f4bf2715607f1323a8acd8d42
DIFF: https://github.com/llvm/llvm-project/commit/2cbc92fb11823c1f4bf2715607f1323a8acd8d42.diff

LOG: [SLP] Strengthen internal invariant assertions slightly

This builds on the invariant checks introduced in 1519629, and adds a couple more than seem to hold without additional work.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index b43fae90ea50..0d74f643f2e3 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2467,10 +2467,13 @@ class BoUpSLP {
     void verify() {
       if (hasValidDependencies()) {
         assert(UnscheduledDeps <= Dependencies && "invariant");
+        assert(UnscheduledDeps <= FirstInBundle->UnscheduledDepsInBundle &&
+               "bundle must have at least as many dependencies as member");
       }
 
       if (IsScheduled) {
-        assert(isSchedulingEntity() && UnscheduledDeps == 0 &&
+        assert(isSchedulingEntity() && hasValidDependencies() &&
+               UnscheduledDeps == 0 &&
                "unexpected scheduled state");
       }
     }
@@ -2729,8 +2732,17 @@ class BoUpSLP {
       if (!ScheduleStart)
         return;
 
-      for (auto *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode())
+      assert(ScheduleStart->getParent() == ScheduleEnd->getParent() &&
+             ScheduleStart->comesBefore(ScheduleEnd) &&
+             "Not a valid scheduling region?");
+
+      for (auto *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode()) {
+        auto *SD = getScheduleData(I);
+        assert(SD && "primary scheduledata must exist in window");
+        assert(isInSchedulingRegion(SD) &&
+               "primary schedule data not in window?");
         doForAllOpcodes(I, [](ScheduleData *SD) { SD->verify(); });
+      }
     }
 
     void doForAllOpcodes(Value *V,
@@ -3883,6 +3895,10 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
   BlockScheduling &BS = *BSRef.get();
 
   Optional<ScheduleData *> Bundle = BS.tryScheduleBundle(VL, this, S);
+#ifdef EXPENSIVE_CHECKS
+  // Make sure we didn't break any internal invariants
+  BS.verify();
+#endif
   if (!Bundle) {
     LLVM_DEBUG(dbgs() << "SLP: We are not able to schedule this bundle!\n");
     assert((!BS.getScheduleData(VL0) ||


        


More information about the llvm-commits mailing list