summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2009-05-13 20:55:30 +0000
committerDale Johannesen <dalej@apple.com>2009-05-13 20:55:30 +0000
commit3181652363be742dbebd38e8bd7ea2ff9b0af942 (patch)
treeef28f9876faf915c6a3920421d531b048e6cf770 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent2b776773228108629ce90c6edd607082ce2574f9 (diff)
downloadbcm5719-llvm-3181652363be742dbebd38e8bd7ea2ff9b0af942.tar.gz
bcm5719-llvm-3181652363be742dbebd38e8bd7ea2ff9b0af942.zip
Handle some additonal cases of external weak globals.
llvm-svn: 71717
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 48345915736..79b92eaabe0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -348,6 +348,20 @@ static Value *GetIfCondition(BasicBlock *BB,
return 0;
}
+/// findGlobalVariableBase - Recurse into a ConstantExpr to find the underlying
+/// GlobalVariable, if there is one.
+static GlobalVariable* findGlobalVariableBase(ConstantExpr* CE) {
+ if (isa<GlobalVariable>(CE))
+ return dyn_cast<GlobalVariable>(CE);
+ if (CE->getOpcode()==Instruction::GetElementPtr ||
+ CE->getOpcode()==Instruction::BitCast) {
+ if (isa<GlobalVariable>(CE->getOperand(0)))
+ return dyn_cast<GlobalVariable>(CE->getOperand(0));
+ if (ConstantExpr *CE2 = dyn_cast<ConstantExpr>(CE->getOperand(0)))
+ return findGlobalVariableBase(CE2);
+ }
+ return NULL;
+}
/// DominatesMergePoint - If we have a merge point of an "if condition" as
/// accepted above, return true if the specified value dominates the block. We
@@ -395,10 +409,14 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
!isa<Constant>(I->getOperand(0)))
return false;
// External weak globals may have address 0, so we can't load them.
- if (GlobalVariable* GV= dyn_cast<GlobalVariable>(I->getOperand(0))) {
- if (GV->hasExternalWeakLinkage())
- return false;
- }
+ GlobalVariable* GV = dyn_cast<GlobalVariable>(I->getOperand(0));
+ if (GV && GV->hasExternalWeakLinkage())
+ return false;
+ // The global may be buried within a ConstantExpr.
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I->getOperand(0)))
+ GV = findGlobalVariableBase(CE);
+ if (GV && GV->hasExternalWeakLinkage())
+ return false;
// Finally, we have to check to make sure there are no instructions
// before the load in its basic block, as we are going to hoist the loop
OpenPOWER on IntegriCloud