summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-18 14:58:19 +0000
committerDan Gohman <gohman@apple.com>2009-08-18 14:58:19 +0000
commit82ac81b1cc0ca3113b4c49caa4881493423f950c (patch)
tree82f803ec2dacf6f9653668f6e20ef62a25bf5d63 /llvm/lib/Transforms
parente4d2e8465ae8326dfb46dcff332e6203b5c5a17e (diff)
downloadbcm5719-llvm-82ac81b1cc0ca3113b4c49caa4881493423f950c.tar.gz
bcm5719-llvm-82ac81b1cc0ca3113b4c49caa4881493423f950c.zip
Fix a bug that caused globalopt to miscompile tramp3d: don't miss
unruly indices for arrays that are members of structs. llvm-svn: 79337
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 46ff307c755..6ec20126d74 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -426,13 +426,18 @@ static bool IsUserOfGlobalSafeForSRA(User *U, GlobalValue *GV) {
// Scalar replacing *just* the outer index of the array is probably not
// going to be a win anyway, so just give up.
for (++GEPI; // Skip array index.
- GEPI != E && (isa<ArrayType>(*GEPI) || isa<VectorType>(*GEPI));
+ GEPI != E;
++GEPI) {
uint64_t NumElements;
if (const ArrayType *SubArrayTy = dyn_cast<ArrayType>(*GEPI))
NumElements = SubArrayTy->getNumElements();
- else
- NumElements = cast<VectorType>(*GEPI)->getNumElements();
+ else if (const VectorType *SubVectorTy = dyn_cast<VectorType>(*GEPI))
+ NumElements = SubVectorTy->getNumElements();
+ else {
+ assert(isa<StructType>(*GEPI) &&
+ "Indexed GEP type is not array, vector, or struct!");
+ continue;
+ }
ConstantInt *IdxVal = dyn_cast<ConstantInt>(GEPI.getOperand());
if (!IdxVal || IdxVal->getZExtValue() >= NumElements)
OpenPOWER on IntegriCloud