llvm.org GIT mirror llvm / 2bbf52d
Revert r316582 [Local] Fix a bug in the domtree update logic for MergeBasicBlockIntoOnlyPred. Summary: This reverts commit r316582. It looks like this commit broke tests on one buildbot: http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/5719 . . . Failing Tests (1): LLVM :: Transforms/CalledValuePropagation/simple-arguments.ll Reviewers: Subscribers: git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316612 91177308-0d34-0410-b5e6-96231b3b80d8 Balaram Makam 1 year, 9 months ago
2 changed file(s) with 3 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
648648 DestBB->moveAfter(PredBB);
649649
650650 if (DT) {
651 // For some irreducible CFG we end up having forward-unreachable blocks
652 // so check if getNode returns a valid node before updating the domtree.
653 if (DomTreeNode *DTN = DT->getNode(PredBB)) {
654 BasicBlock *PredBBIDom = DTN->getIDom()->getBlock();
655 DT->changeImmediateDominator(DestBB, PredBBIDom);
656 DT->eraseNode(PredBB);
657 }
651 BasicBlock *PredBBIDom = DT->getNode(PredBB)->getIDom()->getBlock();
652 DT->changeImmediateDominator(DestBB, PredBBIDom);
653 DT->eraseNode(PredBB);
658654 }
659655 // Nuke BB.
660656 PredBB->eraseFromParent();
165165 Declares++;
166166 EXPECT_EQ(2, Declares);
167167 }
168
169 /// Build the dominator tree for the function and run the Test.
170 static void runWithDomTree(
171 Module &M, StringRef FuncName,
172 function_ref Test) {
173 auto *F = M.getFunction(FuncName);
174 ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
175 // Compute the dominator tree for the function.
176 DominatorTree DT(*F);
177 Test(*F, &DT);
178 }
179
180 TEST(Local, MergeBasicBlockIntoOnlyPred) {
181 LLVMContext C;
182
183 std::unique_ptr M = parseIR(
184 C,
185 "define i32 @f(i8* %str) {\n"
186 "entry:\n"
187 " br label %bb2.i\n"
188 "bb2.i: ; preds = %bb4.i, %entry\n"
189 " br i1 false, label %bb4.i, label %base2flt.exit204\n"
190 "bb4.i: ; preds = %bb2.i\n"
191 " br i1 false, label %base2flt.exit204, label %bb2.i\n"
192 "bb10.i196.bb7.i197_crit_edge: ; No predecessors!\n"
193 " br label %bb7.i197\n"
194 "bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge\n"
195 " %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]\n"
196 " br i1 undef, label %base2flt.exit204, label %base2flt.exit204\n"
197 "base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i\n"
198 " ret i32 0\n"
199 "}\n");
200 runWithDomTree(
201 *M, "f", [&](Function &F, DominatorTree *DT) {
202 for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
203 BasicBlock *BB = &*I++;
204 BasicBlock *SinglePred = BB->getSinglePredecessor();
205 if (!SinglePred || SinglePred == BB || BB->hasAddressTaken()) continue;
206 BranchInst *Term = dyn_cast(SinglePred->getTerminator());
207 if (Term && !Term->isConditional())
208 MergeBasicBlockIntoOnlyPred(BB, DT);
209 }
210 EXPECT_TRUE(DT->verify());
211 });
212 }