[llvm-commits] [llvm] r159110 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/branch-fold.ll
Nick Lewycky
nicholas at mxc.ca
Sun Jun 24 03:15:42 PDT 2012
Author: nicholas
Date: Sun Jun 24 05:15:42 2012
New Revision: 159110
URL: http://llvm.org/viewvc/llvm-project?rev=159110&view=rev
Log:
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!
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/branch-fold.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=159110&r1=159109&r2=159110&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Jun 24 05:15:42 2012
@@ -129,7 +129,7 @@
///
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 @@
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 @@
} 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;
Modified: llvm/trunk/test/Transforms/SimplifyCFG/branch-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/branch-fold.ll?rev=159110&r1=159109&r2=159110&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/branch-fold.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/branch-fold.ll Sun Jun 24 05:15:42 2012
@@ -50,3 +50,21 @@
%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
+}
More information about the llvm-commits
mailing list