Skip to content

Commit

Permalink
Modify transformations to not break parallel regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Doerfert committed Jul 19, 2016
1 parent fad09ed commit 8542598
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Transforms/Scalar/JumpThreading.cpp
Expand Up @@ -713,8 +713,9 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
// predecessors of our predecessor block.
if (BasicBlock *SinglePred = BB->getSinglePredecessor()) {
const TerminatorInst *TI = SinglePred->getTerminator();
if (!TI->isExceptional() && TI->getNumSuccessors() == 1 &&
SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
if (!TI->isExceptional() && !TI->isParallelismRelated() &&
TI->getNumSuccessors() == 1 && SinglePred != BB &&
!hasAddressTakenAndUsed(BB)) {
// If SinglePred was a loop header, BB becomes one.
if (LoopHeaders.erase(SinglePred))
LoopHeaders.insert(BB);
Expand Down Expand Up @@ -1955,6 +1956,6 @@ bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB) {
return true;
}
}

return false;
}
9 changes: 9 additions & 0 deletions lib/Transforms/Scalar/SCCP.cpp
Expand Up @@ -581,6 +581,12 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
return;
}

if (TI.isParallelismRelated()) {
// Mark all destinations executable!
Succs.assign(TI.getNumSuccessors(), true);
return;
}

#ifndef NDEBUG
dbgs() << "Unknown terminator instruction: " << TI << '\n';
#endif
Expand Down Expand Up @@ -637,6 +643,9 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
if (isa<IndirectBrInst>(TI))
return true;

if (TI->isParallelismRelated())
return true;

#ifndef NDEBUG
dbgs() << "Unknown terminator instruction: " << *TI << '\n';
#endif
Expand Down
3 changes: 3 additions & 0 deletions lib/Transforms/Utils/BasicBlockUtils.cpp
Expand Up @@ -107,6 +107,9 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT,
// Don't break unwinding instructions.
if (PredBB->getTerminator()->isExceptional())
return false;
// Don't break parallel tasks.
if (PredBB->getTerminator()->isParallelismRelated())
return false;

succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
BasicBlock *OnlySucc = BB;
Expand Down

0 comments on commit 8542598

Please sign in to comment.