[PATCH] D148205: [IRCE] Refactor parseRangeCheckICmp to compute SCEVs instead of Values
Aleksandr Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 02:46:31 PDT 2023
aleksandr.popov created this revision.
aleksandr.popov added reviewers: reames, mkazantsev, skatkov, danilaml, dmakogon.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The motivation is to make an opportunity to compute and return
expressions after parsing ICmp into a range check (e.g. Length + 1)
https://reviews.llvm.org/D148205
Files:
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
Index: llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -145,7 +145,7 @@
Use *CheckUse = nullptr;
static bool parseRangeCheckICmp(Loop *L, ICmpInst *ICI, ScalarEvolution &SE,
- Value *&Index, Value *&Length);
+ const SCEV *&Index, const SCEV *&End);
static void
extractRangeChecksFromCond(Loop *L, ScalarEvolution &SE, Use &ConditionUse,
@@ -284,13 +284,13 @@
false, false)
/// Parse a single ICmp instruction, `ICI`, into a range check. If `ICI` cannot
-/// be interpreted as a range check, return false and set `Index` and `Length`
-/// to `nullptr`. Otherwise set `Index` to the value being range checked, and
-/// set `Length` to the upper limit `Index` is being range checked.
-bool
-InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
- ScalarEvolution &SE, Value *&Index,
- Value *&Length) {
+/// be interpreted as a range check, return false and set `Index` and `End`
+/// to `nullptr`. Otherwise set `Index` to the SCEV being range checked, and
+/// set `End` to the upper limit `Index` is being range checked.
+bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
+ ScalarEvolution &SE,
+ const SCEV *&Index,
+ const SCEV *&End) {
auto IsLoopInvariant = [&SE, L](Value *V) {
return SE.isLoopInvariant(SE.getSCEV(V), L);
};
@@ -308,7 +308,7 @@
[[fallthrough]];
case ICmpInst::ICMP_SGE:
if (match(RHS, m_ConstantInt<0>())) {
- Index = LHS;
+ Index = SE.getSCEV(LHS);
return true; // Lower.
}
return false;
@@ -318,13 +318,13 @@
[[fallthrough]];
case ICmpInst::ICMP_SGT:
if (match(RHS, m_ConstantInt<-1>())) {
- Index = LHS;
+ Index = SE.getSCEV(LHS);
return true; // Lower.
}
if (IsLoopInvariant(LHS)) {
- Index = RHS;
- Length = LHS;
+ Index = SE.getSCEV(RHS);
+ End = SE.getSCEV(LHS);
return true; // Upper.
}
return false;
@@ -334,8 +334,8 @@
[[fallthrough]];
case ICmpInst::ICMP_UGT:
if (IsLoopInvariant(LHS)) {
- Index = RHS;
- Length = LHS;
+ Index = SE.getSCEV(RHS);
+ End = SE.getSCEV(LHS);
return true; // Both lower and upper.
}
return false;
@@ -365,23 +365,20 @@
if (!ICI)
return;
- Value *Length = nullptr, *Index;
- if (!parseRangeCheckICmp(L, ICI, SE, Index, Length))
+ const SCEV *End = nullptr, *Index;
+ if (!parseRangeCheckICmp(L, ICI, SE, Index, End))
return;
- const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(Index));
+ const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(Index);
bool IsAffineIndex =
IndexAddRec && (IndexAddRec->getLoop() == L) && IndexAddRec->isAffine();
if (!IsAffineIndex)
return;
- const SCEV *End = nullptr;
// We strengthen "0 <= I" to "0 <= I < INT_SMAX" and "I < L" to "0 <= I < L".
// We can potentially do much better here.
- if (Length)
- End = SE.getSCEV(Length);
- else {
+ if (!End) {
// So far we can only reach this point for Signed range check. This may
// change in future. In this case we will need to pick Unsigned max for the
// unsigned range check.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148205.513133.patch
Type: text/x-patch
Size: 3655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/9640b603/attachment.bin>
More information about the llvm-commits
mailing list