aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2022-12-14 11:59:19 +0000
committerFlorian Hahn <flo@fhahn.com>2022-12-14 11:59:19 +0000
commit6e86b544dddae043be0e896f0d5101eb9d1a89f7 (patch)
tree13824e7ec1b50e1e373cafd4af319f93e83ab382 /llvm/lib/Analysis/ScalarEvolution.cpp
parent31f7b1eb65add100953f11ffec34d7a3a2e30299 (diff)
downloadllvm-6e86b544dddae043be0e896f0d5101eb9d1a89f7.zip
llvm-6e86b544dddae043be0e896f0d5101eb9d1a89f7.tar.gz
llvm-6e86b544dddae043be0e896f0d5101eb9d1a89f7.tar.bz2
[SCEV] Cache folded SExt SCEV expressions.
Use FoldID to cache SignExtendExprs that get folded to a different SCEV. Depends on D137505. Reviewed By: mkazantsev Differential Revision: https://reviews.llvm.org/D137849
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index a32a059..2a9dcac 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1934,6 +1934,31 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
Ty = getEffectiveSCEVType(Ty);
+ FoldID ID;
+ ID.addInteger(scSignExtend);
+ ID.addPointer(Op);
+ ID.addPointer(Ty);
+ auto Iter = FoldCache.find(ID);
+ if (Iter != FoldCache.end())
+ return Iter->second;
+
+ const SCEV *S = getSignExtendExprImpl(Op, Ty, Depth);
+ if (!isa<SCEVSignExtendExpr>(S)) {
+ FoldCache.insert({ID, S});
+ auto R = FoldCacheUser.insert({S, {}});
+ R.first->second.push_back(ID);
+ }
+ return S;
+}
+
+const SCEV *ScalarEvolution::getSignExtendExprImpl(const SCEV *Op, Type *Ty,
+ unsigned Depth) {
+ assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) &&
+ "This is not an extending conversion!");
+ assert(isSCEVable(Ty) && "This is not a conversion to a SCEVable type!");
+ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
+ Ty = getEffectiveSCEVType(Ty);
+
// Fold if the operand is constant.
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
return getConstant(