[llvm] aabca2d - [SCEV] Cleanup doesIVOverflowOnX checks [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue May 25 10:12:32 PDT 2021
Author: Philip Reames
Date: 2021-05-25T10:12:24-07:00
New Revision: aabca2d1da11aa3b832ce499acccca093236aac3
URL: https://github.com/llvm/llvm-project/commit/aabca2d1da11aa3b832ce499acccca093236aac3
DIFF: https://github.com/llvm/llvm-project/commit/aabca2d1da11aa3b832ce499acccca093236aac3.diff
LOG: [SCEV] Cleanup doesIVOverflowOnX checks [NFC]
Stylistic changes only.
1) Don't pass a parameter just to do an early exit.
2) Use a name which matches actual behavior.
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 2afa2d1b25b8..547183d54172 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -2002,15 +2002,13 @@ class ScalarEvolution {
/// Verify if an linear IV with positive stride can overflow when in a
/// less-than comparison, knowing the invariant term of the comparison,
- /// the stride and the knowledge of NSW/NUW flags on the recurrence.
- bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride, bool IsSigned,
- bool NoWrap);
+ /// the stride.
+ bool canIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride, bool IsSigned);
/// Verify if an linear IV with negative stride can overflow when in a
/// greater-than comparison, knowing the invariant term of the comparison,
- /// the stride and the knowledge of NSW/NUW flags on the recurrence.
- bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride, bool IsSigned,
- bool NoWrap);
+ /// the stride.
+ bool canIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride, bool IsSigned);
/// Get add expr already created or create a new one.
const SCEV *getOrCreateAddExpr(ArrayRef<const SCEV *> Ops,
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index af5e8bd66bfa..1687929650f0 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11183,12 +11183,10 @@ bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred,
return LHSRange.icmp(Pred, ConstRHS);
}
-bool ScalarEvolution::doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
- bool IsSigned, bool NoWrap) {
+bool ScalarEvolution::canIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
+ bool IsSigned) {
assert(isKnownPositive(Stride) && "Positive stride expected!");
- if (NoWrap) return false;
-
unsigned BitWidth = getTypeSizeInBits(RHS->getType());
const SCEV *One = getOne(Stride->getType());
@@ -11209,10 +11207,9 @@ bool ScalarEvolution::doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
return (std::move(MaxValue) - MaxStrideMinusOne).ult(MaxRHS);
}
-bool ScalarEvolution::doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
- bool IsSigned, bool NoWrap) {
- if (NoWrap) return false;
-
+bool ScalarEvolution::canIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
+ bool IsSigned) {
+
unsigned BitWidth = getTypeSizeInBits(RHS->getType());
const SCEV *One = getOne(Stride->getType());
@@ -11357,13 +11354,14 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
if (PredicatedIV || !NoWrap || isKnownNonPositive(Stride) ||
!loopHasNoSideEffects(L))
return getCouldNotCompute();
- } else if (!Stride->isOne() &&
- doesIVOverflowOnLT(RHS, Stride, IsSigned, NoWrap))
+ } else if (!Stride->isOne() && !NoWrap) {
// Avoid proven overflow cases: this will ensure that the backedge taken
// count will not generate any unsigned overflow. Relaxed no-overflow
// conditions exploit NoWrapFlags, allowing to optimize in presence of
// undefined behaviors like the case of C language.
- return getCouldNotCompute();
+ if (canIVOverflowOnLT(RHS, Stride, IsSigned))
+ return getCouldNotCompute();
+ }
ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT
: ICmpInst::ICMP_ULT;
@@ -11462,8 +11460,9 @@ ScalarEvolution::howManyGreaterThans(const SCEV *LHS, const SCEV *RHS,
// will not generate any unsigned overflow. Relaxed no-overflow conditions
// exploit NoWrapFlags, allowing to optimize in presence of undefined
// behaviors like the case of C language.
- if (!Stride->isOne() && doesIVOverflowOnGT(RHS, Stride, IsSigned, NoWrap))
- return getCouldNotCompute();
+ if (!Stride->isOne() && !NoWrap)
+ if (canIVOverflowOnGT(RHS, Stride, IsSigned))
+ return getCouldNotCompute();
ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SGT
: ICmpInst::ICMP_UGT;
More information about the llvm-commits
mailing list