summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-12-19 03:02:34 +0000
committerChris Lattner <sabre@nondot.org>2010-12-19 03:02:34 +0000
commit583ec6fa447fd3a478c38917d8e7a6f6fb7c7a90 (patch)
tree6a69161f59a880a9aaa3532f47232888047a8ee0 /llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
parent2b43f2df2b91142d55bef8971ff56db635c5b8ba (diff)
downloadbcm5719-llvm-583ec6fa447fd3a478c38917d8e7a6f6fb7c7a90.tar.gz
bcm5719-llvm-583ec6fa447fd3a478c38917d8e7a6f6fb7c7a90.zip
first step to fixing PR8642: don't fold away empty basic blocks
which have trapping constant exprs in them due to PHI nodes. Eliminating them can cause the constant expr to be evalutated on new paths if the input edges are critical. llvm-svn: 122164
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
index 60c7f7565eb..b4a2a12de03 100644
--- a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -211,6 +211,17 @@ bool CodeGenPrepare::CanMergeBlocks(const BasicBlock *BB,
const PHINode *DestBBPN = dyn_cast<PHINode>(DestBB->begin());
if (!DestBBPN) return true; // no conflict.
+ // Walk all the PHI nodes in DestBB. If any of the input values to the PHI
+ // are trapping constant exprs, then merging this block would introduce the
+ // possible trap into new control flow if we have any critical predecessor
+ // edges.
+ for (BasicBlock::const_iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
+ const PHINode *PN = cast<PHINode>(I);
+ if (const Constant *C =dyn_cast<Constant>(PN->getIncomingValueForBlock(BB)))
+ if (C->canTrap())
+ return false;
+ }
+
// Collect the preds of BB.
SmallPtrSet<const BasicBlock*, 16> BBPreds;
if (const PHINode *BBPN = dyn_cast<PHINode>(BB->begin())) {
OpenPOWER on IntegriCloud