[llvm] 1065f34 - [DomTree] findNearestCommonDominator: assert the nodes are in tree

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 15:38:36 PDT 2020


Author: Fangrui Song
Date: 2020-10-04T15:35:14-07:00
New Revision: 1065f3439bad59323f16e7c8ee568c7d94dcd952

URL: https://github.com/llvm/llvm-project/commit/1065f3439bad59323f16e7c8ee568c7d94dcd952
DIFF: https://github.com/llvm/llvm-project/commit/1065f3439bad59323f16e7c8ee568c7d94dcd952.diff

LOG: [DomTree] findNearestCommonDominator: assert the nodes are in tree

i.e. they cannot be unreachable from the entry (which usually indicate usage errors).
This change allows the removal of some nullptr checks.

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D88758

Added: 
    

Modified: 
    llvm/include/llvm/Support/GenericDomTree.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index c77168432058..4bed550f44c0 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -463,8 +463,8 @@ class DominatorTreeBase {
     return this->Roots[0];
   }
 
-  /// findNearestCommonDominator - Find nearest common dominator basic block
-  /// for basic block A and B. If there is no such block then return nullptr.
+  /// Find nearest common dominator basic block for basic block A and B. A and B
+  /// must have tree nodes.
   NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) const {
     assert(A && B && "Pointers are not valid");
     assert(A->getParent() == B->getParent() &&
@@ -480,18 +480,18 @@ class DominatorTreeBase {
 
     DomTreeNodeBase<NodeT> *NodeA = getNode(A);
     DomTreeNodeBase<NodeT> *NodeB = getNode(B);
-
-    if (!NodeA || !NodeB) return nullptr;
+    assert(NodeA && "A must be in the tree");
+    assert(NodeB && "B must be in the tree");
 
     // Use level information to go up the tree until the levels match. Then
     // continue going up til we arrive at the same node.
-    while (NodeA && NodeA != NodeB) {
+    while (NodeA != NodeB) {
       if (NodeA->getLevel() < NodeB->getLevel()) std::swap(NodeA, NodeB);
 
       NodeA = NodeA->IDom;
     }
 
-    return NodeA ? NodeA->getBlock() : nullptr;
+    return NodeA->getBlock();
   }
 
   const NodeT *findNearestCommonDominator(const NodeT *A,


        


More information about the llvm-commits mailing list