[llvm] r275246 - [IR] Make getIndexedOffsetInType return a signed result
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 12 20:42:39 PDT 2016
Author: majnemer
Date: Tue Jul 12 22:42:38 2016
New Revision: 275246
URL: http://llvm.org/viewvc/llvm-project?rev=275246&view=rev
Log:
[IR] Make getIndexedOffsetInType return a signed result
A GEPed offset can go negative, the result of getIndexedOffsetInType
should according be a signed type.
Modified:
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/lib/Analysis/TypeMetadataUtils.cpp
llvm/trunk/lib/IR/DataLayout.cpp
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=275246&r1=275245&r2=275246&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Tue Jul 12 22:42:38 2016
@@ -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.
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=275246&r1=275245&r2=275246&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Tue Jul 12 22:42:38 2016
@@ -920,7 +920,7 @@ Constant *ConstantFoldInstOperandsImpl(c
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;
Modified: llvm/trunk/lib/Analysis/TypeMetadataUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TypeMetadataUtils.cpp?rev=275246&r1=275245&r2=275246&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TypeMetadataUtils.cpp (original)
+++ llvm/trunk/lib/Analysis/TypeMetadataUtils.cpp Tue Jul 12 22:42:38 2016
@@ -41,7 +41,7 @@ findCallsAtConstantOffset(SmallVectorImp
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);
}
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=275246&r1=275245&r2=275246&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Tue Jul 12 22:42:38 2016
@@ -723,9 +723,9 @@ unsigned DataLayout::getLargestLegalIntT
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::getIndexedOffsetInT
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::getIndexedOffsetInT
} 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());
}
}
More information about the llvm-commits
mailing list