diff options
author | Balaram Makam <bmakam@codeaurora.org> | 2017-10-26 15:04:53 +0000 |
---|---|---|
committer | Balaram Makam <bmakam@codeaurora.org> | 2017-10-26 15:04:53 +0000 |
commit | e7df36ebba1063cee0ea8ec06d742bd0f8af7384 (patch) | |
tree | 4481310215bc38f5a5ca0ca6e72264e98bcdd4b6 /unittests/Transforms | |
parent | 509132b368efed10bbdad825403f45e9cf1d6e38 (diff) |
Reapply r316582 [Local] Fix a bug in the domtree update logic for MergeBasicBlockIntoOnlyPred.
Summary: This reverts r316612 to reapply r316582. The buildbot failure was unrelated to this commit.
Reviewers:
Subscribers:
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316669 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms')
-rw-r--r-- | unittests/Transforms/Utils/Local.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/Local.cpp b/unittests/Transforms/Utils/Local.cpp index 1f58dc802fa..ee864e68fc0 100644 --- a/unittests/Transforms/Utils/Local.cpp +++ b/unittests/Transforms/Utils/Local.cpp @@ -166,3 +166,48 @@ TEST(Local, ReplaceDbgDeclare) { Declares++; EXPECT_EQ(2, Declares); } + +/// Build the dominator tree for the function and run the Test. +static void runWithDomTree( + Module &M, StringRef FuncName, + function_ref<void(Function &F, DominatorTree *DT)> Test) { + auto *F = M.getFunction(FuncName); + ASSERT_NE(F, nullptr) << "Could not find " << FuncName; + // Compute the dominator tree for the function. + DominatorTree DT(*F); + Test(*F, &DT); +} + +TEST(Local, MergeBasicBlockIntoOnlyPred) { + LLVMContext C; + + std::unique_ptr<Module> M = parseIR( + C, + "define i32 @f(i8* %str) {\n" + "entry:\n" + " br label %bb2.i\n" + "bb2.i: ; preds = %bb4.i, %entry\n" + " br i1 false, label %bb4.i, label %base2flt.exit204\n" + "bb4.i: ; preds = %bb2.i\n" + " br i1 false, label %base2flt.exit204, label %bb2.i\n" + "bb10.i196.bb7.i197_crit_edge: ; No predecessors!\n" + " br label %bb7.i197\n" + "bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge\n" + " %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]\n" + " br i1 undef, label %base2flt.exit204, label %base2flt.exit204\n" + "base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i\n" + " ret i32 0\n" + "}\n"); + runWithDomTree( + *M, "f", [&](Function &F, DominatorTree *DT) { + for (Function::iterator I = F.begin(), E = F.end(); I != E;) { + BasicBlock *BB = &*I++; + BasicBlock *SinglePred = BB->getSinglePredecessor(); + if (!SinglePred || SinglePred == BB || BB->hasAddressTaken()) continue; + BranchInst *Term = dyn_cast<BranchInst>(SinglePred->getTerminator()); + if (Term && !Term->isConditional()) + MergeBasicBlockIntoOnlyPred(BB, DT); + } + EXPECT_TRUE(DT->verify()); + }); +} |