[PATCH] D88758: [DomTree] findNearestCommonDominator: assert the nodes are in tree

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 17:15:39 PDT 2020


MaskRay updated this revision to Diff 296014.
MaskRay added a comment.

Delete an unneeded loop condition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88758/new/

https://reviews.llvm.org/D88758

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


Index: llvm/include/llvm/Support/GenericDomTree.h
===================================================================
--- llvm/include/llvm/Support/GenericDomTree.h
+++ llvm/include/llvm/Support/GenericDomTree.h
@@ -480,18 +480,18 @@
 
     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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88758.296014.patch
Type: text/x-patch
Size: 939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201004/3945f9d2/attachment.bin>


More information about the llvm-commits mailing list