aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-06-24 10:15:42 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-06-24 10:15:42 +0000
commitedb5842b7cf53ba4a4b5d3e1bad49a9fad47c02b (patch)
tree0e82ce0a7cb7d17aa5e3ec1ee617df89b4e87fdf
parente7f702fc2d496aff1e5c1153519931e203b1ca76 (diff)
downloadexternal_llvm-edb5842b7cf53ba4a4b5d3e1bad49a9fad47c02b.zip
external_llvm-edb5842b7cf53ba4a4b5d3e1bad49a9fad47c02b.tar.gz
external_llvm-edb5842b7cf53ba4a4b5d3e1bad49a9fad47c02b.tar.bz2
Remove dyn_cast + dereference pattern by replacing it with a cast and changing
the safety check to look for the same type we're going to actually cast to. Fixes PR13180! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159110 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp6
-rw-r--r--test/Transforms/SimplifyCFG/branch-fold.ll18
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 3d4d50a..58a8b35 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -129,7 +129,7 @@ static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
///
static bool isProfitableToFoldUnconditional(BranchInst *SI1,
BranchInst *SI2,
- Instruction* Cond,
+ Instruction *Cond,
SmallVectorImpl<PHINode*> &PhiNodes) {
if (SI1 == SI2) return false; // Can't merge with self!
assert(SI1->isUnconditional() && SI2->isConditional());
@@ -156,7 +156,7 @@ static bool isProfitableToFoldUnconditional(BranchInst *SI1,
isa<PHINode>(BBI); ++BBI) {
PHINode *PN = cast<PHINode>(BBI);
if (PN->getIncomingValueForBlock(SI1BB) != Cond ||
- !isa<Constant>(PN->getIncomingValueForBlock(SI2BB)))
+ !isa<ConstantInt>(PN->getIncomingValueForBlock(SI2BB)))
return false;
PhiNodes.push_back(PN);
}
@@ -1782,7 +1782,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
} else {
// Update PHI nodes in the common successors.
for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
- ConstantInt *PBI_C = dyn_cast<ConstantInt>(
+ ConstantInt *PBI_C = cast<ConstantInt>(
PHIs[i]->getIncomingValueForBlock(PBI->getParent()));
assert(PBI_C->getType()->isIntegerTy(1));
Instruction *MergedCond = 0;
diff --git a/test/Transforms/SimplifyCFG/branch-fold.ll b/test/Transforms/SimplifyCFG/branch-fold.ll
index 70c5fb5..7097dea 100644
--- a/test/Transforms/SimplifyCFG/branch-fold.ll
+++ b/test/Transforms/SimplifyCFG/branch-fold.ll
@@ -50,3 +50,21 @@ c:
%o2 = phi i1 [ false, %a ], [ %phitmp, %b ], [ false, %entry ]
ret i1 %o2
}
+
+; PR13180
+define void @pr13180(i8 %p) {
+entry:
+ %tobool = icmp eq i8 %p, 0
+ br i1 %tobool, label %cond.false, label %cond.true
+
+cond.true: ; preds = %entry
+ br label %cond.end
+
+cond.false: ; preds = %entry
+ %phitmp = icmp eq i8 %p, 0
+ br label %cond.end
+
+cond.end: ; preds = %cond.false, %cond.true
+ %cond = phi i1 [ undef, %cond.true ], [ %phitmp, %cond.false ]
+ unreachable
+}