[llvm-commits] [llvm] r81165 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Dan Gohman
gohman at apple.com
Mon Sep 7 15:44:55 PDT 2009
Author: djg
Date: Mon Sep 7 17:44:55 2009
New Revision: 81165
URL: http://llvm.org/viewvc/llvm-project?rev=81165&view=rev
Log:
Don't commit stores with addresses that have indices that are not
compile-time constant integers or that are out of bounds for their
corresponding static array types. These can cause aliasing that
GlobalOpt assumes won't happen.
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=81165&r1=81164&r2=81165&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Sep 7 17:44:55 2009
@@ -2044,6 +2044,27 @@
// external globals.
if (!GV->hasDefinitiveInitializer())
return false;
+
+ gep_type_iterator GEPI = gep_type_begin(CE), E = gep_type_end(CE);
+ User::op_iterator OI = next(CE->op_begin());
+
+ // The first index must be zero.
+ ConstantInt *CI = dyn_cast<ConstantInt>(*OI);
+ if (!CI || !CI->isZero()) return false;
+ ++GEPI;
+ ++OI;
+
+ // The remaining indices must be compile-time known integers within the
+ // bounds of the corresponding static array types.
+ for (; GEPI != E; ++GEPI, ++OI) {
+ CI = dyn_cast<ConstantInt>(*OI);
+ if (!CI) return false;
+ if (const ArrayType *ATy = dyn_cast<ArrayType>(*GEPI))
+ if (CI->getValue().getActiveBits() > 64 ||
+ CI->getZExtValue() >= ATy->getNumElements())
+ return false;
+ }
+
return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE,
Context);
}
More information about the llvm-commits
mailing list