[RewriteStatepointsForGC] Strengthen assertions around liveness
authorPhilip Reames <listmail@philipreames.com>
Mon, 13 Apr 2015 17:35:55 +0000 (17:35 +0000)
committerPhilip Reames <listmail@philipreames.com>
Mon, 13 Apr 2015 17:35:55 +0000 (17:35 +0000)
This is related to the issues addressed in 234651.  These assertions check the properties ensured by that change at the place of use.  Note that a similiar property is checked in checkBasicSSA, but without the reachability constraint.  Technically, the liveness would be correct to include unreachable values, but this would be problematic for actual relocation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234766 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

index 1f2597c74261ef445e42c86bb0ca2e6eb5a3280f..b4752243b6a68e2c2f72e0a759d1ef755c41b94b 100644 (file)
@@ -1879,6 +1879,24 @@ static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P,
     Statepoint statepoint(info.StatepointToken);
     live.insert(live.end(), statepoint.gc_args_begin(),
                 statepoint.gc_args_end());
+#ifndef NDEBUG
+    // Do some basic sanity checks on our liveness results before performing
+    // relocation.  Relocation can and will turn mistakes in liveness results
+    // into non-sensical code which is must harder to debug.
+    // TODO: It would be nice to test consistency as well
+    assert(DT.isReachableFromEntry(info.StatepointToken->getParent()) &&
+           "statepoint must be reachable or liveness is meaningless");
+    for (Value *V : statepoint.gc_args()) {
+      if (!isa<Instruction>(V))
+        // Non-instruction values trivial dominate all possible uses
+        continue;
+      auto LiveInst = cast<Instruction>(V);
+      assert(DT.isReachableFromEntry(LiveInst->getParent()) &&
+             "unreachable values should never be live");
+      assert(DT.dominates(LiveInst, info.StatepointToken) &&
+             "basic SSA liveness expectation violated by liveness analysis");
+    }
+#endif
   }
   unique_unsorted(live);