[PATCH] D110751: [DomTree] Assert that blocks in queries aren't from another function
Daniil Suchkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 29 11:58:51 PDT 2021
DaniilSuchkov created this revision.
DaniilSuchkov added reviewers: asbirlea, MaskRay.
Herald added a subscriber: dexonsmith.
DaniilSuchkov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This assertion should help us catch cases when DT is used in a way that doesn't make much sense and usually indicates usage errors. In the attached testcase you can see the result of incorrect usage of DT. When processing `foo` SimpleLoopUnswitch decided to make `dominates(BB1, BB2)` query with BB2 being a block from another function (`bar`). In that case the result of the query was `true` since B isn't reachable from `foo`'s entry, so SimpleLoopUnswitch went ahead and replaced the use of `true` in `bar` because the preheader of one of the loops from `foo` "dominates" the entry block from `bar`.
I decided to add this assertion to `getNode` since all queries seem to be routed through that function for all non-trivial cases.
https://reviews.llvm.org/D110751
Files:
llvm/include/llvm/Support/GenericDomTree.h
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-invariant-select-bug.ll
Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-invariant-select-bug.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-invariant-select-bug.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-invariant-select-bug.ll
@@ -1,4 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; REQUIRES: asserts
+; XFAIL: *
; RUN: opt -passes='simple-loop-unswitch<nontrivial>' -S < %s | FileCheck %s
; FIXME: We should not replace `true` with `false` here!
Index: llvm/include/llvm/Support/GenericDomTree.h
===================================================================
--- llvm/include/llvm/Support/GenericDomTree.h
+++ llvm/include/llvm/Support/GenericDomTree.h
@@ -349,6 +349,9 @@
/// may (but is not required to) be null for a forward (backwards)
/// statically unreachable block.
DomTreeNodeBase<NodeT> *getNode(const NodeT *BB) const {
+ assert((!BB || !BB->getParent() || BB->getParent() == Parent) &&
+ "A node from another function!");
+
auto I = DomTreeNodes.find(BB);
if (I != DomTreeNodes.end())
return I->second.get();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110751.375971.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210929/42f4bb34/attachment.bin>
More information about the llvm-commits
mailing list