[llvm] 1519629 - [SLP] Add basic self consistency asserts into scheduling

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 13:27:41 PST 2022


Author: Philip Reames
Date: 2022-02-03T13:27:35-08:00
New Revision: 1519629a20b84f563715f48892d9c0ff8f2845ba

URL: https://github.com/llvm/llvm-project/commit/1519629a20b84f563715f48892d9c0ff8f2845ba
DIFF: https://github.com/llvm/llvm-project/commit/1519629a20b84f563715f48892d9c0ff8f2845ba.diff

LOG: [SLP] Add basic self consistency asserts into scheduling

The idea here is to have a verify routine we can call during scheduling to ensure broken invariants are reported.  The intent is to help in debugging scheduling bugs.

At the moment, only the most basic properties are checked as adding several I thought held reported failures.

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 cd6131f22efa8..b43fae90ea501 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2463,6 +2463,18 @@ class BoUpSLP {
       Lane = -1;
     }
 
+    /// Verify basic self consistency properties
+    void verify() {
+      if (hasValidDependencies()) {
+        assert(UnscheduledDeps <= Dependencies && "invariant");
+      }
+
+      if (IsScheduled) {
+        assert(isSchedulingEntity() && UnscheduledDeps == 0 &&
+               "unexpected scheduled state");
+      }
+    }
+
     /// Returns true if the dependency information has been calculated.
     bool hasValidDependencies() const { return Dependencies != InvalidDeps; }
 
@@ -2712,6 +2724,15 @@ class BoUpSLP {
       }
     }
 
+    /// Verify basic self consistency properties of the data structure.
+    void verify() {
+      if (!ScheduleStart)
+        return;
+
+      for (auto *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode())
+        doForAllOpcodes(I, [](ScheduleData *SD) { SD->verify(); });
+    }
+
     void doForAllOpcodes(Value *V,
                          function_ref<void(ScheduleData *SD)> Action) {
       if (ScheduleData *SD = getScheduleData(V))
@@ -7904,6 +7925,11 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) {
   }
   assert(NumToSchedule == 0 && "could not schedule all instructions");
 
+  // Check that we didn't break any of our invariants.
+#ifdef EXPENSIVE_CHECKS
+  BS->verify();
+#endif
+
   // Avoid duplicate scheduling of the block.
   BS->ScheduleStart = nullptr;
 }


        


More information about the llvm-commits mailing list