mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
ConstantFolding: Evaluate GEP indices in the index type.
This fixes some edge cases that we would get wrong with uint64_ts. PR14986. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173289 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -254,13 +254,22 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
|
||||
if (!CI) return false; // Index isn't a simple constant?
|
||||
if (CI->isZero()) continue; // Not adding anything.
|
||||
|
||||
// Evaluate offsets in the index type.
|
||||
APInt APOffset(CI->getBitWidth(), Offset);
|
||||
|
||||
if (StructType *ST = dyn_cast<StructType>(*GTI)) {
|
||||
// N = N + Offset
|
||||
Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
|
||||
APOffset +=
|
||||
APInt(CI->getBitWidth(),
|
||||
TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue()));
|
||||
} else {
|
||||
SequentialType *SQT = cast<SequentialType>(*GTI);
|
||||
Offset += TD.getTypeAllocSize(SQT->getElementType())*CI->getSExtValue();
|
||||
APOffset +=
|
||||
APInt(CI->getBitWidth(),
|
||||
TD.getTypeAllocSize(SQT->getElementType())*CI->getSExtValue());
|
||||
}
|
||||
|
||||
Offset = APOffset.getSExtValue();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user