diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 32993f73acb..4b20d03006f 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2278,9 +2278,8 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) { (Value**)(Elts.data() + 1), Elts.size() - 1)) return Error(ID.Loc, "invalid indices for getelementptr"); - ID.ConstantVal = InBounds ? - ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices) : - ConstantExpr::getGetElementPtr(Elts[0], Indices); + ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices, + InBounds); } else if (Opc == Instruction::Select) { if (Elts.size() != 3) return Error(ID.Loc, "expected three operands to select"); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 910987a472d..e8e8c2a7b6f 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1352,10 +1352,9 @@ bool BitcodeReader::ParseConstants() { Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy)); } ArrayRef Indices(Elts.begin() + 1, Elts.end()); - if (BitCode == bitc::CST_CODE_CE_INBOUNDS_GEP) - V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices); - else - V = ConstantExpr::getGetElementPtr(Elts[0], Indices); + V = ConstantExpr::getGetElementPtr(Elts[0], Indices, + BitCode == + bitc::CST_CODE_CE_INBOUNDS_GEP); break; } case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#] diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 2d971a1e192..fd263c901ba 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2407,9 +2407,9 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e; ++i) GEPOps.push_back(getVal(Values, *i)); - InstResult = cast(GEP)->isInBounds() ? - ConstantExpr::getInBoundsGetElementPtr(P, GEPOps) : - ConstantExpr::getGetElementPtr(P, GEPOps); + InstResult = + ConstantExpr::getGetElementPtr(P, GEPOps, + cast(GEP)->isInBounds()); } else if (LoadInst *LI = dyn_cast(CurInst)) { if (LI->isVolatile()) return false; // no volatile accesses. InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)), diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 2a2faf6590d..b8d15c845f3 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -2231,10 +2231,10 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, NewIndices.push_back(Combined); NewIndices.append(Idxs.begin() + 1, Idxs.end()); - return (inBounds && cast(CE)->isInBounds()) ? - ConstantExpr::getInBoundsGetElementPtr(CE->getOperand(0), - NewIndices) : - ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices); + return + ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices, + inBounds && + cast(CE)->isInBounds()); } } @@ -2250,11 +2250,9 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, if (ArrayType *CAT = dyn_cast(cast(C->getType())->getElementType())) if (CAT->getElementType() == SAT->getElementType()) - return inBounds ? - ConstantExpr::getInBoundsGetElementPtr( - (Constant*)CE->getOperand(0), Idxs) : - ConstantExpr::getGetElementPtr( - (Constant*)CE->getOperand(0), Idxs); + return + ConstantExpr::getGetElementPtr((Constant*)CE->getOperand(0), + Idxs, inBounds); } } @@ -2309,9 +2307,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, if (!NewIdxs.empty()) { for (unsigned i = 0, e = Idxs.size(); i != e; ++i) if (!NewIdxs[i]) NewIdxs[i] = cast(Idxs[i]); - return inBounds ? - ConstantExpr::getInBoundsGetElementPtr(C, NewIdxs) : - ConstantExpr::getGetElementPtr(C, NewIdxs); + return ConstantExpr::getGetElementPtr(C, NewIdxs, inBounds); } // If all indices are known integers and normalized, we can do a simple diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 5147a0d111a..5bc0f67a316 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -839,13 +839,13 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const { for (unsigned i = 1, e = getNumOperands(); i != e; ++i) Ops[i-1] = getOperand(i); if (OpNo == 0) - return cast(this)->isInBounds() ? - ConstantExpr::getInBoundsGetElementPtr(Op, Ops) : - ConstantExpr::getGetElementPtr(Op, Ops); + return + ConstantExpr::getGetElementPtr(Op, Ops, + cast(this)->isInBounds()); Ops[OpNo-1] = Op; - return cast(this)->isInBounds() ? - ConstantExpr::getInBoundsGetElementPtr(getOperand(0), Ops) : - ConstantExpr::getGetElementPtr(getOperand(0), Ops); + return + ConstantExpr::getGetElementPtr(getOperand(0), Ops, + cast(this)->isInBounds()); } default: assert(getNumOperands() == 2 && "Must be binary operator?"); @@ -891,9 +891,9 @@ getWithOperands(ArrayRef Ops, Type *Ty) const { case Instruction::ShuffleVector: return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]); case Instruction::GetElementPtr: - return cast(this)->isInBounds() ? - ConstantExpr::getInBoundsGetElementPtr(Ops[0], Ops.slice(1)) : - ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1)); + return + ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1), + cast(this)->isInBounds()); case Instruction::ICmp: case Instruction::FCmp: return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);