aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorkhei4 <kk.asano.luxy@gmail.com>2023-05-15 22:33:15 +0900
committerkhei4 <kk.asano.luxy@gmail.com>2023-05-15 23:04:47 +0900
commitf5dbbf494ff0020978d7cdd052980e9ab9c05edb (patch)
tree8eac6855db560091e5da404cdeaacbf7451a86b8 /llvm/lib/Analysis/ConstantFolding.cpp
parent627e6efa5b274db10564ace161d2ef583ddfcb66 (diff)
downloadllvm-f5dbbf494ff0020978d7cdd052980e9ab9c05edb.zip
llvm-f5dbbf494ff0020978d7cdd052980e9ab9c05edb.tar.gz
llvm-f5dbbf494ff0020978d7cdd052980e9ab9c05edb.tar.bz2
[ConstantFold] use StoreSize for VectorType folding
Differential Revision: https://reviews.llvm.org/D150515 Reviewed By: nikic
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index ce6f334..7a4ea74 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -501,16 +501,22 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr,
if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
isa<ConstantDataSequential>(C)) {
- uint64_t NumElts;
+ uint64_t NumElts, EltSize;
Type *EltTy;
if (auto *AT = dyn_cast<ArrayType>(C->getType())) {
NumElts = AT->getNumElements();
EltTy = AT->getElementType();
+ EltSize = DL.getTypeAllocSize(EltTy);
} else {
NumElts = cast<FixedVectorType>(C->getType())->getNumElements();
EltTy = cast<FixedVectorType>(C->getType())->getElementType();
+ // TODO: For non-byte-sized vectors, current implementation assumes there is
+ // padding to the next byte boundary between elements.
+ if (!DL.typeSizeEqualsStoreSize(EltTy))
+ return false;
+
+ EltSize = DL.getTypeStoreSize(EltTy);
}
- uint64_t EltSize = DL.getTypeAllocSize(EltTy);
uint64_t Index = ByteOffset / EltSize;
uint64_t Offset = ByteOffset - Index * EltSize;