From: Dale Johannesen Date: Wed, 13 May 2009 20:55:30 +0000 (+0000) Subject: Handle some additonal cases of external weak globals. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=556d0a0d15689531f2b203575a3fe55e00713777;p=oota-llvm.git Handle some additonal cases of external weak globals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71717 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 48345915736..79b92eaabe0 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/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(CE)) + return dyn_cast(CE); + if (CE->getOpcode()==Instruction::GetElementPtr || + CE->getOpcode()==Instruction::BitCast) { + if (isa(CE->getOperand(0))) + return dyn_cast(CE->getOperand(0)); + if (ConstantExpr *CE2 = dyn_cast(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(I->getOperand(0))) return false; // External weak globals may have address 0, so we can't load them. - if (GlobalVariable* GV= dyn_cast(I->getOperand(0))) { - if (GV->hasExternalWeakLinkage()) - return false; - } + GlobalVariable* GV = dyn_cast(I->getOperand(0)); + if (GV && GV->hasExternalWeakLinkage()) + return false; + // The global may be buried within a ConstantExpr. + if (ConstantExpr *CE = dyn_cast(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