[IR] Make getIndexedOffsetInType return a signed result

A GEPed offset can go negative, the result of getIndexedOffsetInType
should according be a signed type.

llvm-svn: 275246
This commit is contained in:
David Majnemer 2016-07-13 03:42:38 +00:00
parent ea53e31958
commit bf9b17b342
4 changed files with 9 additions and 9 deletions

View File

@ -440,7 +440,7 @@ public:
///
/// Note that this takes the element type, not the pointer type.
/// This is used to implement getelementptr.
uint64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
/// \brief Returns a StructLayout object, indicating the alignment of the
/// struct, its size, and the offsets of its fields.

View File

@ -920,7 +920,7 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, Type *DestTy,
if (Instruction::isCast(Opcode))
return ConstantFoldCastOperand(Opcode, Ops[0], DestTy, DL);
if(auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
if (auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
if (Constant *C = SymbolicallyEvaluateGEP(GEP, Ops, DL, TLI))
return C;

View File

@ -41,7 +41,7 @@ findCallsAtConstantOffset(SmallVectorImpl<DevirtCallSite> &DevirtCalls,
static void
findLoadCallsAtConstantOffset(Module *M,
SmallVectorImpl<DevirtCallSite> &DevirtCalls,
Value *VPtr, uint64_t Offset) {
Value *VPtr, int64_t Offset) {
for (const Use &U : VPtr->uses()) {
Value *User = U.getUser();
if (isa<BitCastInst>(User)) {
@ -52,7 +52,7 @@ findLoadCallsAtConstantOffset(Module *M,
// Take into account the GEP offset.
if (VPtr == GEP->getPointerOperand() && GEP->hasAllConstantIndices()) {
SmallVector<Value *, 8> Indices(GEP->op_begin() + 1, GEP->op_end());
uint64_t GEPOffset = M->getDataLayout().getIndexedOffsetInType(
int64_t GEPOffset = M->getDataLayout().getIndexedOffsetInType(
GEP->getSourceElementType(), Indices);
findLoadCallsAtConstantOffset(M, DevirtCalls, User, Offset + GEPOffset);
}

View File

@ -723,9 +723,9 @@ unsigned DataLayout::getLargestLegalIntTypeSizeInBits() const {
return Max != LegalIntWidths.end() ? *Max : 0;
}
uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
ArrayRef<Value *> Indices) const {
uint64_t Result = 0;
int64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
ArrayRef<Value *> Indices) const {
int64_t Result = 0;
// We can use 0 as the address space as we don't need
// to get pointer types back from gep_type_iterator.
@ -735,7 +735,7 @@ uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
GTE = gep_type_end(ElemTy, AS, Indices);
for (; GTI != GTE; ++GTI) {
Value *Idx = GTI.getOperand();
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
if (auto *STy = dyn_cast<StructType>(*GTI)) {
assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx");
unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
@ -747,7 +747,7 @@ uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
} else {
// Get the array index and the size of each array element.
if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
Result += (uint64_t)arrayIdx * getTypeAllocSize(GTI.getIndexedType());
Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType());
}
}