[llvm-branch-commits] [llvm-branch] r71719 - in /llvm/branches/Apple/Dib: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
Bill Wendling
isanbard at gmail.com
Wed May 13 14:11:36 PDT 2009
Author: void
Date: Wed May 13 16:11:15 2009
New Revision: 71719
URL: http://llvm.org/viewvc/llvm-project?rev=71719&view=rev
Log:
--- Merging r71688 into '.':
U lib/Transforms/Utils/SimplifyCFG.cpp
--- Merging r71717 into '.':
G lib/Transforms/Utils/SimplifyCFG.cpp
--- Merging r71691 into '.':
A test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
Added:
llvm/branches/Apple/Dib/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
- copied unchanged from r71691, llvm/trunk/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
Modified:
llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp
Modified: llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp?rev=71719&r1=71718&r2=71719&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Utils/SimplifyCFG.cpp Wed May 13 16:11:15 2009
@@ -18,6 +18,7 @@
#include "llvm/IntrinsicInst.h"
#include "llvm/Type.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/GlobalVariable.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h"
#include "llvm/Analysis/ConstantFolding.h"
@@ -347,6 +348,20 @@
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
@@ -393,6 +408,15 @@
if (!isa<AllocaInst>(I->getOperand(0)) &&
!isa<Constant>(I->getOperand(0)))
return false;
+ // External weak globals may have address 0, so we can't load them.
+ 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
More information about the llvm-branch-commits
mailing list