From e56a94ef91009ddb8d8b68783ff1650bcad3b326 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 3 Sep 2009 22:17:40 +0000 Subject: Remove the API for creating ConstantExprs with the nsw, nuw, inbounds, and exact flags. Because ConstantExprs are uniqued, creating an expression with this flag causes all expressions with the same operands to have the same flag, which may not be safe. Add, sub, mul, and sdiv ConstantExprs are usually folded anyway, so the main interesting flag here is inbounds, and the constant folder already knows how to set the inbounds flag automatically in most cases, so there isn't an urgent need for the API support. This can be reconsidered in the future, but for now just removing these API bits eliminates a source of potential trouble with little downside. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80959 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/Analysis/ConstantFolding.cpp') diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 109eaad..9bc0093 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -203,15 +203,21 @@ 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(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. - Constant *C = isa(Ptr) && NewIdxs[0]->isNullValue() ? - ConstantExpr::getInBoundsGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()) : - ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size()); - assert(cast(C->getType())->getElementType() == Ty && - "Computed GetElementPtr has unexpected type!"); + // 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(Ptr) && NewIdxs[0]->isNullValue()) + if (GEPOperator *GEP = dyn_cast(C)) + GEP->setIsInBounds(true); // 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. -- cgit v1.1