summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-09-19 14:24:21 +0000
committerHans Wennborg <hans@hanshq.net>2012-09-19 14:24:21 +0000
commitf744fa917ddc3d045c96de623880a57bca31214f (patch)
tree2b881093360eae35feff2abb96e0301c5c62ebfa /llvm/lib/Transforms
parentbc0b3f43d10411208c02dd5ecf1b4f56ab17b171 (diff)
downloadbcm5719-llvm-f744fa917ddc3d045c96de623880a57bca31214f.tar.gz
bcm5719-llvm-f744fa917ddc3d045c96de623880a57bca31214f.zip
SimplifyCFG: Don't generate invalid code for switch used to initialize
two variables where the first variable is returned and the second ignored. I don't think this occurs in practice (other passes should have cleaned up the unused phi node), but it should still be handled correctly. Also make the logic for determining if we should return early less sketchy. llvm-svn: 164225
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 3365c2feed6..7c6a1523293 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3258,17 +3258,16 @@ static bool SwitchToLookupTable(SwitchInst *SI,
"switch.gep");
Value *Result = Builder.CreateLoad(GEP, "switch.load");
- // If the result is only going to be used to return from the function,
- // we want to do that right here.
- if (PHI->hasOneUse() && isa<ReturnInst>(*PHI->use_begin())) {
- if (CommonDest->getFirstNonPHIOrDbg() == CommonDest->getTerminator()) {
- Builder.CreateRet(Result);
- ReturnedEarly = true;
- }
+ // If the result is used to return immediately from the function, we want to
+ // do that right here.
+ if (PHI->hasOneUse() && isa<ReturnInst>(*PHI->use_begin()) &&
+ *PHI->use_begin() == CommonDest->getFirstNonPHIOrDbg()) {
+ Builder.CreateRet(Result);
+ ReturnedEarly = true;
+ break;
}
- if (!ReturnedEarly)
- PHI->addIncoming(Result, LookupBB);
+ PHI->addIncoming(Result, LookupBB);
}
if (!ReturnedEarly)
OpenPOWER on IntegriCloud