[llvm] Handle backedge-count logic for std::reverse like loops (PR #92560)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 20 13:13:23 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 7ef602b58c1ccacab20d9d01e24b281458c3facc a702df91a2e2b748e89f1be72c94bf5f1175a00f -- llvm/lib/Analysis/ScalarEvolution.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c273abf088..8e6c907a6f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12941,10 +12941,10 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
return RHS;
}
- const SCEV *End = nullptr, *BECount = nullptr,
- *BECountIfBackedgeTaken = nullptr;
+ const SCEV *End = nullptr, *BECount = nullptr,
+ *BECountIfBackedgeTaken = nullptr;
if (!isLoopInvariant(RHS, L)) {
- if (auto RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)){
+ if (auto RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)) {
/*
The structure of loop we are trying to calculate backedge-count of:
left = left_start
@@ -12962,23 +12962,23 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
const SCEV *RHSStride = RHSAddRec->getStepRecurrence(*this);
// if Stride-RHSStride>0 and does not overflow, we can write
// backedge count as:
- // RHSStart >= Start ? (RHSStart - Start)/(Stride - RHSStride) ? 0
+ // RHSStart >= Start ? (RHSStart - Start)/(Stride - RHSStride) ? 0
- // check if RHSStride<0 and Stride-RHSStride will not overflow
+ // check if RHSStride<0 and Stride-RHSStride will not overflow
// FIXME: Can RHSStride be positive?
- if (isKnownNegative(RHSStride) &&
- willNotOverflow(llvm::Instruction::Sub, true, Stride, RHSStride)) {
-
- const SCEV *Denominator = getMinusSCEV(Stride, RHSStride);
+ if (isKnownNegative(RHSStride) &&
+ willNotOverflow(llvm::Instruction::Sub, true, Stride, RHSStride)) {
+
+ const SCEV *Denominator = getMinusSCEV(Stride, RHSStride);
if (isKnownPositive(Denominator)) {
- End = IsSigned ? getSMaxExpr(RHSStart, Start) :
- getUMaxExpr(RHSStart, Start); // max(RHSStart, Start)
+ End = IsSigned ? getSMaxExpr(RHSStart, Start)
+ : getUMaxExpr(RHSStart, Start); // max(RHSStart, Start)
const SCEV *Delta = getMinusSCEV(End, Start); // End >= Start
-
+
BECount = getUDivCeilSCEV(Delta, Denominator);
- BECountIfBackedgeTaken = getUDivCeilSCEV(
- getMinusSCEV(RHSStart, Start), Denominator);
+ BECountIfBackedgeTaken =
+ getUDivCeilSCEV(getMinusSCEV(RHSStart, Start), Denominator);
const SCEV *ConstantMaxBECount;
bool MaxOrZero = false;
@@ -12989,25 +12989,25 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
MaxOrZero = true;
} else {
ConstantMaxBECount = computeMaxBECountForLT(
- Start, Stride, RHS, getTypeSizeInBits(LHS->getType()),
+ Start, Stride, RHS, getTypeSizeInBits(LHS->getType()),
IsSigned);
}
const SCEV *SymbolicMaxBECount = BECount;
- return ExitLimit(BECount, ConstantMaxBECount, SymbolicMaxBECount,
- MaxOrZero, Predicates);
+ return ExitLimit(BECount, ConstantMaxBECount, SymbolicMaxBECount,
+ MaxOrZero, Predicates);
}
}
- }
+ }
if (BECount == nullptr) {
- // If we cannot calculate ExactBECount, we can calculate the MaxBECount,
- // given the start, stride and max value for the end bound of the
+ // If we cannot calculate ExactBECount, we can calculate the MaxBECount,
+ // given the start, stride and max value for the end bound of the
// loop (RHS), and the fact that IV does not overflow (which is
// checked above).
const SCEV *MaxBECount = computeMaxBECountForLT(
Start, Stride, RHS, getTypeSizeInBits(LHS->getType()), IsSigned);
return ExitLimit(getCouldNotCompute() /* ExactNotTaken */, MaxBECount,
- MaxBECount, false /*MaxOrZero*/, Predicates);
+ MaxBECount, false /*MaxOrZero*/, Predicates);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/92560
More information about the llvm-commits
mailing list