[LLVMdev] ConstantExpr::replaceUsesOfWithOnConstant() function for llvm::GetElementPtrConstantExpr
Jin Gu Kang
jaykang10 at imrc.kist.re.kr
Thu Feb 10 03:31:45 PST 2011
Hi LLVMdev members
I found something strange in ConstantExpr::replaceUsesOfWithOnConstant() function.
in lib/VMCore/Constants.cpp file
2118 if (getOpcode() == Instruction::GetElementPtr) {
2119 SmallVector<Constant*, 8> Indices;
2120 Constant *Pointer = getOperand(0);
2121 Indices.reserve(getNumOperands()-1);
2122 if (Pointer == From) Pointer = To;
2123
2124 for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
2125 Constant *Val = getOperand(i);
2126 if (Val == From) Val = To;
2127 Indices.push_back(Val);
2128 }
2129 Replacement = ConstantExpr::getGetElementPtr(Pointer,
2130 &Indices[0], Indices.size());
when making replacement for GetElementPtr, above codes do not consider inbounds factor.
so, I thought codes to inbounds factor as follows:
original
2129 Replacement = ConstantExpr::getGetElementPtr(Pointer,
2130 &Indices[0], Indices.size());
------------------------------------------------------------------------------------------->
modified
2129 if(cast<GEPOperator>(this)->isInBounds())
2130 Replacement = ConstantExpr::getInBoundsGetElementPtr(Pointer,
2131 &Indices[0], Indices.size());
2132 else
2133 Replacement = ConstantExpr::getGetElementPtr(Pointer,
2134 &Indices[0], Indices.size());
What do you think about above codes?
Best regards,
Jin-Gu Kang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110210/3e2d880c/attachment.html>
More information about the llvm-dev
mailing list