aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/GlobalOpt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-09 17:33:02 +0000
committerChris Lattner <sabre@nondot.org>2007-11-09 17:33:02 +0000
commit7b52fe7272ec337a77b7cc96b14e27d15fec3c89 (patch)
tree9a7dca11ee1b0ed9e39b6f2fe90b4a3f1521b380 /lib/Transforms/IPO/GlobalOpt.cpp
parent27b12384e673679845cdd91af759296b681516ca (diff)
Tighten up a check for folding away loads from (newly constant) globals. This
fixes a crash on Transforms/GlobalOpt/2007-11-09-GEP-GEP-Crash.ll and rdar://5585488. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43949 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/GlobalOpt.cpp')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 779b4a1871..76f04efda6 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -342,12 +342,17 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
Changed = true;
}
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
- Constant *SubInit = 0;
- ConstantExpr *CE =
- dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP));
- if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr)
- SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
- Changed |= CleanupConstantGlobalUsers(GEP, SubInit);
+ // Do not transform "gepinst (gep constexpr (GV))" here, because forming
+ // "gepconstexpr (gep constexpr (GV))" will cause the two gep's to fold
+ // and will invalidate our notion of what Init is.
+ if (!isa<ConstantExpr>(GEP->getOperand(0))) {
+ ConstantExpr *CE =
+ dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP));
+ if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr)
+ if (Constant *SubInit =
+ ConstantFoldLoadThroughGEPConstantExpr(Init, CE))
+ Changed |= CleanupConstantGlobalUsers(GEP, SubInit);
+ }
if (GEP->use_empty()) {
GEP->eraseFromParent();