[PATCH] D137849: [SCEV] Cache folded SExt SCEV expressions.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 11 08:37:18 PST 2022
fhahn created this revision.
fhahn added reviewers: efriedma, nikic, reames, mkazantsev.
Herald added a subscriber: hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.
Depends on D137505 <https://reviews.llvm.org/D137505>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137849
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1930,6 +1930,32 @@
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.insert({ID, nullptr});
+ if (Iter.second || !Iter.first->second) {
+ auto *S = getSignExtendExprImpl(Op, Ty, Depth);
+
+ Iter = FoldCache.insert({ID, nullptr});
+ Iter.first->second = S;
+
+ auto R = FoldCacheUser.insert({S, {}});
+ R.first->second.push_back(ID);
+ }
+ return Iter.first->second;
+}
+
+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(
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -629,6 +629,7 @@
const SCEV *getZeroExtendExprImpl(const SCEV *Op, Type *Ty,
unsigned Depth = 0);
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
+ const SCEV *getSignExtendExprImpl(const SCEV *Op, Type *Ty, unsigned Depth = 0);
const SCEV *getCastExpr(SCEVTypes Kind, const SCEV *Op, Type *Ty);
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137849.474778.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221111/30b92ae1/attachment.bin>
More information about the llvm-commits
mailing list