aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-09-10 23:37:55 +0000
committerDan Gohman <gohman@apple.com>2009-09-10 23:37:55 +0000
commite6992f728a94654e43269580a10a667f18dadba9 (patch)
tree5e6c18363d9917d22eec2a3f54d9c9c24dd37aee /lib/Transforms
parent83e3c4f9d796a5da223a3ebd5d4ba985c7ecc39d (diff)
downloadexternal_llvm-e6992f728a94654e43269580a10a667f18dadba9.zip
external_llvm-e6992f728a94654e43269580a10a667f18dadba9.tar.gz
external_llvm-e6992f728a94654e43269580a10a667f18dadba9.tar.bz2
Factor out the code for checking that all indices in a getelementptr are
within the notional bounds of the static type of the getelementptr (which is not the same as "inbounds") from GlobalOpt into a utility routine, and use it in ConstantFold.cpp to check whether there are any mis-behaved indices. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81478 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index b995a3d..63bc03d 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2045,25 +2045,14 @@ static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) {
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);
+ ConstantInt *CI = dyn_cast<ConstantInt>(*next(CE->op_begin()));
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;
- }
+ // notional bounds of the corresponding static array types.
+ if (!CE->isGEPWithNoNotionalOverIndexing())
+ return false;
return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE,
Context);