[PATCH] D115784: [LoopIdiom] Use utility from SE instead of local rewriter
Yueh-Ting Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 14 23:00:37 PST 2021
eopXD created this revision.
eopXD added a reviewer: reames.
Herald added a subscriber: hiraditya.
eopXD requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
ScalarEvolution::applyLoopGuards shall do the work.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115784
Files:
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -307,25 +307,6 @@
}
};
-// The Folder will fold expressions that are guarded by the loop entry.
-class SCEVSignToZeroExtentionRewriter
- : public SCEVRewriteVisitor<SCEVSignToZeroExtentionRewriter> {
-public:
- ScalarEvolution &SE;
- const Loop *CurLoop;
- SCEVSignToZeroExtentionRewriter(ScalarEvolution &SE, const Loop *CurLoop)
- : SCEVRewriteVisitor(SE), SE(SE), CurLoop(CurLoop) {}
-
- const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
- // If expression is guarded by CurLoop to be greater or equal to zero
- // then convert sext to zext. Otherwise return the original expression.
- if (SE.isLoopEntryGuardedByCond(CurLoop, ICmpInst::ICMP_SGE, Expr,
- SE.getZero(Expr->getType())))
- return SE.getZeroExtendExpr(visit(Expr->getOperand()), Expr->getType());
- return Expr;
- }
-};
-
} // end anonymous namespace
char LoopIdiomRecognizeLegacyPass::ID = 0;
@@ -986,12 +967,12 @@
<< "\n");
if (PositiveStrideSCEV != MemsetSizeSCEV) {
- // The folding is to fold an expression that is covered by the loop guard
- // at loop entry. After the folding, compare again and proceed with
- // optimization, if equal.
- SCEVSignToZeroExtentionRewriter Folder(*SE, CurLoop);
- const SCEV *FoldedPositiveStride = Folder.visit(PositiveStrideSCEV);
- const SCEV *FoldedMemsetSize = Folder.visit(MemsetSizeSCEV);
+ // If an expression is covered by the loop guard, compare again and
+ // proceed with optimization if equal.
+ const SCEV *FoldedPositiveStride =
+ SE->applyLoopGuards(PositiveStrideSCEV, CurLoop);
+ const SCEV *FoldedMemsetSize =
+ SE->applyLoopGuards(MemsetSizeSCEV, CurLoop);
LLVM_DEBUG(dbgs() << " Try to fold SCEV based on loop guard\n"
<< " FoldedMemsetSize: " << *FoldedMemsetSize << "\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115784.394472.patch
Type: text/x-patch
Size: 2162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211215/de8c6b88/attachment.bin>
More information about the llvm-commits
mailing list