[llvm] 96ef794 - [SCEV] Add a hasFlags utility to improve readability [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 23 17:37:04 PDT 2021
Author: Philip Reames
Date: 2021-08-23T17:36:52-07:00
New Revision: 96ef794fd04d8d2e7d15527e4ec18895de83a9cf
URL: https://github.com/llvm/llvm-project/commit/96ef794fd04d8d2e7d15527e4ec18895de83a9cf
DIFF: https://github.com/llvm/llvm-project/commit/96ef794fd04d8d2e7d15527e4ec18895de83a9cf.diff
LOG: [SCEV] Add a hasFlags utility to improve readability [NFC]
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 ae9c73fede961..bbe94c8ed8f6f 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -472,6 +472,10 @@ class ScalarEvolution {
clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
}
+ LLVM_NODISCARD static bool hasFlags(SCEV::NoWrapFlags Flags,
+ SCEV::NoWrapFlags TestFlags) {
+ return TestFlags == maskFlags(Flags, TestFlags);
+ };
ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
DominatorTree &DT, LoopInfo &LI);
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index e6fdcc1ea4f10..b43e69fb4ed25 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -2562,8 +2562,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
APInt ConstAdd = C1 + C2;
auto AddFlags = AddExpr->getNoWrapFlags();
// Adding a smaller constant is NUW if the original AddExpr was NUW.
- if (ScalarEvolution::maskFlags(AddFlags, SCEV::FlagNUW) ==
- SCEV::FlagNUW &&
+ if (ScalarEvolution::hasFlags(AddFlags, SCEV::FlagNUW) &&
ConstAdd.ule(C1)) {
PreservedFlags =
ScalarEvolution::setFlags(PreservedFlags, SCEV::FlagNUW);
@@ -2571,8 +2570,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
// Adding a constant with the same sign and small magnitude is NSW, if the
// original AddExpr was NSW.
- if (ScalarEvolution::maskFlags(AddFlags, SCEV::FlagNSW) ==
- SCEV::FlagNSW &&
+ if (ScalarEvolution::hasFlags(AddFlags, SCEV::FlagNSW) &&
C1.isSignBitSet() == ConstAdd.isSignBitSet() &&
ConstAdd.abs().ule(C1.abs())) {
PreservedFlags =
@@ -4207,7 +4205,7 @@ const SCEV *ScalarEvolution::getMinusSCEV(const SCEV *LHS, const SCEV *RHS,
auto AddFlags = SCEV::FlagAnyWrap;
const bool RHSIsNotMinSigned =
!getSignedRangeMin(RHS).isMinSignedValue();
- if (maskFlags(Flags, SCEV::FlagNSW) == SCEV::FlagNSW) {
+ if (hasFlags(Flags, SCEV::FlagNSW)) {
// Let M be the minimum representable signed value. Then (-1)*RHS
// signed-wraps if and only if RHS is M. That can happen even for
// a NSW subtraction because e.g. (-1)*M signed-wraps even though
More information about the llvm-commits
mailing list