mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 15:39:06 +00:00
[IR] Make getIndexedOffsetInType return a signed result
A GEPed offset can go negative, the result of getIndexedOffsetInType should according be a signed type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275246 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
43ac9a4a1e
commit
17c5ce914c
@ -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.
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user