summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-09-03 23:34:49 +0000
committerDan Gohman <gohman@apple.com>2009-09-03 23:34:49 +0000
commite4ca02da1b6f41343cbf7595c0c63c73b66ab705 (patch)
tree749a8a5096f2331dbc88b19e86e17cc1d0660fbc /llvm/lib/Analysis/ConstantFolding.cpp
parent19e1eec248e6b713fd213754761c6afbe664dc22 (diff)
downloadbcm5719-llvm-e4ca02da1b6f41343cbf7595c0c63c73b66ab705.tar.gz
bcm5719-llvm-e4ca02da1b6f41343cbf7595c0c63c73b66ab705.zip
Revert 80959. It isn't sufficient to solve the full problem. And it
introduced regressions in the Ocaml bindings tests. llvm-svn: 80969
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 9bc00938816..109eaad4584 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -203,21 +203,15 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps,
if (Offset != 0)
return 0;
- // Create the GEP constant expr.
- Constant *C = ConstantExpr::getGetElementPtr(Ptr,
- &NewIdxs[0], NewIdxs.size());
- assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
- "Computed GetElementPtr has unexpected type!");
-
// If the base is the start of a GlobalVariable and all the array indices
// remain in their static bounds, the GEP is inbounds. We can check that
// all indices are in bounds by just checking the first index only
- // because we've just normalized all the indices. We can mutate the
- // Constant in place because we've proven that the indices are in bounds,
- // so they'll always be in bounds.
- if (isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue())
- if (GEPOperator *GEP = dyn_cast<GEPOperator>(C))
- GEP->setIsInBounds(true);
+ // because we've just normalized all the indices.
+ Constant *C = isa<GlobalVariable>(Ptr) && NewIdxs[0]->isNullValue() ?
+ ConstantExpr::getInBoundsGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()) :
+ ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size());
+ assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
+ "Computed GetElementPtr has unexpected type!");
// If we ended up indexing a member with a type that doesn't match
// the type of what the original indices indexed, add a cast.
OpenPOWER on IntegriCloud