aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-10-21 20:46:06 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-10-22 18:33:03 +0200
commit3a10fe2d893f3c112663d117a4802aacde3b378a (patch)
treedec4a87836c2184168ab6267e731a0828b0747fb /llvm/lib/Analysis/Loads.cpp
parent5bb7562962de711959401db5a1eb7ad0ae8bc10b (diff)
downloadllvm-3a10fe2d893f3c112663d117a4802aacde3b378a.zip
llvm-3a10fe2d893f3c112663d117a4802aacde3b378a.tar.gz
llvm-3a10fe2d893f3c112663d117a4802aacde3b378a.tar.bz2
[Loads] Use more powerful constant folding API
This follows up on D111023 by exporting the generic "load value from constant at given offset as given type" and using it in the store to load forwarding code. We now need to make sure that the load size is smaller than the store size, previously this was implicitly ensured by ConstantFoldLoadThroughBitcast(). Differential Revision: https://reviews.llvm.org/D112260
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 2e5f80d..1882e31 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -511,8 +511,11 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
return Val;
- if (auto *C = dyn_cast<Constant>(Val))
- return ConstantFoldLoadThroughBitcast(C, AccessTy, DL);
+ TypeSize StoreSize = DL.getTypeStoreSize(Val->getType());
+ TypeSize LoadSize = DL.getTypeStoreSize(AccessTy);
+ if (TypeSize::isKnownLE(LoadSize, StoreSize))
+ if (auto *C = dyn_cast<Constant>(Val))
+ return ConstantFoldLoadFromConst(C, AccessTy, DL);
}
return nullptr;