diff options
| author | Dan Gohman <gohman@apple.com> | 2009-09-07 22:44:55 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-09-07 22:44:55 +0000 |
| commit | 161429fe7e26303c634da6bcf66bba52beba8bbb (patch) | |
| tree | d9d7bbc07f26002fba3c9ec11c76a30bda3829f0 /llvm | |
| parent | 82e747580f3a42a964146666316275ac745cea53 (diff) | |
| download | bcm5719-llvm-161429fe7e26303c634da6bcf66bba52beba8bbb.tar.gz bcm5719-llvm-161429fe7e26303c634da6bcf66bba52beba8bbb.zip | |
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.
llvm-svn: 81165
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 86c5e291948..b995a3d2864 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2044,6 +2044,27 @@ static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) { // 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); } |

