diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-01-23 20:41:05 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-01-23 20:41:05 +0000 |
commit | b4d201ec544bbd3aec5e9feaec44df43b6b4bb6c (patch) | |
tree | d8c04802d6bd1193a715a96f8b9ec221ef9125e7 /lib/Analysis | |
parent | 9e6a5a37460ff82ad4e3a7aea1c45e2c934ab25b (diff) | |
download | external_llvm-b4d201ec544bbd3aec5e9feaec44df43b6b4bb6c.zip external_llvm-b4d201ec544bbd3aec5e9feaec44df43b6b4bb6c.tar.gz external_llvm-b4d201ec544bbd3aec5e9feaec44df43b6b4bb6c.tar.bz2 |
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
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index e2b1e25..95a68bf 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -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; } |