[llvm] [polly] [SCEV] Refactor SCEV flags, in preparation to extend (NFC) (PR #225179)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 12:53:50 PDT 2026


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/225179

In preparation to extend the flags that ScalarEvolution can represent, rename SCEV::NoWrapFlags to the more general SCEVFlags. This is a large refactoring non-functional change.

See also: #225065

>From 4e1a5c0314a5415b948e0de3ade4f79ef5e5beda Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 21 Sep 2026 20:20:32 +0100
Subject: [PATCH] [SCEV] Refactor SCEV flags, in preparation to extend (NFC)

In preparation to extend the flags that ScalarEvolution can represent,
rename SCEV::NoWrapFlags to the more general SCEVFlags. This is a large
refactoring non-functional change.

See also: #225065
---
 llvm/include/llvm/Analysis/IVDescriptors.h    |   9 +-
 llvm/include/llvm/Analysis/ScalarEvolution.h  | 128 +++--
 .../Analysis/ScalarEvolutionExpressions.h     |  51 +-
 .../Analysis/ScalarEvolutionPatternMatch.h    |  26 +-
 .../Utils/ScalarEvolutionExpander.h           |   4 +-
 llvm/lib/Analysis/IVDescriptors.cpp           |   2 +-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp      |   2 +-
 llvm/lib/Analysis/LoopCacheAnalysis.cpp       |   6 +-
 llvm/lib/Analysis/ScalarEvolution.cpp         | 483 +++++++++---------
 llvm/lib/Analysis/ScalarEvolutionDivision.cpp |   8 +-
 .../Analysis/ScalarEvolutionNormalization.cpp |   4 +-
 .../Transforms/Scalar/LoopStrengthReduce.cpp  |  10 +-
 .../Utils/ScalarEvolutionExpander.cpp         |  45 +-
 .../Vectorize/LoopVectorizationLegality.cpp   |   2 +-
 llvm/lib/Transforms/Vectorize/VPlanUtils.cpp  |  14 +-
 llvm/unittests/Analysis/IVDescriptorsTest.cpp |   2 +-
 .../Analysis/ScalarEvolutionTest.cpp          | 127 +++--
 .../Utils/ScalarEvolutionExpanderTest.cpp     |   8 +-
 polly/lib/Analysis/ScopInfo.cpp               |   2 +-
 polly/lib/CodeGen/IslNodeBuilder.cpp          |   6 +-
 polly/lib/Support/SCEVAffinator.cpp           |   8 +-
 polly/lib/Support/SCEVValidator.cpp           |   9 +-
 polly/lib/Support/ScopHelper.cpp              |   2 +-
 23 files changed, 459 insertions(+), 499 deletions(-)

diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h
index 7548ea1c871fe..08bde23b8f328 100644
--- a/llvm/include/llvm/Analysis/IVDescriptors.h
+++ b/llvm/include/llvm/Analysis/IVDescriptors.h
@@ -30,7 +30,7 @@ class ScalarEvolution;
 class SCEV;
 class SCEVPredicate;
 class StoreInst;
-enum class SCEVNoWrapFlags;
+enum class SCEVFlags;
 
 /// These are the kinds of recurrences that we support.
 enum class RecurKind {
@@ -515,13 +515,12 @@ class ConditionalInductionDescriptor {
   const SCEV *getStepSCEV() const { return StepSCEV; }
 
   /// Returns the SCEV no-wrap flags that apply to StepInst.
-  SCEVNoWrapFlags getSCEVNoWrapFlags() const { return NoWrapFlags; }
+  SCEVFlags getSCEVNoWrapFlags() const { return NoWrapFlags; }
 
 private:
   ConditionalInductionDescriptor(PHINode *HeaderPHI, PHINode *BackedgePHI,
                                  Instruction *StepInst, const SCEV *StartSCEV,
-                                 const SCEV *StepSCEV,
-                                 SCEVNoWrapFlags NoWrapFlags)
+                                 const SCEV *StepSCEV, SCEVFlags NoWrapFlags)
       : HeaderPHI(HeaderPHI), BackedgePHI(BackedgePHI), StepInst(StepInst),
         StartSCEV(StartSCEV), StepSCEV(StepSCEV), NoWrapFlags(NoWrapFlags) {}
 
@@ -543,7 +542,7 @@ class ConditionalInductionDescriptor {
   const SCEV *StepSCEV = nullptr;
 
   /// The SCEV no-wrap flags that apply to StepInst.
-  SCEVNoWrapFlags NoWrapFlags{};
+  SCEVFlags NoWrapFlags{};
 };
 
 } // end namespace llvm
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 8d423c57824e7..2ba0ae30f5ce4 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -107,20 +107,20 @@ LLVM_ABI extern bool VerifySCEV;
 /// can trap) can be defined per these rules in regions where it would trap
 /// at runtime.  A SCEV being defined does not require the existence of any
 /// instruction within the defined scope.
-enum class SCEVNoWrapFlags {
-  FlagAnyWrap = 0,    // No guarantee.
+enum class SCEVFlags {
+  FlagAny = 0,        // No guarantee.
   FlagNW = (1 << 0),  // No self-wrap.
   FlagNUW = (1 << 1), // No unsigned wrap.
   FlagNSW = (1 << 2), // No signed wrap.
-  NoWrapMask = (1 << 3) - 1,
-  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/NoWrapMask)
+  NoFlagMask = (1 << 3) - 1,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/NoFlagMask)
 };
 
 class SCEV;
 
 template <typename SCEVPtrT = const SCEV *>
-struct SCEVUseT : private PointerIntPair<SCEVPtrT, 2> {
-  using Base = PointerIntPair<SCEVPtrT, 2>;
+struct SCEVUseT : private PointerIntPair<SCEVPtrT, 3> {
+  using Base = PointerIntPair<SCEVPtrT, 3>;
   using Base::getOpaqueValue;
   using Base::getPointer;
 
@@ -130,11 +130,11 @@ struct SCEVUseT : private PointerIntPair<SCEVPtrT, 2> {
   /// must be an expression supporting flags. Only flags not already present on
   /// \p S are added. Note that the expression may gain flags also part of the
   /// SCEVUse later, via settNoWrapFlags.
-  SCEVUseT(SCEVPtrT S, SCEVNoWrapFlags Flags);
+  SCEVUseT(SCEVPtrT S, SCEVFlags Flags);
   template <typename OtherPtrT, typename = std::enable_if_t<
                                     std::is_convertible_v<OtherPtrT, SCEVPtrT>>>
   SCEVUseT(const SCEVUseT<OtherPtrT> &Other)
-      : SCEVUseT(Other.getPointer(), Other.getUseNoWrapFlags()) {}
+      : SCEVUseT(Other.getPointer(), Other.getUseFlags()) {}
 
   operator SCEVPtrT() const { return getPointer(); }
   SCEVPtrT operator->() const { return getPointer(); }
@@ -151,16 +151,14 @@ struct SCEVUseT : private PointerIntPair<SCEVPtrT, 2> {
 
   /// Return the no-wrap flags for this SCEVUse, which is the union of the
   /// use-specific flags and the underlying SCEV's flags, masked by \p Mask.
-  SCEVNoWrapFlags
-  getNoWrapFlags(SCEVNoWrapFlags Mask = SCEVNoWrapFlags::NoWrapMask) const;
+  SCEVFlags getFlags(SCEVFlags Mask = SCEVFlags::NoFlagMask) const;
 
   /// Return only the use-specific no-wrap flags (NUW/NSW) without the
   /// underlying SCEV's flags.
-  SCEVNoWrapFlags getUseNoWrapFlags() const {
-    SCEVNoWrapFlags UseFlags =
-        static_cast<SCEVNoWrapFlags>(Base::getInt() << 1);
-    if (any(UseFlags & (SCEVNoWrapFlags::FlagNUW | SCEVNoWrapFlags::FlagNSW)))
-      UseFlags |= SCEVNoWrapFlags::FlagNW;
+  SCEVFlags getUseFlags() const {
+    SCEVFlags UseFlags = static_cast<SCEVFlags>(Base::getInt() << 1);
+    if (any(UseFlags & (SCEVFlags::FlagNUW | SCEVFlags::FlagNSW)))
+      UseFlags |= SCEVFlags::FlagNW;
     return UseFlags;
   }
 
@@ -193,18 +191,14 @@ template <typename SCEVPtrT> SCEVUseT(SCEVPtrT) -> SCEVUseT<SCEVPtrT>;
 using SCEVUse = SCEVUseT<const SCEV *>;
 
 /// The no-wrap flags to apply when creating a SCEV expression, to the
-/// expression and use respectively.
-struct SCEVFlags {
-  /// Flags applied directly to a SCEV expression, must be valid wherever the
-  /// expression is valid.
-  SCEVNoWrapFlags ExprFlags;
-
-  /// Flags only applied to a SCEVUse.
-  SCEVNoWrapFlags UseFlags;
-
-  constexpr SCEVFlags(SCEVNoWrapFlags ExprFlags = SCEVNoWrapFlags::FlagAnyWrap,
-                      SCEVNoWrapFlags UseFlags = SCEVNoWrapFlags::FlagAnyWrap)
-      : ExprFlags(ExprFlags), UseFlags(UseFlags) {}
+/// expression and use: the first component of the pair is applied directly to a
+/// SCEV expression, and the second component is only applied to a SCEVUse.
+struct SCEVFlagInfo : public std::pair<SCEVFlags, SCEVFlags> {
+  using BaseT = std::pair<SCEVFlags, SCEVFlags>;
+
+  constexpr SCEVFlagInfo(SCEVFlags ExprFlags = SCEVFlags::FlagAny,
+                         SCEVFlags UseFlags = SCEVFlags::FlagAny)
+      : BaseT(ExprFlags, UseFlags) {}
 };
 
 /// Provide PointerLikeTypeTraits for SCEVUse, so it can be used with
@@ -249,7 +243,7 @@ struct CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse,
 
   static bool isPossible(const SCEVUse &U) { return isa<To>(U.getPointer()); }
   static CastReturnType doCast(const SCEVUse &U) {
-    return CastReturnType(cast<To>(U.getPointer()), U.getUseNoWrapFlags());
+    return CastReturnType(cast<To>(U.getPointer()), U.getUseFlags());
   }
   static CastReturnType castFailed() { return CastReturnType(nullptr); }
   static CastReturnType doCastIfPossible(const SCEVUse &U) {
@@ -293,12 +287,11 @@ class SCEV : public FoldingSetNode {
   Type *const Ty;
 
 public:
-  using NoWrapFlags = SCEVNoWrapFlags;
-  static constexpr auto FlagAnyWrap = SCEVNoWrapFlags::FlagAnyWrap;
-  static constexpr auto FlagNW = SCEVNoWrapFlags::FlagNW;
-  static constexpr auto FlagNUW = SCEVNoWrapFlags::FlagNUW;
-  static constexpr auto FlagNSW = SCEVNoWrapFlags::FlagNSW;
-  static constexpr auto NoWrapMask = SCEVNoWrapFlags::NoWrapMask;
+  static constexpr auto FlagAny = SCEVFlags::FlagAny;
+  static constexpr auto FlagNW = SCEVFlags::FlagNW;
+  static constexpr auto FlagNUW = SCEVFlags::FlagNUW;
+  static constexpr auto FlagNSW = SCEVFlags::FlagNSW;
+  static constexpr auto NoFlagMask = SCEVFlags::NoFlagMask;
 
   explicit SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy,
                 unsigned short ExpressionSize, Type *Ty)
@@ -647,20 +640,17 @@ class ScalarEvolution {
 
   /// Convenient NoWrapFlags manipulation. TODO: Replace with & operator of
   /// enum class.
-  [[nodiscard]] static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags,
-                                                   SCEV::NoWrapFlags Mask) {
+  [[nodiscard]] static SCEVFlags maskFlags(SCEVFlags Flags, SCEVFlags Mask) {
     return Flags & Mask;
   }
-  [[nodiscard]] static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
-                                                  SCEV::NoWrapFlags OnFlags) {
+  [[nodiscard]] static SCEVFlags setFlags(SCEVFlags Flags, SCEVFlags OnFlags) {
     return Flags | OnFlags;
   }
-  [[nodiscard]] static SCEV::NoWrapFlags
-  clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
+  [[nodiscard]] static SCEVFlags clearFlags(SCEVFlags Flags,
+                                            SCEVFlags OffFlags) {
     return Flags & ~OffFlags;
   }
-  [[nodiscard]] static bool hasFlags(SCEV::NoWrapFlags Flags,
-                                     SCEV::NoWrapFlags TestFlags) {
+  [[nodiscard]] static bool hasFlags(SCEVFlags Flags, SCEVFlags TestFlags) {
     return TestFlags == maskFlags(Flags, TestFlags);
   };
 
@@ -722,7 +712,7 @@ class ScalarEvolution {
   /// Does not mutate the original instruction. Returns std::nullopt if it could
   /// not deduce more precise flags than the instruction already has, otherwise
   /// returns proven flags.
-  LLVM_ABI std::optional<SCEV::NoWrapFlags>
+  LLVM_ABI std::optional<SCEVFlags>
   getStrengthenedNoWrapFlagsFromBinOp(const OverflowingBinaryOperator *OBO);
 
   /// Notify this ScalarEvolution that \p User directly uses SCEVs in \p Ops.
@@ -750,9 +740,8 @@ class ScalarEvolution {
   LLVM_ABI const SCEV *getTruncateExpr(SCEVUse Op, Type *Ty,
                                        unsigned Depth = 0);
   LLVM_ABI const SCEV *getVScale(Type *Ty);
-  LLVM_ABI const SCEV *
-  getElementCount(Type *Ty, ElementCount EC,
-                  SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
+  LLVM_ABI const SCEV *getElementCount(Type *Ty, ElementCount EC,
+                                       SCEVFlags Flags = SCEV::FlagAny);
   LLVM_ABI const SCEV *getZeroExtendExpr(SCEVUse Op, Type *Ty,
                                          unsigned Depth = 0);
   LLVM_ABI const SCEV *getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
@@ -765,26 +754,26 @@ class ScalarEvolution {
   LLVM_ABI const SCEV *getAnyExtendExpr(SCEVUse Op, Type *Ty);
 
   LLVM_ABI SCEVUse getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
-                              SCEVFlags Flags = {}, unsigned Depth = 0);
-  SCEVUse getAddExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags = {},
+                              SCEVFlagInfo Flags = {}, unsigned Depth = 0);
+  SCEVUse getAddExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlagInfo Flags = {},
                      unsigned Depth = 0) {
     SmallVector<SCEVUse, 2> Ops = {LHS, RHS};
     return getAddExpr(Ops, Flags, Depth);
   }
   SCEVUse getAddExpr(SCEVUse Op0, SCEVUse Op1, SCEVUse Op2,
-                     SCEVFlags Flags = {}, unsigned Depth = 0) {
+                     SCEVFlagInfo Flags = {}, unsigned Depth = 0) {
     SmallVector<SCEVUse, 3> Ops = {Op0, Op1, Op2};
     return getAddExpr(Ops, Flags, Depth);
   }
   LLVM_ABI SCEVUse getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
-                              SCEVFlags Flags = {}, unsigned Depth = 0);
-  SCEVUse getMulExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags = {},
+                              SCEVFlagInfo Flags = {}, unsigned Depth = 0);
+  SCEVUse getMulExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlagInfo Flags = {},
                      unsigned Depth = 0) {
     SmallVector<SCEVUse, 2> Ops = {LHS, RHS};
     return getMulExpr(Ops, Flags, Depth);
   }
   SCEVUse getMulExpr(SCEVUse Op0, SCEVUse Op1, SCEVUse Op2,
-                     SCEVFlags Flags = {}, unsigned Depth = 0) {
+                     SCEVFlagInfo Flags = {}, unsigned Depth = 0) {
     SmallVector<SCEVUse, 3> Ops = {Op0, Op1, Op2};
     return getMulExpr(Ops, Flags, Depth);
   }
@@ -792,11 +781,11 @@ class ScalarEvolution {
   LLVM_ABI const SCEV *getUDivExactExpr(SCEVUse LHS, SCEVUse RHS);
   LLVM_ABI const SCEV *getURemExpr(SCEVUse LHS, SCEVUse RHS);
   LLVM_ABI SCEVUse getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L,
-                                 SCEVFlags Flags);
+                                 SCEVFlagInfo Flags);
   LLVM_ABI SCEVUse getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
-                                 const Loop *L, SCEVFlags Flags);
+                                 const Loop *L, SCEVFlagInfo Flags);
   SCEVUse getAddRecExpr(const SmallVectorImpl<SCEVUse> &Operands, const Loop *L,
-                        SCEVFlags Flags) {
+                        SCEVFlagInfo Flags) {
     SmallVector<SCEVUse, 4> NewOp(Operands.begin(), Operands.end());
     return getAddRecExpr(NewOp, L, Flags);
   }
@@ -869,8 +858,8 @@ class ScalarEvolution {
                                        unsigned FieldNo);
 
   /// Return the SCEV object corresponding to -V.
-  LLVM_ABI const SCEV *
-  getNegativeSCEV(const SCEV *V, SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
+  LLVM_ABI const SCEV *getNegativeSCEV(const SCEV *V,
+                                       SCEVFlags Flags = SCEV::FlagAny);
 
   /// Return the SCEV object corresponding to ~V.
   LLVM_ABI const SCEV *getNotSCEV(const SCEV *V);
@@ -883,7 +872,7 @@ class ScalarEvolution {
   /// explicitly convert the arguments using getPtrToAddrExpr(), for pointer
   /// types that support it.
   LLVM_ABI const SCEV *getMinusSCEV(SCEVUse LHS, SCEVUse RHS,
-                                    SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap,
+                                    SCEVFlags Flags = SCEV::FlagAny,
                                     unsigned Depth = 0);
 
   /// Compute ceil(N / D). N and D are treated as unsigned values.
@@ -1579,7 +1568,7 @@ class ScalarEvolution {
   /// Update no-wrap flags of an AddRec. This may drop the cached info about
   /// this AddRec (such as range info) in case if new flags may potentially
   /// sharpen it.
-  LLVM_ABI void setNoWrapFlags(SCEVAddRecExpr *AddRec, SCEV::NoWrapFlags Flags);
+  LLVM_ABI void setFlags(SCEVAddRecExpr *AddRec, SCEVFlags Flags);
 
   class LoopGuards {
     DenseMap<const SCEV *, const SCEV *> RewriteMap;
@@ -2023,7 +2012,7 @@ class ScalarEvolution {
 
   /// Determines the range for the affine SCEVAddRecExpr {\p Start,+,\p Step},
   /// and whether it may wrap. Helper for \c getRange.
-  std::pair<ConstantRange, SCEV::NoWrapFlags>
+  std::pair<ConstantRange, SCEVFlags>
   getRangeForAffineAR(const SCEV *Start, const SCEV *Step,
                       const APInt &MaxBECount);
   /// If \p S is a SCEVConstant, return the wrapped constant or nullptr
@@ -2406,8 +2395,7 @@ class ScalarEvolution {
                                     SCEVUse RHS);
 
   /// Try to match the Expr as "(L + R)<Flags>".
-  bool splitBinaryAdd(SCEVUse Expr, SCEVUse &L, SCEVUse &R,
-                      SCEV::NoWrapFlags &Flags);
+  bool splitBinaryAdd(SCEVUse Expr, SCEVUse &L, SCEVUse &R, SCEVFlags &Flags);
 
   /// Forget predicated/non-predicated backedge taken counts for the given loop.
   void forgetBackedgeTakenCounts(const Loop *L, bool Predicated);
@@ -2448,11 +2436,11 @@ class ScalarEvolution {
 
   /// Try to prove NSW on \p AR by proving facts about conditions known  on
   /// entry and backedge.
-  SCEV::NoWrapFlags proveNoSignedWrapViaInduction(const SCEVAddRecExpr *AR);
+  SCEVFlags proveNoSignedWrapViaInduction(const SCEVAddRecExpr *AR);
 
   /// Try to prove NUW on \p AR by proving facts about conditions known on
   /// entry and backedge.
-  SCEV::NoWrapFlags proveNoUnsignedWrapViaInduction(const SCEVAddRecExpr *AR);
+  SCEVFlags proveNoUnsignedWrapViaInduction(const SCEVAddRecExpr *AR);
 
   std::optional<MonotonicPredicateType>
   getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS,
@@ -2461,7 +2449,7 @@ class ScalarEvolution {
   /// Return SCEV no-wrap flags that can be proven based on reasoning about
   /// how poison produced from no-wrap flags on this value (e.g. a nuw add)
   /// would trigger undefined behavior on overflow.
-  SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
+  SCEVFlags getNoWrapFlagsFromUB(const Value *V);
 
   /// Return a scope which provides an upper bound on the defining scope of
   /// 'S'. Specifically, return the first instruction in said bounding scope.
@@ -2560,16 +2548,14 @@ class ScalarEvolution {
                          bool Invert = false);
 
   /// Get add expr already created or create a new one.
-  const SCEV *getOrCreateAddExpr(ArrayRef<SCEVUse> Ops,
-                                 SCEV::NoWrapFlags Flags);
+  const SCEV *getOrCreateAddExpr(ArrayRef<SCEVUse> Ops, SCEVFlags Flags);
 
   /// Get mul expr already created or create a new one.
-  const SCEV *getOrCreateMulExpr(ArrayRef<SCEVUse> Ops,
-                                 SCEV::NoWrapFlags Flags);
+  const SCEV *getOrCreateMulExpr(ArrayRef<SCEVUse> Ops, SCEVFlags Flags);
 
   // Get addrec expr already created or create a new one.
   const SCEV *getOrCreateAddRecExpr(ArrayRef<SCEVUse> Ops, const Loop *L,
-                                    SCEV::NoWrapFlags Flags);
+                                    SCEVFlags Flags);
 
   // Get UDiv expression already created or create a new one.
   const SCEV *getOrCreateUDivExpr(SCEVUse LHS, SCEVUse RHS);
@@ -2812,7 +2798,7 @@ template <> inline const SCEV *SCEVUseT<const SCEV *>::getCanonical() const {
 template <typename SCEVPtrT>
 void SCEVUseT<SCEVPtrT>::print(raw_ostream &OS) const {
   getPointer()->print(OS);
-  SCEV::NoWrapFlags Flags = getUseNoWrapFlags();
+  SCEVFlags Flags = getUseFlags();
   if (any(Flags & SCEV::FlagNUW))
     OS << "<u nuw>";
   if (any(Flags & SCEV::FlagNSW))
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
index ace050bd2c2c1..ac1e194968f42 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
@@ -210,19 +210,15 @@ class SCEVNAryExpr : public SCEV {
 
   ArrayRef<SCEVUse> operands() const { return ArrayRef(Operands, NumOperands); }
 
-  NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const {
-    return static_cast<NoWrapFlags>(SubclassData) & Mask;
+  SCEVFlags getFlags(SCEVFlags Mask = NoFlagMask) const {
+    return static_cast<SCEVFlags>(SubclassData) & Mask;
   }
 
-  bool hasNoUnsignedWrap() const {
-    return getNoWrapFlags(FlagNUW) != FlagAnyWrap;
-  }
+  bool hasNoUnsignedWrap() const { return getFlags(FlagNUW) != FlagAny; }
 
-  bool hasNoSignedWrap() const {
-    return getNoWrapFlags(FlagNSW) != FlagAnyWrap;
-  }
+  bool hasNoSignedWrap() const { return getFlags(FlagNSW) != FlagAny; }
 
-  bool hasNoSelfWrap() const { return getNoWrapFlags(FlagNW) != FlagAnyWrap; }
+  bool hasNoSelfWrap() const { return getFlags(FlagNW) != FlagAny; }
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const SCEV *S) {
@@ -251,7 +247,7 @@ class SCEVCommutativeExpr : public SCEVNAryExpr {
   }
 
   /// Set flags for a non-recurrence without clearing previously set flags.
-  void setNoWrapFlags(NoWrapFlags Flags) {
+  void setFlags(SCEVFlags Flags) {
     SubclassData |= static_cast<unsigned short>(Flags);
   }
 };
@@ -350,7 +346,7 @@ class SCEVAddRecExpr : public SCEVNAryExpr {
     if (isAffine())
       return getOperand(1);
     return SE.getAddRecExpr(SmallVector<SCEVUse, 3>(operands().drop_front()),
-                            getLoop(), FlagAnyWrap);
+                            getLoop(), FlagAny);
   }
 
   /// Return true if this represents an expression A + B*x where A
@@ -369,7 +365,7 @@ class SCEVAddRecExpr : public SCEVNAryExpr {
   /// Set flags for a recurrence without clearing any previously set flags.
   /// For AddRec, either NUW or NSW implies NW. Keep track of this fact here
   /// to make it easier to propagate flags.
-  void setNoWrapFlags(NoWrapFlags Flags) {
+  void setFlags(SCEVFlags Flags) {
     if (any(Flags & (FlagNUW | FlagNSW)))
       Flags = ScalarEvolution::setFlags(Flags, FlagNW);
     SubclassData |= static_cast<unsigned short>(Flags);
@@ -384,8 +380,7 @@ class SCEVAddRecExpr : public SCEVNAryExpr {
   /// number. Takes an explicit list of operands to represent an AddRec.
   LLVM_ABI static SCEVUse
   evaluateAtIteration(ArrayRef<SCEVUse> Operands, const SCEV *It,
-                      ScalarEvolution &SE,
-                      SCEV::NoWrapFlags UseFlags = SCEV::FlagAnyWrap);
+                      ScalarEvolution &SE, SCEVFlags UseFlags = SCEV::FlagAny);
 
   /// Return the value of this recurrences when its loop exits, i.e. its value
   /// at the loop's exact backedge-taken count, or SCEVCouldNotCompute if that
@@ -427,7 +422,7 @@ class SCEVMinMaxExpr : public SCEVCommutativeExpr {
       : SCEVCommutativeExpr(ID, T, O, N, O[0]->getType()) {
     assert(isMinMaxType(T));
     // Min and max never overflow
-    setNoWrapFlags(FlagNUW | FlagNSW);
+    setFlags(FlagNUW | FlagNSW);
   }
 
 public:
@@ -511,7 +506,7 @@ class SCEVSequentialMinMaxExpr : public SCEVNAryExpr {
   }
 
   /// Set flags for a non-recurrence without clearing previously set flags.
-  void setNoWrapFlags(NoWrapFlags Flags) {
+  void setFlags(SCEVFlags Flags) {
     SubclassData |= static_cast<unsigned short>(Flags);
   }
 
@@ -522,7 +517,7 @@ class SCEVSequentialMinMaxExpr : public SCEVNAryExpr {
       : SCEVNAryExpr(ID, T, O, N, O[0]->getType()) {
     assert(isSequentialMinMaxType(T));
     // Min and max never overflow
-    setNoWrapFlags(FlagNUW | FlagNSW);
+    setFlags(FlagNUW | FlagNSW);
   }
 
 public:
@@ -882,9 +877,9 @@ class SCEVRewriteVisitor : public SCEVVisitor<SC, const SCEV *> {
       Operands.push_back(((SC *)this)->visit(Op));
       Changed |= Op != Operands.back();
     }
-    return !Changed ? Expr
-                    : SE.getAddRecExpr(Operands, Expr->getLoop(),
-                                       Expr->getNoWrapFlags());
+    return !Changed
+               ? Expr
+               : SE.getAddRecExpr(Operands, Expr->getLoop(), Expr->getFlags());
   }
 
   const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
@@ -995,7 +990,7 @@ class SCEVLoopAddRecRewriter
     const Loop *L = Expr->getLoop();
     auto It = Map.find(L);
     if (It == Map.end())
-      return SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags());
+      return SE.getAddRecExpr(Operands, L, Expr->getFlags());
 
     return SCEVAddRecExpr::evaluateAtIteration(Operands, It->second, SE);
   }
@@ -1005,24 +1000,22 @@ class SCEVLoopAddRecRewriter
 };
 
 template <typename SCEVPtrT>
-inline SCEVUseT<SCEVPtrT>::SCEVUseT(SCEVPtrT S, SCEVNoWrapFlags Flags)
-    : Base(S, 0) {
+inline SCEVUseT<SCEVPtrT>::SCEVUseT(SCEVPtrT S, SCEVFlags Flags) : Base(S, 0) {
   if (any(Flags)) {
     assert((isa<SCEVAddExpr, SCEVMulExpr, SCEVAddRecExpr>(S)) &&
            "use flags require an expression that can carry no-wrap flags");
     // Drop flags already present on S.
-    Flags &= ~cast<SCEVNAryExpr>(S)->getNoWrapFlags();
+    Flags &= ~cast<SCEVNAryExpr>(S)->getFlags();
   }
   Base::setInt(static_cast<unsigned>(Flags) >> 1);
 }
 
 template <typename SCEVPtrT>
-inline SCEVNoWrapFlags
-SCEVUseT<SCEVPtrT>::getNoWrapFlags(SCEVNoWrapFlags Mask) const {
-  SCEVNoWrapFlags Flags = SCEVNoWrapFlags::FlagAnyWrap;
+inline SCEVFlags SCEVUseT<SCEVPtrT>::getFlags(SCEVFlags Mask) const {
+  SCEVFlags Flags = SCEVFlags::FlagAny;
   if (auto *NAry = dyn_cast<SCEVNAryExpr>(Base::getPointer()))
-    Flags = NAry->getNoWrapFlags();
-  return (Flags | getUseNoWrapFlags()) & Mask;
+    Flags = NAry->getFlags();
+  return (Flags | getUseFlags()) & Mask;
 }
 
 } // end namespace llvm
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
index 0ed08989e483b..e80582fe89c06 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
@@ -200,8 +200,7 @@ m_scev_Trunc(const Op0_t &Op0) {
 
 /// Match a binary SCEV.
 template <typename SCEVTy, typename Op0_t, typename Op1_t,
-          SCEV::NoWrapFlags WrapFlags = SCEV::FlagAnyWrap,
-          bool Commutable = false>
+          SCEVFlags WrapFlags = SCEV::FlagAny, bool Commutable = false>
 struct SCEVBinaryExpr_match {
   Op0_t Op0;
   Op1_t Op1;
@@ -210,7 +209,7 @@ struct SCEVBinaryExpr_match {
 
   bool match(const SCEV *S) const {
     if (auto WrappingS = dyn_cast<SCEVNAryExpr>(S))
-      if (WrappingS->getNoWrapFlags(WrapFlags) != WrapFlags)
+      if (WrappingS->getFlags(WrapFlags) != WrapFlags)
         return false;
 
     auto *E = dyn_cast<SCEVTy>(S);
@@ -223,8 +222,7 @@ struct SCEVBinaryExpr_match {
 };
 
 template <typename SCEVTy, typename Op0_t, typename Op1_t,
-          SCEV::NoWrapFlags WrapFlags = SCEV::FlagAnyWrap,
-          bool Commutable = false>
+          SCEVFlags WrapFlags = SCEV::FlagAny, bool Commutable = false>
 inline SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable>
 m_scev_Binary(const Op0_t &Op0, const Op1_t &Op1) {
   return SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable>(Op0,
@@ -244,10 +242,10 @@ m_scev_Mul(const Op0_t &Op0, const Op1_t &Op1) {
 }
 
 template <typename Op0_t, typename Op1_t>
-inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>
+inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAny, true>
 m_scev_c_Mul(const Op0_t &Op0, const Op1_t &Op1) {
-  return m_scev_Binary<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>(Op0,
-                                                                           Op1);
+  return m_scev_Binary<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAny, true>(Op0,
+                                                                       Op1);
 }
 
 template <typename Op0_t, typename Op1_t>
@@ -264,17 +262,17 @@ m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) {
 }
 
 template <typename Op0_t, typename Op1_t>
-inline SCEVBinaryExpr_match<SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>
+inline SCEVBinaryExpr_match<SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagAny, true>
 m_scev_SMax(const Op0_t &Op0, const Op1_t &Op1) {
-  return m_scev_Binary<SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>(
-      Op0, Op1);
+  return m_scev_Binary<SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagAny, true>(Op0,
+                                                                        Op1);
 }
 
 template <typename Op0_t, typename Op1_t>
-inline SCEVBinaryExpr_match<SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>
+inline SCEVBinaryExpr_match<SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagAny, true>
 m_scev_UMax(const Op0_t &Op0, const Op1_t &Op1) {
-  return m_scev_Binary<SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>(
-      Op0, Op1);
+  return m_scev_Binary<SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagAny, true>(Op0,
+                                                                        Op1);
 }
 
 template <typename Op0_t, typename Op1_t>
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index c98c0cb52fa9c..88a9588482227 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -470,7 +470,7 @@ class SCEVExpander : public SCEVUseVisitor<SCEVExpander, Value *> {
   /// avoid inserting an obviously redundant operation, and hoisting to an
   /// outer loop when the opportunity is there and it is safe.
   Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS,
-                     SCEV::NoWrapFlags Flags, bool IsSafeToHoist);
+                     SCEVFlags Flags, bool IsSafeToHoist);
 
   /// We want to cast \p V. What would be the best place for such a cast?
   BasicBlock::iterator GetOptimalInsertionPointForCastOf(Value *V) const;
@@ -487,7 +487,7 @@ class SCEVExpander : public SCEVUseVisitor<SCEVExpander, Value *> {
 
   /// Expand a SCEVAddExpr with a pointer type into a GEP instead of using
   /// ptrtoint+arithmetic+inttoptr.
-  Value *expandAddToGEP(const SCEV *Op, Value *V, SCEV::NoWrapFlags Flags);
+  Value *expandAddToGEP(const SCEV *Op, Value *V, SCEVFlags Flags);
 
   /// Find a previous Value in ExprValueMap for expand.
   /// DropPoisonGeneratingInsts is populated with instructions for which
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index d79624e071f3e..7f64fa85124af 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1765,7 +1765,7 @@ bool ConditionalInductionDescriptor::isConditionalInductionPHI(
   Value *Start = PN->getIncomingValueForBlock(Preheader);
   const SCEV *StartSCEV = SE.getSCEV(Start);
 
-  SCEV::NoWrapFlags NoWrapFlags = SCEV::FlagAnyWrap;
+  SCEVFlags NoWrapFlags = SCEV::FlagAny;
   if (auto *GEP = dyn_cast<GEPOperator>(StepInst)) {
     // With NUSW, we can add NUW if the step is non-negative. We can't add NSW
     // as the base address is unsigned.
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 437d25b3d56ed..4ddd0c18cd843 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1105,7 +1105,7 @@ isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR, Value *Ptr,
          std::optional<int64_t> Stride = std::nullopt,
          SmallVectorImpl<const SCEVPredicate *> *Predicates = nullptr) {
   // FIXME: This should probably only return true for NUW.
-  if (any(AR->getNoWrapFlags(SCEV::NoWrapMask)))
+  if (any(AR->getFlags(SCEV::NoFlagMask)))
     return true;
 
   if (Ptr && PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
index caf1b1a655632..e639ceba22329 100644
--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
@@ -415,9 +415,9 @@ bool IndexedReference::delinearize(const LoopInfo &LI) {
       const SCEV *StepRec = AccessFnAR ? AccessFnAR->getStepRecurrence(SE) : nullptr;
 
       if (StepRec && SE.isKnownNegative(StepRec))
-        AccessFn = SE.getAddRecExpr(
-            AccessFnAR->getStart(), SE.getNegativeSCEV(StepRec),
-            AccessFnAR->getLoop(), SCEV::NoWrapFlags::FlagAnyWrap);
+        AccessFn = SE.getAddRecExpr(AccessFnAR->getStart(),
+                                    SE.getNegativeSCEV(StepRec),
+                                    AccessFnAR->getLoop(), SCEVFlags::FlagAny);
       const SCEV *Div = SE.getUDivExactExpr(AccessFn, ElemSize);
       Subscripts.push_back(Div);
       Sizes.push_back(ElemSize);
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index f06ef51c25101..fe55980d8abde 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -502,7 +502,7 @@ const SCEV *ScalarEvolution::getVScale(Type *Ty) {
 }
 
 const SCEV *ScalarEvolution::getElementCount(Type *Ty, ElementCount EC,
-                                             SCEV::NoWrapFlags Flags) {
+                                             SCEVFlags Flags) {
   const SCEV *Res = getConstant(Ty, EC.getKnownMinValue());
   if (EC.isScalable())
     Res = getMulExpr(Res, getVScale(Ty), Flags);
@@ -985,9 +985,9 @@ const SCEV *SCEVAddRecExpr::evaluateAtIteration(const SCEV *It,
 
 SCEVUse SCEVAddRecExpr::evaluateAtIteration(ArrayRef<SCEVUse> Operands,
                                             const SCEV *It, ScalarEvolution &SE,
-                                            SCEV::NoWrapFlags UseFlags) {
+                                            SCEVFlags UseFlags) {
   assert(Operands.size() > 0);
-  assert((Operands.size() == 2 || UseFlags == SCEV::FlagAnyWrap) &&
+  assert((Operands.size() == 2 || UseFlags == SCEV::FlagAny) &&
          "use-specific flags only supported for affine AddRecs");
   SCEVUse Result = Operands[0].getPointer();
   for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
@@ -999,8 +999,8 @@ SCEVUse SCEVAddRecExpr::evaluateAtIteration(ArrayRef<SCEVUse> Operands,
       return Coeff;
 
     SCEVUse Mul = SE.getMulExpr(Operands[i].getPointer(), Coeff,
-                                {SCEV::FlagAnyWrap, UseFlags});
-    Result = SE.getAddExpr(Result, Mul, {SCEV::FlagAnyWrap, UseFlags});
+                                {SCEV::FlagAny, UseFlags});
+    Result = SE.getAddExpr(Result, Mul, {SCEV::FlagAny, UseFlags});
   }
   return Result;
 }
@@ -1012,8 +1012,8 @@ SCEVUse SCEVAddRecExpr::getExitValue(ScalarEvolution &SE) const {
   // The loop reaches iteration BTC, so the value this recurrence computes there
   // is the value it had, and that did not wrap.
   return evaluateAtIteration(operands(), BTC, SE,
-                             isAffine() ? getNoWrapFlags(SCEV::FlagNUW)
-                                        : SCEV::FlagAnyWrap);
+                             isAffine() ? getFlags(SCEV::FlagNUW)
+                                        : SCEV::FlagAny);
 }
 
 //===----------------------------------------------------------------------===//
@@ -1062,7 +1062,7 @@ class SCEVCastSinkingRewriter
       Operands.push_back(visit(Op.getPointer()));
       Changed |= Op.getPointer() != Operands.back();
     }
-    return !Changed ? Expr : SE.getAddExpr(Operands, Expr->getNoWrapFlags());
+    return !Changed ? Expr : SE.getAddExpr(Operands, Expr->getFlags());
   }
 
   const SCEV *visitUnknown(const SCEVUnknown *Expr) {
@@ -1189,7 +1189,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(SCEVUse Op, Type *Ty,
     SmallVector<SCEVUse, 4> Operands;
     for (const SCEV *Op : AddRec->operands())
       Operands.push_back(getTruncateExpr(Op, Ty, Depth + 1));
-    return getAddRecExpr(Operands, AddRec->getLoop(), SCEV::FlagAnyWrap);
+    return getAddRecExpr(Operands, AddRec->getLoop(), SCEV::FlagAny);
   }
 
   // Return zero if truncating to known zeros.
@@ -1252,7 +1252,7 @@ struct ExtendOpTraitsBase {
 template <typename ExtendOp> struct ExtendOpTraits {
   // Members present:
   //
-  // static const SCEV::NoWrapFlags WrapType;
+  // static const SCEVFlags WrapType;
   //
   // static const ExtendOpTraitsBase::GetExtendExprTy GetExtendExpr;
   //
@@ -1263,7 +1263,7 @@ template <typename ExtendOp> struct ExtendOpTraits {
 
 template <>
 struct ExtendOpTraits<SCEVSignExtendExpr> : public ExtendOpTraitsBase {
-  static const SCEV::NoWrapFlags WrapType = SCEV::FlagNSW;
+  static const SCEVFlags WrapType = SCEV::FlagNSW;
 
   static const GetExtendExprTy GetExtendExpr;
 
@@ -1279,7 +1279,7 @@ const ExtendOpTraitsBase::GetExtendExprTy ExtendOpTraits<
 
 template <>
 struct ExtendOpTraits<SCEVZeroExtendExpr> : public ExtendOpTraitsBase {
-  static const SCEV::NoWrapFlags WrapType = SCEV::FlagNUW;
+  static const SCEVFlags WrapType = SCEV::FlagNUW;
 
   static const GetExtendExprTy GetExtendExpr;
 
@@ -1336,17 +1336,17 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR,
 
   // 1. NSW/NUW flags on the step increment.
   auto PreStartFlags =
-    ScalarEvolution::maskFlags(SA->getNoWrapFlags(), SCEV::FlagNUW);
+      ScalarEvolution::maskFlags(SA->getFlags(), SCEV::FlagNUW);
   const SCEV *PreStart = SE->getAddExpr(DiffOps, PreStartFlags);
   const SCEVAddRecExpr *PreAR = dyn_cast<SCEVAddRecExpr>(
-      SE->getAddRecExpr(PreStart, Step, L, SCEV::FlagAnyWrap));
+      SE->getAddRecExpr(PreStart, Step, L, SCEV::FlagAny));
 
   // "{S,+,X} is <nsw>/<nuw>" and "the backedge is taken at least once" implies
   // "S+X does not sign/unsign-overflow".
   //
 
   const SCEV *BECount = SE->getBackedgeTakenCount(L);
-  if (PreAR && any(PreAR->getNoWrapFlags(WrapType)) &&
+  if (PreAR && any(PreAR->getFlags(WrapType)) &&
       !isa<SCEVCouldNotCompute>(BECount) && SE->isKnownPositive(BECount))
     return PreStart;
 
@@ -1357,11 +1357,11 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR,
       SE->getAddExpr((SE->*GetExtendExpr)(PreStart, WideTy, Depth),
                      (SE->*GetExtendExpr)(Step, WideTy, Depth));
   if ((SE->*GetExtendExpr)(Start, WideTy, Depth) == OperandExtendedStart) {
-    if (PreAR && any(AR->getNoWrapFlags(WrapType))) {
+    if (PreAR && any(AR->getFlags(WrapType))) {
       // If we know `AR` == {`PreStart`+`Step`,+,`Step`} is `WrapType` (FlagNSW
       // or FlagNUW) and that `PreStart` + `Step` is `WrapType` too, then
       // `PreAR` == {`PreStart`,+,`Step`} is also `WrapType`.  Cache this fact.
-      SE->setNoWrapFlags(const_cast<SCEVAddRecExpr *>(PreAR), WrapType);
+      SE->setFlags(const_cast<SCEVAddRecExpr *>(PreAR), WrapType);
     }
     return PreStart;
   }
@@ -1456,7 +1456,7 @@ bool ScalarEvolution::proveNoWrapByVaryingStart(const SCEV *Start,
 
     // Give up if we don't already have the add recurrence we need because
     // actually constructing an add recurrence is relatively expensive.
-    if (PreAR && any(PreAR->getNoWrapFlags(WrapType))) { // proves (2)
+    if (PreAR && any(PreAR->getFlags(WrapType))) { // proves (2)
       const SCEV *DeltaS = getConstant(StartC->getType(), Delta);
       ICmpInst::Predicate Pred = ICmpInst::BAD_ICMP_PREDICATE;
       const SCEV *Limit = ExtendOpTraits<ExtendOpTy>::getOverflowLimitForStep(
@@ -1572,7 +1572,7 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
     if (AR->hasNoUnsignedWrap()) {
       Start = getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
       Step = getZeroExtendExpr(Step, Ty, Depth + 1);
-      return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+      return getAddRecExpr(Start, Step, L, AR->getFlags());
     }
   }
 
@@ -1639,10 +1639,10 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
         Type *WideTy = IntegerType::get(getContext(), BitWidth * 2);
         // Check whether Start+Step*MaxBECount has no unsigned overflow.
         const SCEV *ZMul =
-            getMulExpr(CastedMaxBECount, Step, SCEV::FlagAnyWrap, Depth + 1);
-        const SCEV *ZAdd = getZeroExtendExpr(
-            getAddExpr(Start, ZMul, SCEV::FlagAnyWrap, Depth + 1), WideTy,
-            Depth + 1);
+            getMulExpr(CastedMaxBECount, Step, SCEV::FlagAny, Depth + 1);
+        const SCEV *ZAdd =
+            getZeroExtendExpr(getAddExpr(Start, ZMul, SCEV::FlagAny, Depth + 1),
+                              WideTy, Depth + 1);
         const SCEV *WideStart = getZeroExtendExpr(Start, WideTy, Depth + 1);
         const SCEV *WideMaxBECount =
             getZeroExtendExpr(CastedMaxBECount, WideTy, Depth + 1);
@@ -1650,16 +1650,16 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
             getAddExpr(WideStart,
                        getMulExpr(WideMaxBECount,
                                   getZeroExtendExpr(Step, WideTy, Depth + 1),
-                                  SCEV::FlagAnyWrap, Depth + 1),
-                       SCEV::FlagAnyWrap, Depth + 1);
+                                  SCEV::FlagAny, Depth + 1),
+                       SCEV::FlagAny, Depth + 1);
         if (ZAdd == OperandExtendedAdd) {
           // Cache knowledge of AR NUW, which is propagated to this AddRec.
-          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
+          setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
           // Return the expression with the addrec on the outside.
           Start =
               getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
           Step = getZeroExtendExpr(Step, Ty, Depth + 1);
-          return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+          return getAddRecExpr(Start, Step, L, AR->getFlags());
         }
         // Similar to above, only this time treat the step value as signed.
         // This covers loops that count down.
@@ -1667,17 +1667,17 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
             getAddExpr(WideStart,
                        getMulExpr(WideMaxBECount,
                                   getSignExtendExpr(Step, WideTy, Depth + 1),
-                                  SCEV::FlagAnyWrap, Depth + 1),
-                       SCEV::FlagAnyWrap, Depth + 1);
+                                  SCEV::FlagAny, Depth + 1),
+                       SCEV::FlagAny, Depth + 1);
         if (ZAdd == OperandExtendedAdd) {
           // Cache knowledge of AR NW, which is propagated to this AddRec.
           // Negative step causes unsigned wrap, but it still can't self-wrap.
-          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
+          setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
           // Return the expression with the addrec on the outside.
           Start =
               getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
           Step = getSignExtendExpr(Step, Ty, Depth + 1);
-          return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+          return getAddRecExpr(Start, Step, L, AR->getFlags());
         }
       }
     }
@@ -1693,7 +1693,7 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
         !AC.assumptions().empty()) {
 
       auto NewFlags = proveNoUnsignedWrapViaInduction(AR);
-      setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), NewFlags);
+      setFlags(const_cast<SCEVAddRecExpr *>(AR), NewFlags);
       if (AR->hasNoUnsignedWrap()) {
         // Same as nuw case above - duplicated here to avoid a compile time
         // issue.  It's not clear that the order of checks does matter, but
@@ -1702,7 +1702,7 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
         Start =
             getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
         Step = getZeroExtendExpr(Step, Ty, Depth + 1);
-        return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+        return getAddRecExpr(Start, Step, L, AR->getFlags());
       }
 
       // For a negative step, we can extend the operands iff doing so only
@@ -1715,12 +1715,12 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
           // Cache knowledge of AR NW, which is propagated to this
           // AddRec.  Negative step causes unsigned wrap, but it
           // still can't self-wrap.
-          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
+          setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
           // Return the expression with the addrec on the outside.
           Start =
               getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
           Step = getSignExtendExpr(Step, Ty, Depth + 1);
-          return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+          return getAddRecExpr(Start, Step, L, AR->getFlags());
         }
       }
     }
@@ -1734,7 +1734,7 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
       if (D != 0) {
         const SCEV *SZExtD = getZeroExtendExpr(getConstant(D), Ty, Depth);
         const SCEV *SResidual =
-            getAddRecExpr(getConstant(C - D), Step, L, AR->getNoWrapFlags());
+            getAddRecExpr(getConstant(C - D), Step, L, AR->getFlags());
         const SCEV *SZExtR = getZeroExtendExpr(SResidual, Ty, Depth + 1);
         return getAddExpr(SZExtD, SZExtR, SCEV::FlagNSW | SCEV::FlagNUW,
                           Depth + 1);
@@ -1742,10 +1742,10 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
     }
 
     if (proveNoWrapByVaryingStart<SCEVZeroExtendExpr>(Start, Step, L)) {
-      setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
+      setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
       Start = getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1);
       Step = getZeroExtendExpr(Step, Ty, Depth + 1);
-      return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+      return getAddRecExpr(Start, Step, L, AR->getFlags());
     }
   }
 
@@ -1801,7 +1801,7 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
       if (D != 0) {
         const SCEV *SZExtD = getZeroExtendExpr(getConstant(D), Ty, Depth);
         const SCEV *SResidual =
-            getAddExpr(getConstant(-D), SA, SCEV::FlagAnyWrap, Depth);
+            getAddExpr(getConstant(-D), SA, SCEV::FlagAny, Depth);
         const SCEV *SZExtR = getZeroExtendExpr(SResidual, Ty, Depth + 1);
         return getAddExpr(SZExtD, SZExtR, (SCEV::FlagNSW | SCEV::FlagNUW),
                           Depth + 1);
@@ -1929,7 +1929,7 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
     if (AR->hasNoSignedWrap()) {
       Start = getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1);
       Step = getSignExtendExpr(Step, Ty, Depth + 1);
-      return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+      return getAddRecExpr(Start, Step, L, AR->getFlags());
     }
   }
 
@@ -1990,7 +1990,7 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
       if (D != 0) {
         const SCEV *SSExtD = getSignExtendExpr(getConstant(D), Ty, Depth);
         const SCEV *SResidual =
-            getAddExpr(getConstant(-D), SA, SCEV::FlagAnyWrap, Depth);
+            getAddExpr(getConstant(-D), SA, SCEV::FlagAny, Depth);
         const SCEV *SSExtR = getSignExtendExpr(SResidual, Ty, Depth + 1);
         return getAddExpr(SSExtD, SSExtR, (SCEV::FlagNSW | SCEV::FlagNUW),
                           Depth + 1);
@@ -2030,10 +2030,10 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
         Type *WideTy = IntegerType::get(getContext(), BitWidth * 2);
         // Check whether Start+Step*MaxBECount has no signed overflow.
         const SCEV *SMul =
-            getMulExpr(CastedMaxBECount, Step, SCEV::FlagAnyWrap, Depth + 1);
-        const SCEV *SAdd = getSignExtendExpr(
-            getAddExpr(Start, SMul, SCEV::FlagAnyWrap, Depth + 1), WideTy,
-            Depth + 1);
+            getMulExpr(CastedMaxBECount, Step, SCEV::FlagAny, Depth + 1);
+        const SCEV *SAdd =
+            getSignExtendExpr(getAddExpr(Start, SMul, SCEV::FlagAny, Depth + 1),
+                              WideTy, Depth + 1);
         const SCEV *WideStart = getSignExtendExpr(Start, WideTy, Depth + 1);
         const SCEV *WideMaxBECount =
             getZeroExtendExpr(CastedMaxBECount, WideTy, Depth + 1);
@@ -2041,16 +2041,16 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
             getAddExpr(WideStart,
                        getMulExpr(WideMaxBECount,
                                   getSignExtendExpr(Step, WideTy, Depth + 1),
-                                  SCEV::FlagAnyWrap, Depth + 1),
-                       SCEV::FlagAnyWrap, Depth + 1);
+                                  SCEV::FlagAny, Depth + 1),
+                       SCEV::FlagAny, Depth + 1);
         if (SAdd == OperandExtendedAdd) {
           // Cache knowledge of AR NSW, which is propagated to this AddRec.
-          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
+          setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
           // Return the expression with the addrec on the outside.
           Start =
               getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1);
           Step = getSignExtendExpr(Step, Ty, Depth + 1);
-          return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+          return getAddRecExpr(Start, Step, L, AR->getFlags());
         }
         // Similar to above, only this time treat the step value as unsigned.
         // This covers loops that count up with an unsigned step.
@@ -2058,8 +2058,8 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
             getAddExpr(WideStart,
                        getMulExpr(WideMaxBECount,
                                   getZeroExtendExpr(Step, WideTy, Depth + 1),
-                                  SCEV::FlagAnyWrap, Depth + 1),
-                       SCEV::FlagAnyWrap, Depth + 1);
+                                  SCEV::FlagAny, Depth + 1),
+                       SCEV::FlagAny, Depth + 1);
         if (SAdd == OperandExtendedAdd) {
           // If AR wraps around then
           //
@@ -2069,19 +2069,19 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
           // Thus (AR is not NW => SAdd != OperandExtendedAdd) <=>
           // (SAdd == OperandExtendedAdd => AR is NW)
 
-          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
+          setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
 
           // Return the expression with the addrec on the outside.
           Start =
               getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1);
           Step = getZeroExtendExpr(Step, Ty, Depth + 1);
-          return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+          return getAddRecExpr(Start, Step, L, AR->getFlags());
         }
       }
     }
 
     auto NewFlags = proveNoSignedWrapViaInduction(AR);
-    setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), NewFlags);
+    setFlags(const_cast<SCEVAddRecExpr *>(AR), NewFlags);
     if (AR->hasNoSignedWrap()) {
       // Same as nsw case above - duplicated here to avoid a compile time
       // issue.  It's not clear that the order of checks does matter, but
@@ -2089,7 +2089,7 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
       // reverted.  Be conservative for the moment.
       Start = getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1);
       Step = getSignExtendExpr(Step, Ty, Depth + 1);
-      return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+      return getAddRecExpr(Start, Step, L, AR->getFlags());
     }
 
     // sext({C,+,Step}) --> (sext(D) + sext({C-D,+,Step}))<nuw><nsw>
@@ -2101,7 +2101,7 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
       if (D != 0) {
         const SCEV *SSExtD = getSignExtendExpr(getConstant(D), Ty, Depth);
         const SCEV *SResidual =
-            getAddRecExpr(getConstant(C - D), Step, L, AR->getNoWrapFlags());
+            getAddRecExpr(getConstant(C - D), Step, L, AR->getFlags());
         const SCEV *SSExtR = getSignExtendExpr(SResidual, Ty, Depth + 1);
         return getAddExpr(SSExtD, SSExtR, (SCEV::FlagNSW | SCEV::FlagNUW),
                           Depth + 1);
@@ -2109,10 +2109,10 @@ const SCEV *ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
     }
 
     if (proveNoWrapByVaryingStart<SCEVSignExtendExpr>(Start, Step, L)) {
-      setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
+      setFlags(const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
       Start = getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1);
       Step = getSignExtendExpr(Step, Ty, Depth + 1);
-      return getAddRecExpr(Start, Step, L, AR->getNoWrapFlags());
+      return getAddRecExpr(Start, Step, L, AR->getFlags());
     }
   }
 
@@ -2368,14 +2368,13 @@ bool ScalarEvolution::willNotOverflow(Instruction::BinaryOps BinOp, bool Signed,
   }
 }
 
-std::optional<SCEV::NoWrapFlags>
-ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
+std::optional<SCEVFlags> ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
     const OverflowingBinaryOperator *OBO) {
   // It cannot be done any better.
   if (OBO->hasNoUnsignedWrap() && OBO->hasNoSignedWrap())
     return std::nullopt;
 
-  SCEV::NoWrapFlags Flags = SCEV::NoWrapFlags::FlagAnyWrap;
+  SCEVFlags Flags = SCEVFlags::FlagAny;
 
   if (OBO->hasNoUnsignedWrap())
     Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
@@ -2427,10 +2426,8 @@ ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
 // We're trying to construct a SCEV of type `Type' with `Ops' as operands and
 // `OldFlags' as can't-wrap behavior.  Infer a more aggressive set of
 // can't-overflow flags for the operation if possible.
-static SCEV::NoWrapFlags StrengthenNoWrapFlags(ScalarEvolution *SE,
-                                               SCEVTypes Type,
-                                               ArrayRef<SCEVUse> Ops,
-                                               SCEV::NoWrapFlags Flags) {
+static SCEVFlags StrengthenNoWrapFlags(ScalarEvolution *SE, SCEVTypes Type,
+                                       ArrayRef<SCEVUse> Ops, SCEVFlags Flags) {
   using namespace std::placeholders;
 
   using OBO = OverflowingBinaryOperator;
@@ -2440,8 +2437,8 @@ static SCEV::NoWrapFlags StrengthenNoWrapFlags(ScalarEvolution *SE,
   (void)CanAnalyze;
   assert(CanAnalyze && "don't call from other places!");
 
-  SCEV::NoWrapFlags SignOrUnsignMask = SCEV::FlagNUW | SCEV::FlagNSW;
-  SCEV::NoWrapFlags SignOrUnsignWrap =
+  SCEVFlags SignOrUnsignMask = SCEV::FlagNUW | SCEV::FlagNSW;
+  SCEVFlags SignOrUnsignWrap =
       ScalarEvolution::maskFlags(Flags, SignOrUnsignMask);
 
   // If FlagNSW is true and all the operands are non-negative, infer FlagNUW.
@@ -2515,10 +2512,10 @@ bool ScalarEvolution::isAvailableAtLoopEntry(const SCEV *S, const Loop *L) {
 
 /// Get a canonical add expression, or something simpler if possible.
 SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
-                                    SCEVFlags Flags, unsigned Depth) {
-  SCEV::NoWrapFlags OrigFlags = Flags.ExprFlags;
-  SCEV::NoWrapFlags UseFlags = Flags.UseFlags;
-  assert(!(OrigFlags & ~(SCEV::FlagNUW | SCEV::FlagNSW)) &&
+                                    SCEVFlagInfo Flags, unsigned Depth) {
+  SCEVFlags ExprFlags, UseFlags;
+  std::tie(ExprFlags, UseFlags) = Flags;
+  assert(!(ExprFlags & ~(SCEV::FlagNUW | SCEV::FlagNSW)) &&
          "only nuw or nsw allowed");
   assert(!(UseFlags & ~(SCEV::FlagNUW | SCEV::FlagNSW)) &&
          "only nuw or nsw allowed");
@@ -2551,8 +2548,8 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
   unsigned Idx = isa<SCEVConstant>(Ops[0]) ? 1 : 0;
 
   // Delay expensive flag strengthening until necessary.
-  auto ComputeFlags = [this, OrigFlags](ArrayRef<SCEVUse> Ops) {
-    return StrengthenNoWrapFlags(this, scAddExpr, Ops, OrigFlags);
+  auto ComputeFlags = [this, ExprFlags](ArrayRef<SCEVUse> Ops) {
+    return StrengthenNoWrapFlags(this, scAddExpr, Ops, ExprFlags);
   };
 
   // Limit recursion calls depth.
@@ -2562,8 +2559,8 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
   if (SCEV *S = findExistingSCEVInCache(scAddExpr, Ops)) {
     // Don't strengthen flags if we have no new information.
     SCEVAddExpr *Add = static_cast<SCEVAddExpr *>(S);
-    if (Add->getNoWrapFlags(OrigFlags) != OrigFlags)
-      Add->setNoWrapFlags(ComputeFlags(Ops));
+    if (Add->getFlags(ExprFlags) != ExprFlags)
+      Add->setFlags(ComputeFlags(Ops));
     return {S, UseFlags};
   }
 
@@ -2580,7 +2577,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
         ++Count;
       // Merge the values into a multiply.
       SCEVUse Scale = getConstant(Ty, Count);
-      const SCEV *Mul = getMulExpr(Scale, Ops[i], SCEV::FlagAnyWrap, Depth + 1);
+      const SCEV *Mul = getMulExpr(Scale, Ops[i], SCEV::FlagAny, Depth + 1);
       if (Ops.size() == Count)
         return Mul;
       Ops[i] = Mul;
@@ -2589,7 +2586,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       FoundMatch = true;
     }
   if (FoundMatch)
-    return getAddExpr(Ops, OrigFlags, Depth + 1);
+    return getAddExpr(Ops, ExprFlags, Depth + 1);
 
   // Check for truncates. If all the operands are truncated from the same
   // type, see if factoring out the truncate would permit the result to be
@@ -2641,7 +2638,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
           }
         }
         if (Ok)
-          LargeOps.push_back(getMulExpr(LargeMulOps, SCEV::FlagAnyWrap, Depth + 1));
+          LargeOps.push_back(getMulExpr(LargeMulOps, SCEV::FlagAny, Depth + 1));
       } else {
         Ok = false;
         break;
@@ -2649,7 +2646,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
     }
     if (Ok) {
       // Evaluate the expression in the larger type.
-      const SCEV *Fold = getAddExpr(LargeOps, SCEV::FlagAnyWrap, Depth + 1);
+      const SCEV *Fold = getAddExpr(LargeOps, SCEV::FlagAny, Depth + 1);
       // If it folds to something simple, use it. Otherwise, don't.
       if (isa<SCEVConstant>(Fold) || isa<SCEVUnknown>(Fold))
         return getTruncateExpr(Fold, Ty);
@@ -2667,10 +2664,10 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
     if (AddExpr && C && isa<SCEVConstant>(AddExpr->getOperand(0))) {
       auto C1 = cast<SCEVConstant>(AddExpr->getOperand(0))->getAPInt();
       auto C2 = C->getAPInt();
-      SCEV::NoWrapFlags PreservedFlags = SCEV::FlagAnyWrap;
+      SCEVFlags PreservedFlags = SCEV::FlagAny;
 
       APInt ConstAdd = C1 + C2;
-      auto AddFlags = AddExpr->getNoWrapFlags();
+      auto AddFlags = AddExpr->getFlags();
       // Adding a smaller constant is NUW if the original AddExpr was NUW.
       if (ScalarEvolution::hasFlags(AddFlags, SCEV::FlagNUW) &&
           ConstAdd.ule(C1)) {
@@ -2687,7 +2684,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
             ScalarEvolution::setFlags(PreservedFlags, SCEV::FlagNSW);
       }
 
-      if (PreservedFlags != SCEV::FlagAnyWrap) {
+      if (PreservedFlags != SCEV::FlagAny) {
         SmallVector<SCEVUse, 4> NewOps(AddExpr->operands());
         NewOps[0] = getConstant(ConstAdd);
         return getAddExpr(NewOps, PreservedFlags);
@@ -2702,7 +2699,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       if (NarrowA == getNegativeSCEV(InnerAdd->getOperand(0)) &&
           getZeroExtendExpr(NarrowA, B->getType()) == A &&
           hasFlags(StrengthenNoWrapFlags(this, scAddExpr, {NarrowA, InnerAdd},
-                                         SCEV::FlagAnyWrap),
+                                         SCEV::FlagAny),
                    SCEV::FlagNUW)) {
         return getZeroExtendExpr(getAddExpr(NarrowA, InnerAdd), B->getType());
       }
@@ -2727,7 +2724,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
     // If the original flags and all inlined SCEVAddExprs are NUW, use the
     // common NUW flag for expression after inlining. Other flags cannot be
     // preserved, because they may depend on the original order of operations.
-    SCEV::NoWrapFlags CommonFlags = maskFlags(OrigFlags, SCEV::FlagNUW);
+    SCEVFlags CommonFlags = maskFlags(ExprFlags, SCEV::FlagNUW);
     while (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[Idx])) {
       if (Ops.size() > AddOpsInlineThreshold ||
           Add->getNumOperands() > AddOpsInlineThreshold)
@@ -2737,7 +2734,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       Ops.erase(Ops.begin()+Idx);
       append_range(Ops, Add->operands());
       DeletedAdd = true;
-      CommonFlags = maskFlags(CommonFlags, Add->getNoWrapFlags());
+      CommonFlags = maskFlags(CommonFlags, Add->getFlags());
     }
 
     // If we deleted at least one add, we added operands to the end of the list,
@@ -2778,19 +2775,19 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
         Ops.push_back(getConstant(AccumulatedConstant));
       for (auto &MulOp : MulOpLists) {
         if (MulOp.first == 1) {
-          Ops.push_back(getAddExpr(MulOp.second, SCEV::FlagAnyWrap, Depth + 1));
+          Ops.push_back(getAddExpr(MulOp.second, SCEV::FlagAny, Depth + 1));
         } else if (MulOp.first != 0) {
-          Ops.push_back(getMulExpr(
-              getConstant(MulOp.first),
-              getAddExpr(MulOp.second, SCEV::FlagAnyWrap, Depth + 1),
-              SCEV::FlagAnyWrap, Depth + 1));
+          Ops.push_back(
+              getMulExpr(getConstant(MulOp.first),
+                         getAddExpr(MulOp.second, SCEV::FlagAny, Depth + 1),
+                         SCEV::FlagAny, Depth + 1));
         }
       }
       if (Ops.empty())
         return getZero(Ty);
       if (Ops.size() == 1)
         return Ops[0];
-      return getAddExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+      return getAddExpr(Ops, SCEV::FlagAny, Depth + 1);
     }
   }
 
@@ -2801,7 +2798,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       return M->getOperand(OpIdx == 0);
     SmallVector<SCEVUse, 4> Remaining(M->operands().take_front(OpIdx));
     append_range(Remaining, M->operands().drop_front(OpIdx + 1));
-    return getMulExpr(Remaining, SCEV::FlagAnyWrap, Depth + 1);
+    return getMulExpr(Remaining, SCEV::FlagAny, Depth + 1);
   };
 
   // If we are adding something to a multiply expression, make sure the
@@ -2849,9 +2846,9 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       if (!Cofactors.empty()) {
         Cofactors.push_back(StripFactor(Mul, MulOp));
 
-        SCEVUse InnerSum = getAddExpr(Cofactors, SCEV::FlagAnyWrap, Depth + 1);
+        SCEVUse InnerSum = getAddExpr(Cofactors, SCEV::FlagAny, Depth + 1);
         SCEVUse OuterMul =
-            getMulExpr(MulOpSCEV, InnerSum, SCEV::FlagAnyWrap, Depth + 1);
+            getMulExpr(MulOpSCEV, InnerSum, SCEV::FlagAny, Depth + 1);
 
         // DeadIndices does not include Idx (the anchor), hence +1.
         if (Ops.size() == DeadIndices.size() + 1)
@@ -2866,7 +2863,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
           Ops.erase(Ops.begin() + (Dead > Idx ? Dead - 1 : Dead));
 
         Ops.push_back(OuterMul);
-        return getAddExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+        return getAddExpr(Ops, SCEV::FlagAny, Depth + 1);
       }
     }
   }
@@ -2897,7 +2894,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       // the addrec. Temporarily push it as an operand for that purpose. These
       // flags are valid in the scope of the addrec only.
       LIOps.push_back(AddRec);
-      SCEV::NoWrapFlags Flags = ComputeFlags(LIOps);
+      SCEVFlags Flags = ComputeFlags(LIOps);
       LIOps.pop_back();
 
       //  NLI + LI + {Start,+,Step}  -->  NLI + {LI+Start,+,Step}
@@ -2915,19 +2912,19 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
       // Proving that entry to the outer scope neccesitates entry to the inner
       // scope, thus proves the program undefined if the flags would be violated
       // in the outer scope.
-      SCEV::NoWrapFlags AddFlags = Flags;
-      if (AddFlags != SCEV::FlagAnyWrap) {
+      SCEVFlags AddFlags = Flags;
+      if (AddFlags != SCEV::FlagAny) {
         auto *DefI = getDefiningScopeBound(LIOps);
         auto *ReachI = &*AddRecLoop->getHeader()->begin();
         if (!isGuaranteedToTransferExecutionTo(DefI, ReachI))
-          AddFlags = SCEV::FlagAnyWrap;
+          AddFlags = SCEV::FlagAny;
       }
       AddRecOps[0] = getAddExpr(LIOps, AddFlags, Depth + 1);
 
       // Build the new addrec. Propagate the NUW and NSW flags if both the
       // outer add and the inner addrec are guaranteed to have no overflow.
       // Always propagate NW.
-      Flags = AddRec->getNoWrapFlags(setFlags(Flags, SCEV::FlagNW));
+      Flags = AddRec->getFlags(setFlags(Flags, SCEV::FlagNW));
       const SCEV *NewRec = getAddRecExpr(AddRecOps, AddRecLoop, Flags);
 
       // If all of the other operands were loop invariant, we are done.
@@ -2939,7 +2936,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
           Ops[i] = NewRec;
           break;
         }
-      return getAddExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+      return getAddExpr(Ops, SCEV::FlagAny, Depth + 1);
     }
 
     // Okay, if there weren't any loop invariants to be folded, check to see if
@@ -2969,14 +2966,14 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
               }
               AddRecOps[i] =
                   getAddExpr(AddRecOps[i], OtherAddRec->getOperand(i),
-                             SCEV::FlagAnyWrap, Depth + 1);
+                             SCEV::FlagAny, Depth + 1);
             }
             Ops.erase(Ops.begin() + OtherIdx); --OtherIdx;
           }
         }
         // Step size has changed, so we cannot guarantee no self-wraparound.
-        Ops[Idx] = getAddRecExpr(AddRecOps, AddRecLoop, SCEV::FlagAnyWrap);
-        return getAddExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+        Ops[Idx] = getAddRecExpr(AddRecOps, AddRecLoop, SCEV::FlagAny);
+        return getAddExpr(Ops, SCEV::FlagAny, Depth + 1);
       }
     }
 
@@ -2986,13 +2983,13 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
 
   // Okay, it looks like we really DO need an add expr.  Check to see if we
   // already have one, otherwise create a new one.
-  assert((UseFlags == SCEV::FlagAnyWrap || equal(OrigOps, Ops)) &&
+  assert((UseFlags == SCEV::FlagAny || equal(OrigOps, Ops)) &&
          "Tried to add SCEVUse flags after operands changed");
   return {getOrCreateAddExpr(Ops, ComputeFlags(Ops)), UseFlags};
 }
 
 const SCEV *ScalarEvolution::getOrCreateAddExpr(ArrayRef<SCEVUse> Ops,
-                                                SCEV::NoWrapFlags Flags) {
+                                                SCEVFlags Flags) {
   FoldingSetNodeID ID;
   ID.AddInteger(scAddExpr);
   for (SCEVUse Op : Ops)
@@ -3008,13 +3005,13 @@ const SCEV *ScalarEvolution::getOrCreateAddExpr(ArrayRef<SCEVUse> Ops,
     S->computeAndSetCanonical(*this);
     registerUser(S, Ops);
   }
-  S->setNoWrapFlags(Flags);
+  S->setFlags(Flags);
   return S;
 }
 
 const SCEV *ScalarEvolution::getOrCreateAddRecExpr(ArrayRef<SCEVUse> Ops,
                                                    const Loop *L,
-                                                   SCEV::NoWrapFlags Flags) {
+                                                   SCEVFlags Flags) {
   FoldingSetNodeID ID;
   ID.AddInteger(scAddRecExpr);
   for (SCEVUse Op : Ops)
@@ -3033,12 +3030,12 @@ const SCEV *ScalarEvolution::getOrCreateAddRecExpr(ArrayRef<SCEVUse> Ops,
     LoopUsers[L].push_back(S);
     registerUser(S, Ops);
   }
-  setNoWrapFlags(S, Flags);
+  S->setFlags(Flags);
   return S;
 }
 
 const SCEV *ScalarEvolution::getOrCreateMulExpr(ArrayRef<SCEVUse> Ops,
-                                                SCEV::NoWrapFlags Flags) {
+                                                SCEVFlags Flags) {
   FoldingSetNodeID ID;
   ID.AddInteger(scMulExpr);
   for (SCEVUse Op : Ops)
@@ -3054,7 +3051,7 @@ const SCEV *ScalarEvolution::getOrCreateMulExpr(ArrayRef<SCEVUse> Ops,
     S->computeAndSetCanonical(*this);
     registerUser(S, Ops);
   }
-  S->setNoWrapFlags(Flags);
+  S->setFlags(Flags);
   return S;
 }
 
@@ -3130,10 +3127,10 @@ static bool containsConstantInAddMulChain(const SCEV *StartExpr) {
 
 /// Get a canonical multiply expression, or something simpler if possible.
 SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
-                                    SCEVFlags Flags, unsigned Depth) {
-  SCEV::NoWrapFlags OrigFlags = Flags.ExprFlags;
-  SCEV::NoWrapFlags UseFlags = Flags.UseFlags;
-  assert(OrigFlags == maskFlags(OrigFlags, SCEV::FlagNUW | SCEV::FlagNSW) &&
+                                    SCEVFlagInfo Flags, unsigned Depth) {
+  SCEVFlags ExprFlags, UseFlags;
+  std::tie(ExprFlags, UseFlags) = Flags;
+  assert(ExprFlags == maskFlags(ExprFlags, SCEV::FlagNUW | SCEV::FlagNSW) &&
          "only nuw or nsw allowed");
   assert(UseFlags == maskFlags(UseFlags, SCEV::FlagNUW | SCEV::FlagNSW) &&
          "only nuw or nsw allowed");
@@ -3162,8 +3159,8 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
 #endif
 
   // Delay expensive flag strengthening until necessary.
-  auto ComputeFlags = [this, OrigFlags](const ArrayRef<SCEVUse> Ops) {
-    return StrengthenNoWrapFlags(this, scMulExpr, Ops, OrigFlags);
+  auto ComputeFlags = [this, ExprFlags](const ArrayRef<SCEVUse> Ops) {
+    return StrengthenNoWrapFlags(this, scMulExpr, Ops, ExprFlags);
   };
 
   // Limit recursion calls depth.
@@ -3173,8 +3170,8 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
   if (SCEV *S = findExistingSCEVInCache(scMulExpr, Ops)) {
     // Don't strengthen flags if we have no new information.
     SCEVMulExpr *Mul = static_cast<SCEVMulExpr *>(S);
-    if (Mul->getNoWrapFlags(OrigFlags) != OrigFlags)
-      Mul->setNoWrapFlags(ComputeFlags(Ops));
+    if (Mul->getFlags(ExprFlags) != ExprFlags)
+      Mul->setFlags(ComputeFlags(Ops));
     return {S, UseFlags};
   }
 
@@ -3190,9 +3187,9 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
       const SCEV *Op0, *Op1;
       if (match(Ops[1], m_scev_Add(m_SCEV(Op0), m_SCEV(Op1))) &&
           containsConstantInAddMulChain(Ops[1])) {
-        const SCEV *LHS = getMulExpr(LHSC, Op0, SCEV::FlagAnyWrap, Depth + 1);
-        const SCEV *RHS = getMulExpr(LHSC, Op1, SCEV::FlagAnyWrap, Depth + 1);
-        return getAddExpr(LHS, RHS, SCEV::FlagAnyWrap, Depth + 1);
+        const SCEV *LHS = getMulExpr(LHSC, Op0, SCEV::FlagAny, Depth + 1);
+        const SCEV *RHS = getMulExpr(LHSC, Op1, SCEV::FlagAny, Depth + 1);
+        return getAddExpr(LHS, RHS, SCEV::FlagAny, Depth + 1);
       }
 
       if (Ops[0]->isAllOnesValue()) {
@@ -3202,19 +3199,19 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
           SmallVector<SCEVUse, 4> NewOps;
           bool AnyFolded = false;
           for (const SCEV *AddOp : Add->operands()) {
-            const SCEV *Mul = getMulExpr(Ops[0], SCEVUse(AddOp),
-                                         SCEV::FlagAnyWrap, Depth + 1);
+            const SCEV *Mul =
+                getMulExpr(Ops[0], SCEVUse(AddOp), SCEV::FlagAny, Depth + 1);
             if (!isa<SCEVMulExpr>(Mul)) AnyFolded = true;
             NewOps.push_back(Mul);
           }
           if (AnyFolded)
-            return getAddExpr(NewOps, SCEV::FlagAnyWrap, Depth + 1);
+            return getAddExpr(NewOps, SCEV::FlagAny, Depth + 1);
         } else if (const auto *AddRec = dyn_cast<SCEVAddRecExpr>(Ops[1])) {
           // Negation preserves a recurrence's no self-wrap property.
           SmallVector<SCEVUse, 4> Operands;
           for (const SCEV *AddRecOp : AddRec->operands())
             Operands.push_back(getMulExpr(Ops[0], SCEVUse(AddRecOp),
-                                          SCEV::FlagAnyWrap, Depth + 1));
+                                          SCEV::FlagAny, Depth + 1));
           // Let M be the minimum representable signed value. AddRec with nsw
           // multiplied by -1 can have signed overflow if and only if it takes a
           // value of M: M * (-1) would stay M and (M + 1) * (-1) would be the
@@ -3228,7 +3225,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
               FlagsMask = setFlags(FlagsMask, SCEV::FlagNSW);
           }
           return getAddRecExpr(Operands, AddRec->getLoop(),
-                               AddRec->getNoWrapFlags(FlagsMask));
+                               AddRec->getFlags(FlagsMask));
         }
       }
 
@@ -3240,7 +3237,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
         if (isa<SCEVConstant>(InnerAdd->getOperand(0)) &&
             getZeroExtendExpr(NarrowC, Ops[1]->getType()) == LHSC &&
             hasFlags(StrengthenNoWrapFlags(this, scMulExpr, {NarrowC, InnerAdd},
-                                           SCEV::FlagAnyWrap),
+                                           SCEV::FlagAny),
                      SCEV::FlagNUW)) {
           const SCEV *Res =
               getMulExpr(NarrowC, InnerAdd, SCEV::FlagNUW, Depth + 1);
@@ -3297,7 +3294,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
     // list, and they are not necessarily sorted.  Recurse to resort and
     // resimplify any operands we just acquired.
     if (DeletedMul)
-      return getMulExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+      return getMulExpr(Ops, SCEV::FlagAny, Depth + 1);
   }
 
   // If there are any add recurrences in the operands list, see if any other
@@ -3324,18 +3321,17 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
       //  NLI * LI * {Start,+,Step}  -->  NLI * {LI*Start,+,LI*Step}
       SmallVector<SCEVUse, 4> NewOps;
       NewOps.reserve(AddRec->getNumOperands());
-      const SCEV *Scale = getMulExpr(LIOps, SCEV::FlagAnyWrap, Depth + 1);
+      const SCEV *Scale = getMulExpr(LIOps, SCEV::FlagAny, Depth + 1);
 
       // If both the mul and addrec are nuw, we can preserve nuw.
       // If both the mul and addrec are nsw, we can only preserve nsw if either
       // a) they are also nuw, or
       // b) all multiplications of addrec operands with scale are nsw.
-      SCEV::NoWrapFlags Flags =
-          AddRec->getNoWrapFlags(ComputeFlags({Scale, AddRec}));
+      SCEVFlags Flags = AddRec->getFlags(ComputeFlags({Scale, AddRec}));
 
       for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) {
-        NewOps.push_back(getMulExpr(Scale, AddRec->getOperand(i),
-                                    SCEV::FlagAnyWrap, Depth + 1));
+        NewOps.push_back(
+            getMulExpr(Scale, AddRec->getOperand(i), SCEV::FlagAny, Depth + 1));
 
         if (hasFlags(Flags, SCEV::FlagNSW) && !hasFlags(Flags, SCEV::FlagNUW)) {
           ConstantRange NSWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
@@ -3357,7 +3353,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
           Ops[i] = NewRec;
           break;
         }
-      return getMulExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+      return getMulExpr(Ops, SCEV::FlagAny, Depth + 1);
     }
 
     // Okay, if there weren't any loop invariants to be folded, check to see
@@ -3410,17 +3406,17 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
             const SCEV *CoeffTerm = getConstant(Ty, Coeff);
             const SCEV *Term1 = AddRec->getOperand(y-z);
             const SCEV *Term2 = OtherAddRec->getOperand(z);
-            SumOps.push_back(getMulExpr(CoeffTerm, Term1, Term2,
-                                        SCEV::FlagAnyWrap, Depth + 1));
+            SumOps.push_back(
+                getMulExpr(CoeffTerm, Term1, Term2, SCEV::FlagAny, Depth + 1));
           }
         }
         if (SumOps.empty())
           SumOps.push_back(getZero(Ty));
-        AddRecOps.push_back(getAddExpr(SumOps, SCEV::FlagAnyWrap, Depth + 1));
+        AddRecOps.push_back(getAddExpr(SumOps, SCEV::FlagAny, Depth + 1));
       }
       if (!Overflow) {
-        const SCEV *NewAddRec = getAddRecExpr(AddRecOps, AddRec->getLoop(),
-                                              SCEV::FlagAnyWrap);
+        const SCEV *NewAddRec =
+            getAddRecExpr(AddRecOps, AddRec->getLoop(), SCEV::FlagAny);
         if (Ops.size() == 2) return NewAddRec;
         Ops[Idx] = NewAddRec;
         Ops.erase(Ops.begin() + OtherIdx); --OtherIdx;
@@ -3431,7 +3427,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
       }
     }
     if (OpsModified)
-      return getMulExpr(Ops, SCEV::FlagAnyWrap, Depth + 1);
+      return getMulExpr(Ops, SCEV::FlagAny, Depth + 1);
 
     // Otherwise couldn't fold anything into this recurrence.  Move onto the
     // next one.
@@ -3439,7 +3435,7 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
 
   // Okay, it looks like we really DO need an mul expr.  Check to see if we
   // already have one, otherwise create a new one.
-  assert((UseFlags == SCEV::FlagAnyWrap || equal(OrigOps, Ops)) &&
+  assert((UseFlags == SCEV::FlagAny || equal(OrigOps, Ops)) &&
          "Tried to add SCEVUse flags after operands changed");
   return {getOrCreateMulExpr(Ops, ComputeFlags(Ops)), UseFlags};
 }
@@ -3513,9 +3509,9 @@ const SCEV *ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
           const APInt &DivInt = RHSC->getAPInt();
           if (!StepInt.urem(DivInt) &&
               getZeroExtendExpr(AR, ExtTy) ==
-              getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
-                            getZeroExtendExpr(Step, ExtTy),
-                            AR->getLoop(), SCEV::FlagAnyWrap)) {
+                  getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
+                                getZeroExtendExpr(Step, ExtTy), AR->getLoop(),
+                                SCEV::FlagAny)) {
             SmallVector<SCEVUse, 4> Operands;
             for (const SCEV *Op : AR->operands())
               Operands.push_back(getUDivExpr(Op, RHS));
@@ -3530,7 +3526,7 @@ const SCEV *ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
                 getZeroExtendExpr(AR, ExtTy) ==
                 getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy),
                               getZeroExtendExpr(Step, ExtTy), AR->getLoop(),
-                              SCEV::FlagAnyWrap);
+                              SCEV::FlagAny);
 
             // With N <= C and both N, C as powers-of-2, the transformation
             // {X,+,N}/C => {(X - X%N),+,N}/C preserves division results even
@@ -3546,7 +3542,7 @@ const SCEV *ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
                 !isa<SCEVAddExpr>(NewStart)) {
               const SCEV *NewLHS =
                   getAddRecExpr(NewStart, Step, AR->getLoop(),
-                                NoWrap ? SCEV::FlagNW : SCEV::FlagAnyWrap);
+                                NoWrap ? SCEV::FlagNW : SCEV::FlagAny);
               if (LHS != NewLHS)
                 return getUDivExpr(NewLHS, RHS);
             }
@@ -3682,7 +3678,7 @@ const SCEV *ScalarEvolution::getUDivExactExpr(SCEVUse LHS, SCEVUse RHS) {
 /// Get an add recurrence expression for the specified loop.  Simplify the
 /// expression as much as possible.
 SCEVUse ScalarEvolution::getAddRecExpr(SCEVUse Start, SCEVUse Step,
-                                       const Loop *L, SCEVFlags Flags) {
+                                       const Loop *L, SCEVFlagInfo Flags) {
   SmallVector<SCEVUse, 4> Operands;
   Operands.push_back(Start);
   if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
@@ -3690,8 +3686,7 @@ SCEVUse ScalarEvolution::getAddRecExpr(SCEVUse Start, SCEVUse Step,
       append_range(Operands, StepChrec->operands());
       // The use flags describe the two-operand recurrence, not the flattened
       // one built here, so drop them just like the expression's NUW/NSW.
-      return getAddRecExpr(Operands, L,
-                           maskFlags(Flags.ExprFlags, SCEV::FlagNW));
+      return getAddRecExpr(Operands, L, maskFlags(Flags.first, SCEV::FlagNW));
     }
 
   Operands.push_back(Step);
@@ -3701,9 +3696,8 @@ SCEVUse ScalarEvolution::getAddRecExpr(SCEVUse Start, SCEVUse Step,
 /// Get an add recurrence expression for the specified loop.  Simplify the
 /// expression as much as possible.
 SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
-                                       const Loop *L, SCEVFlags NWFlags) {
-  SCEV::NoWrapFlags Flags = NWFlags.ExprFlags;
-  SCEV::NoWrapFlags UseFlags = NWFlags.UseFlags;
+                                       const Loop *L, SCEVFlagInfo Flags) {
+  auto [ExprFlags, UseFlags] = Flags;
   assert(!(UseFlags & ~(SCEV::FlagNUW | SCEV::FlagNSW)) &&
          "only nuw or nsw allowed");
   if (Operands.size() == 1) return Operands[0];
@@ -3725,7 +3719,7 @@ SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
 
   if (Operands.back()->isZero()) {
     Operands.pop_back();
-    return getAddRecExpr(Operands, L, SCEV::FlagAnyWrap); // {X,+,0}  -->  X
+    return getAddRecExpr(Operands, L, SCEV::FlagAny); // {X,+,0}  -->  X
   }
 
   // It's tempting to want to call getConstantMaxBackedgeTakenCount count here and
@@ -3734,7 +3728,7 @@ SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
   // meaningful BE count at this point (and if we don't, we'd be stuck
   // with a SCEVCouldNotCompute as the cached BE count).
 
-  Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
+  ExprFlags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, ExprFlags);
 
   // Canonicalize nested AddRecs in by nesting them in order of loop depth.
   if (const SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
@@ -3756,8 +3750,8 @@ SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
         //
         // The outer recurrence keeps its NW flag but only keeps NUW/NSW if the
         // inner recurrence has the same property.
-        SCEV::NoWrapFlags OuterFlags =
-          maskFlags(Flags, SCEV::FlagNW | NestedAR->getNoWrapFlags());
+        SCEVFlags OuterFlags =
+            maskFlags(ExprFlags, SCEV::FlagNW | NestedAR->getFlags());
 
         NestedOperands[0] = getAddRecExpr(Operands, L, OuterFlags);
         AllInvariant = all_of(NestedOperands, [&](const SCEV *Op) {
@@ -3769,8 +3763,8 @@ SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
           //
           // The inner recurrence keeps its NW flag but only keeps NUW/NSW if
           // the outer recurrence has the same property.
-          SCEV::NoWrapFlags InnerFlags =
-            maskFlags(NestedAR->getNoWrapFlags(), SCEV::FlagNW | Flags);
+          SCEVFlags InnerFlags =
+              maskFlags(NestedAR->getFlags(), SCEV::FlagNW | ExprFlags);
           return getAddRecExpr(NestedOperands, NestedLoop, InnerFlags);
         }
       }
@@ -3781,9 +3775,9 @@ SCEVUse ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVUse> &Operands,
 
   // Okay, it looks like we really DO need an addrec expr.  Check to see if we
   // already have one, otherwise create a new one.
-  assert((UseFlags == SCEV::FlagAnyWrap || equal(OrigOperands, Operands)) &&
+  assert((UseFlags == SCEV::FlagAny || equal(OrigOperands, Operands)) &&
          "Tried to add SCEVUse flags after operands changed");
-  return {getOrCreateAddRecExpr(Operands, L, Flags), UseFlags};
+  return {getOrCreateAddRecExpr(Operands, L, ExprFlags), UseFlags};
 }
 
 const SCEV *ScalarEvolution::getGEPExpr(GEPOperator *GEP,
@@ -3809,7 +3803,7 @@ const SCEV *ScalarEvolution::getGEPExpr(GEPOperator *GEP,
 const SCEV *ScalarEvolution::getGEPExpr(SCEVUse BaseExpr,
                                         ArrayRef<SCEVUse> IndexExprs,
                                         Type *SrcElementTy, GEPNoWrapFlags NW) {
-  SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap;
+  SCEVFlags OffsetWrap = SCEV::FlagAny;
   if (NW.hasNoUnsignedSignedWrap())
     OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNSW);
   if (NW.hasNoUnsignedWrap())
@@ -3862,7 +3856,7 @@ const SCEV *ScalarEvolution::getGEPExpr(SCEVUse BaseExpr,
   // non-negative, we can use nuw.
   bool NUW = NW.hasNoUnsignedWrap() ||
              (NW.hasNoUnsignedSignedWrap() && isKnownNonNegative(Offset));
-  SCEV::NoWrapFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAnyWrap;
+  SCEVFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAny;
   const SCEV *GEPExpr = getAddExpr(BaseExpr, Offset, BaseWrap);
   assert(BaseExpr->getType() == GEPExpr->getType() &&
          "GEP should not change type mid-flight.");
@@ -3880,7 +3874,7 @@ SCEV *ScalarEvolution::findExistingSCEVInCache(SCEVTypes SCEVType,
 }
 
 const SCEV *ScalarEvolution::getAbsExpr(const SCEV *Op, bool IsNSW) {
-  SCEV::NoWrapFlags Flags = IsNSW ? SCEV::FlagNSW : SCEV::FlagAnyWrap;
+  SCEVFlags Flags = IsNSW ? SCEV::FlagNSW : SCEV::FlagAny;
   return getSMaxExpr(Op, getNegativeSCEV(Op, Flags));
 }
 
@@ -4578,8 +4572,7 @@ const SCEV *ScalarEvolution::getExistingSCEV(Value *V) {
 }
 
 /// Return a SCEV corresponding to -V = -1*V
-const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V,
-                                             SCEV::NoWrapFlags Flags) {
+const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V, SCEVFlags Flags) {
   if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
     return getConstant(
                cast<ConstantInt>(ConstantExpr::getNeg(VC->getValue())));
@@ -4637,7 +4630,7 @@ const SCEV *ScalarEvolution::removePointerBase(const SCEV *P) {
     Ops[0] = removePointerBase(Ops[0]);
     // Don't try to transfer nowrap flags for now. We could in some cases
     // (for example, if pointer operand of the AddRec is a SCEVUnknown).
-    return getAddRecExpr(Ops, AddRec->getLoop(), SCEV::FlagAnyWrap);
+    return getAddRecExpr(Ops, AddRec->getLoop(), SCEV::FlagAny);
   }
   if (auto *Add = dyn_cast<SCEVAddExpr>(P)) {
     // The base of an Add is the pointer operand.
@@ -4659,8 +4652,7 @@ const SCEV *ScalarEvolution::removePointerBase(const SCEV *P) {
 }
 
 const SCEV *ScalarEvolution::getMinusSCEV(SCEVUse LHS, SCEVUse RHS,
-                                          SCEV::NoWrapFlags Flags,
-                                          unsigned Depth) {
+                                          SCEVFlags Flags, unsigned Depth) {
   // Fast path: X - X --> 0.
   if (LHS == RHS)
     return getZero(LHS->getType());
@@ -4678,7 +4670,7 @@ const SCEV *ScalarEvolution::getMinusSCEV(SCEVUse LHS, SCEVUse RHS,
 
   // We represent LHS - RHS as LHS + (-1)*RHS. This transformation
   // makes it so that we cannot make much use of NUW.
-  auto AddFlags = SCEV::FlagAnyWrap;
+  auto AddFlags = SCEV::FlagAny;
   const bool RHSIsNotMinSigned =
       !getSignedRangeMin(RHS).isMinSignedValue();
   if (hasFlags(Flags, SCEV::FlagNSW)) {
@@ -4703,7 +4695,7 @@ const SCEV *ScalarEvolution::getMinusSCEV(SCEVUse LHS, SCEVUse RHS,
   // relative to a loop that is to be found in a recurrence in LHS and
   // not in RHS. Applying NSW to (-1)*M may then let the NSW have a
   // larger scope than intended.
-  auto NegFlags = RHSIsNotMinSigned ? SCEV::FlagNSW : SCEV::FlagAnyWrap;
+  auto NegFlags = RHSIsNotMinSigned ? SCEV::FlagNSW : SCEV::FlagAny;
 
   return getAddExpr(LHS, getNegativeSCEV(RHS, NegFlags), AddFlags, Depth);
 }
@@ -5079,14 +5071,14 @@ void ScalarEvolution::inferNoWrapViaConstantRanges(const SCEVAddRecExpr *AR) {
       unsigned NoOverflowBitWidth =
         BECountAP.getActiveBits() + StepCR.getMinSignedBits();
       if (NoOverflowBitWidth <= getTypeSizeInBits(AR->getType()))
-        const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags(SCEV::FlagNW);
+        const_cast<SCEVAddRecExpr *>(AR)->setFlags(SCEV::FlagNW);
     }
   }
 }
 
-SCEV::NoWrapFlags
+SCEVFlags
 ScalarEvolution::proveNoSignedWrapViaInduction(const SCEVAddRecExpr *AR) {
-  SCEV::NoWrapFlags Result = AR->getNoWrapFlags();
+  SCEVFlags Result = AR->getFlags();
 
   if (AR->hasNoSignedWrap())
     return Result;
@@ -5137,9 +5129,9 @@ ScalarEvolution::proveNoSignedWrapViaInduction(const SCEVAddRecExpr *AR) {
   }
   return Result;
 }
-SCEV::NoWrapFlags
+SCEVFlags
 ScalarEvolution::proveNoUnsignedWrapViaInduction(const SCEVAddRecExpr *AR) {
-  SCEV::NoWrapFlags Result = AR->getNoWrapFlags();
+  SCEVFlags Result = AR->getFlags();
 
   if (AR->hasNoUnsignedWrap())
     return Result;
@@ -5553,7 +5545,7 @@ ScalarEvolution::createAddRecFromPHIWithCastsImpl(const SCEVUnknown *SymbolicPHI
   const SCEV *StartVal = getSCEV(StartValueV);
   const SCEV *PHISCEV =
       getAddRecExpr(getTruncateExpr(StartVal, TruncTy),
-                    getTruncateExpr(Accum, TruncTy), L, SCEV::FlagAnyWrap);
+                    getTruncateExpr(Accum, TruncTy), L, SCEV::FlagAny);
 
   // PHISCEV can be either a SCEVConstant or a SCEVAddRecExpr.
   // ex: If truncated Accum is 0 and StartVal is a constant, then PHISCEV
@@ -5630,7 +5622,7 @@ ScalarEvolution::createAddRecFromPHIWithCastsImpl(const SCEVUnknown *SymbolicPHI
   // which the casts had been folded away. The caller can rewrite SymbolicPHI
   // into NewAR if it will also add the runtime overflow checks specified in
   // Predicates.
-  const SCEV *NewAR = getAddRecExpr(StartVal, Accum, L, SCEV::FlagAnyWrap);
+  const SCEV *NewAR = getAddRecExpr(StartVal, Accum, L, SCEV::FlagAny);
 
   std::pair<const SCEV *, SmallVector<const SCEVPredicate *, 3>> PredRewrite =
       std::make_pair(NewAR, Predicates);
@@ -5702,9 +5694,9 @@ bool PredicatedScalarEvolution::areAddRecsEqualWithPreds(
   return true;
 }
 
-static SCEV::NoWrapFlags
-getNoWrapFlagsForGEP(GEPOperator *GEP, const SCEV *Accum, ScalarEvolution &SE) {
-  SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+static SCEVFlags getNoWrapFlagsForGEP(GEPOperator *GEP, const SCEV *Accum,
+                                      ScalarEvolution &SE) {
+  SCEVFlags Flags = SCEV::FlagAny;
   GEPNoWrapFlags NW = GEP->getNoWrapFlags();
   // If the increment has any nowrap flags, then we know the address
   // space cannot be wrapped around.
@@ -5734,7 +5726,7 @@ const SCEV *ScalarEvolution::createSimpleAffineAddRec(PHINode *PN,
   assert(BEValueV && StartValueV);
 
   const SCEV *Accum = nullptr;
-  SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+  SCEVFlags Flags = SCEV::FlagAny;
   if (auto BO = MatchBinaryOp(BEValueV, getDataLayout(), AC, DT, PN)) {
     if (BO->Opcode != Instruction::Add)
       return nullptr;
@@ -5861,7 +5853,7 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) {
       if (isLoopInvariant(Accum, L) ||
           (isa<SCEVAddRecExpr>(Accum) &&
            cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) {
-        SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+        SCEVFlags Flags = SCEV::FlagAny;
 
         if (auto BO = MatchBinaryOp(BEValueV, getDataLayout(), AC, DT, PN)) {
           if (BO->Opcode == Instruction::Add && BO->LHS == PN) {
@@ -6448,10 +6440,9 @@ static std::optional<ConstantRange> GetRangeFromMetadata(Value *V) {
   return std::nullopt;
 }
 
-void ScalarEvolution::setNoWrapFlags(SCEVAddRecExpr *AddRec,
-                                     SCEV::NoWrapFlags Flags) {
-  if (AddRec->getNoWrapFlags(Flags) != Flags) {
-    AddRec->setNoWrapFlags(Flags);
+void ScalarEvolution::setFlags(SCEVAddRecExpr *AddRec, SCEVFlags Flags) {
+  if (AddRec->getFlags(Flags) != Flags) {
+    AddRec->setFlags(Flags);
     UnsignedRanges.erase(AddRec);
     SignedRanges.erase(AddRec);
     ConstantMultipleCache.erase(AddRec);
@@ -6857,7 +6848,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
               AddRec->getStart(), AddRec->getStepRecurrence(*this), MaxBECount);
           ConservativeResult =
               ConservativeResult.intersectWith(RangeFromAffine, RangeType);
-          const_cast<SCEVAddRecExpr *>(AddRec)->setNoWrapFlags(Flags);
+          const_cast<SCEVAddRecExpr *>(AddRec)->setFlags(Flags);
 
           auto RangeFromFactoring = getRangeViaFactoring(
               AddRec->getStart(), AddRec->getStepRecurrence(*this), MaxBECount);
@@ -7114,7 +7105,7 @@ getRangeForAffineARHelper(APInt Step, const ConstantRange &StartRange,
           !Overflow};
 }
 
-std::pair<ConstantRange, SCEV::NoWrapFlags>
+std::pair<ConstantRange, SCEVFlags>
 ScalarEvolution::getRangeForAffineAR(const SCEV *Start, const SCEV *Step,
                                      const APInt &MaxBECount) {
   assert(getTypeSizeInBits(Start->getType()) ==
@@ -7140,7 +7131,7 @@ ScalarEvolution::getRangeForAffineAR(const SCEV *Start, const SCEV *Step,
       getUnsignedRangeMax(Step), getUnsignedRange(Start), MaxBECount,
       /*Signed=*/false);
 
-  SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+  SCEVFlags Flags = SCEV::FlagAny;
   if (NUW)
     Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
   if (NSW1 && NSW2)
@@ -7332,12 +7323,13 @@ ConstantRange ScalarEvolution::getRangeViaFactoring(const SCEV *Start,
   return TrueRange.unionWith(FalseRange);
 }
 
-SCEV::NoWrapFlags ScalarEvolution::getNoWrapFlagsFromUB(const Value *V) {
-  if (isa<ConstantExpr>(V)) return SCEV::FlagAnyWrap;
+SCEVFlags ScalarEvolution::getNoWrapFlagsFromUB(const Value *V) {
+  if (isa<ConstantExpr>(V))
+    return SCEV::FlagAny;
   const BinaryOperator *BinOp = cast<BinaryOperator>(V);
 
   // Return early if there are no flags to propagate to the SCEV.
-  SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+  SCEVFlags Flags = SCEV::FlagAny;
   if (auto *PDI = dyn_cast<PossiblyDisjointInst>(BinOp);
       PDI && PDI->isDisjoint()) {
     Flags = ScalarEvolution::setFlags(SCEV::FlagNUW, SCEV::FlagNSW);
@@ -7347,10 +7339,10 @@ SCEV::NoWrapFlags ScalarEvolution::getNoWrapFlagsFromUB(const Value *V) {
     if (BinOp->hasNoSignedWrap())
       Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNSW);
   }
-  if (Flags == SCEV::FlagAnyWrap)
-    return SCEV::FlagAnyWrap;
+  if (Flags == SCEV::FlagAny)
+    return SCEV::FlagAny;
 
-  return isSCEVExprNeverPoison(BinOp) ? Flags : SCEV::FlagAnyWrap;
+  return isSCEVExprNeverPoison(BinOp) ? Flags : SCEV::FlagAny;
 }
 
 const Instruction *
@@ -7881,8 +7873,8 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
           // addition - they may not apply to other additions that can be
           // formed with operands from AddOps.
           const SCEV *RHS = getSCEV(BO->RHS);
-          SCEV::NoWrapFlags Flags = getNoWrapFlagsFromUB(BO->Op);
-          if (Flags != SCEV::FlagAnyWrap) {
+          SCEVFlags Flags = getNoWrapFlagsFromUB(BO->Op);
+          if (Flags != SCEV::FlagAny) {
             const SCEV *LHS = getSCEV(BO->LHS);
             if (BO->Opcode == Instruction::Sub)
               AddOps.push_back(getMinusSCEV(LHS, RHS, Flags));
@@ -7919,8 +7911,8 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
             break;
           }
 
-          SCEV::NoWrapFlags Flags = getNoWrapFlagsFromUB(BO->Op);
-          if (Flags != SCEV::FlagAnyWrap) {
+          SCEVFlags Flags = getNoWrapFlagsFromUB(BO->Op);
+          if (Flags != SCEV::FlagAny) {
             LHS = getSCEV(BO->LHS);
             RHS = getSCEV(BO->RHS);
             MulOps.push_back(getMulExpr(LHS, RHS, Flags));
@@ -7949,7 +7941,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
       RHS = getSCEV(BO->RHS);
       return getURemExpr(LHS, RHS);
     case Instruction::Sub: {
-      SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
+      SCEVFlags Flags = SCEV::FlagAny;
       if (BO->Op)
         Flags = getNoWrapFlagsFromUB(BO->Op);
 
@@ -8022,7 +8014,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
               SmallVector<SCEVUse, 4> MulOps;
               MulOps.push_back(getConstant(OpC->getAPInt().ashr(GCD)));
               append_range(MulOps, LHSMul->operands().drop_front());
-              const SCEV *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags());
+              const SCEV *NewMul = getMulExpr(MulOps, LHSMul->getFlags());
               ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt));
             }
           }
@@ -8108,7 +8100,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
         // turn a nuw nsw shl into a nuw nsw mul. However, nsw in isolation
         // requires special handling. It can be preserved as long as we're not
         // left shifting by bitwidth - 1.
-        auto Flags = SCEV::FlagAnyWrap;
+        auto Flags = SCEV::FlagAny;
         if (BO->Op) {
           auto MulFlags = getNoWrapFlagsFromUB(BO->Op);
           if (any(MulFlags & SCEV::FlagNSW) &&
@@ -9434,11 +9426,11 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
         AR && !AR->hasNoSelfWrap() && AR->getLoop() == L && AR->isAffine() &&
         isKnownToBeAPowerOfTwo(AR->getStepRecurrence(*this), /*OrZero=*/true,
                                /*OrNegative=*/true)) {
-      auto Flags = AR->getNoWrapFlags();
+      auto Flags = AR->getFlags();
       Flags = setFlags(Flags, SCEV::FlagNW);
       SmallVector<SCEVUse> Operands{AR->operands()};
       Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
-      setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
+      setFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
     }
 
     // For a slt/ult condition with a positive step, can we prove nsw/nuw?
@@ -9450,13 +9442,13 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
       auto WrapType = Pred == ICmpInst::ICMP_SLT ? SCEV::FlagNSW : SCEV::FlagNUW;
       if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(LHS);
           AR && AR->getLoop() == L && AR->isAffine() &&
-          !AR->getNoWrapFlags(WrapType) && AR->hasNoSelfWrap() &&
+          !AR->getFlags(WrapType) && AR->hasNoSelfWrap() &&
           isKnownPositive(AR->getStepRecurrence(*this))) {
-        auto Flags = AR->getNoWrapFlags();
+        auto Flags = AR->getFlags();
         Flags = setFlags(Flags, WrapType);
         SmallVector<SCEVUse> Operands{AR->operands()};
         Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
-        setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
+        setFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
       }
     }
   }
@@ -10189,12 +10181,12 @@ const SCEV *ScalarEvolution::getWithOperands(const SCEV *S,
     return getCastExpr(S->getSCEVType(), NewOps[0], S->getType());
   case scAddRecExpr: {
     auto *AddRec = cast<SCEVAddRecExpr>(S);
-    return getAddRecExpr(NewOps, AddRec->getLoop(), AddRec->getNoWrapFlags());
+    return getAddRecExpr(NewOps, AddRec->getLoop(), AddRec->getFlags());
   }
   case scAddExpr:
-    return getAddExpr(NewOps, cast<SCEVAddExpr>(S)->getNoWrapFlags());
+    return getAddExpr(NewOps, cast<SCEVAddExpr>(S)->getFlags());
   case scMulExpr:
-    return getMulExpr(NewOps, cast<SCEVMulExpr>(S)->getNoWrapFlags());
+    return getMulExpr(NewOps, cast<SCEVMulExpr>(S)->getFlags());
   case scUDivExpr:
     return getUDivExpr(NewOps[0], NewOps[1]);
   case scUMaxExpr:
@@ -10240,8 +10232,8 @@ SCEVUse ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
       for (++i; i != e; ++i)
         NewOps.push_back(getSCEVAtScope(AddRec->getOperand(i), L));
 
-      const SCEV *FoldedRec = getAddRecExpr(
-          NewOps, AddRec->getLoop(), AddRec->getNoWrapFlags(SCEV::FlagNW));
+      const SCEV *FoldedRec = getAddRecExpr(NewOps, AddRec->getLoop(),
+                                            AddRec->getFlags(SCEV::FlagNW));
       AddRec = dyn_cast<SCEVAddRecExpr>(FoldedRec);
       // The addrec may be folded to a nonrecurrence, for example, if the
       // induction variable is multiplied by zero after constant folding. Go
@@ -11762,12 +11754,11 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(CmpPredicate Pred,
   // consider them as X + 0 and Y + 0 respectively. C1 and C2 are returned via
   // OutC1 and OutC2.
   auto MatchBinaryAddToConst = [this](SCEVUse X, SCEVUse Y, APInt &OutC1,
-                                      APInt &OutC2,
-                                      SCEV::NoWrapFlags ExpectedFlags) {
+                                      APInt &OutC2, SCEVFlags ExpectedFlags) {
     SCEVUse XNonConstOp, XConstOp;
     SCEVUse YNonConstOp, YConstOp;
-    SCEV::NoWrapFlags XFlagsPresent;
-    SCEV::NoWrapFlags YFlagsPresent;
+    SCEVFlags XFlagsPresent;
+    SCEVFlags YFlagsPresent;
 
     if (!splitBinaryAdd(X, XConstOp, XNonConstOp, XFlagsPresent)) {
       XConstOp = getZero(X->getType());
@@ -11938,7 +11929,7 @@ bool ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
     // LatchBECount times.  This means the backdege condition at Latch is
     // equivalent to  "{0,+,1} u< LatchBECount".
     Type *Ty = LatchBECount->getType();
-    auto NoWrapFlags = SCEV::NoWrapFlags(SCEV::FlagNUW | SCEV::FlagNW);
+    auto NoWrapFlags = SCEVFlags(SCEV::FlagNUW | SCEV::FlagNW);
     const SCEV *LoopCounter =
       getAddRecExpr(getZero(Ty), getOne(Ty), L, NoWrapFlags);
     if (isImpliedCond(Pred, LHS, RHS, ICmpInst::ICMP_ULT, LoopCounter,
@@ -12416,11 +12407,11 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
 }
 
 bool ScalarEvolution::splitBinaryAdd(SCEVUse Expr, SCEVUse &L, SCEVUse &R,
-                                     SCEV::NoWrapFlags &Flags) {
+                                     SCEVFlags &Flags) {
   if (!match(Expr, m_scev_Add(m_SCEV(L), m_SCEV(R))))
     return false;
 
-  Flags = cast<SCEVAddExpr>(Expr)->getNoWrapFlags();
+  Flags = cast<SCEVAddExpr>(Expr)->getFlags();
   return true;
 }
 
@@ -12921,9 +12912,8 @@ static bool IsKnownPredicateViaAddRecStart(ScalarEvolution &SE,
     return false;
   const SCEVAddRecExpr *LAR = cast<SCEVAddRecExpr>(LHS);
   const SCEVAddRecExpr *RAR = cast<SCEVAddRecExpr>(RHS);
-  SCEV::NoWrapFlags NW = ICmpInst::isSigned(Pred) ?
-                         SCEV::FlagNSW : SCEV::FlagNUW;
-  if (!LAR->getNoWrapFlags(NW) || !RAR->getNoWrapFlags(NW))
+  SCEVFlags NW = ICmpInst::isSigned(Pred) ? SCEV::FlagNSW : SCEV::FlagNUW;
+  if (!LAR->getFlags(NW) || !RAR->getFlags(NW))
     return false;
 
   return SE.isKnownPredicate(Pred, LStart, RStart);
@@ -13422,11 +13412,11 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
           Limit = Limit.zext(OuterBitWidth);
           return getUnsignedRangeMax(applyLoopGuards(RHS, L)).ule(Limit);
         };
-        auto Flags = AR->getNoWrapFlags();
+        auto Flags = AR->getFlags();
         if (!hasFlags(Flags, SCEV::FlagNUW) && canProveNUW())
           Flags = setFlags(Flags, SCEV::FlagNUW);
 
-        setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
+        setFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
         if (AR->hasNoUnsignedWrap()) {
           // Emulate what getZeroExtendExpr would have done during construction
           // if we'd been able to infer the fact just above at that time.
@@ -13434,7 +13424,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
           Type *Ty = ZExt->getType();
           const SCEV *S = getAddRecExpr(
               getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, 0),
-              getZeroExtendExpr(Step, Ty, 0), L, AR->getNoWrapFlags());
+              getZeroExtendExpr(Step, Ty, 0), L, AR->getFlags());
           IV = dyn_cast<SCEVAddRecExpr>(S);
         }
       }
@@ -13465,7 +13455,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
   // implicit/exceptional) which causes the loop to execute before the
   // exiting instruction we're analyzing would trigger UB.
   auto WrapType = IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW;
-  bool NoWrap = ControlsOnlyExit && any(IV->getNoWrapFlags(WrapType));
+  bool NoWrap = ControlsOnlyExit && any(IV->getFlags(WrapType));
   ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
 
   const SCEV *Stride = IV->getStepRecurrence(*this);
@@ -13596,7 +13586,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
   if (!isLoopInvariant(RHS, L)) {
     const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS);
     if (PositiveStride && RHSAddRec != nullptr && RHSAddRec->getLoop() == L &&
-        any(RHSAddRec->getNoWrapFlags())) {
+        any(RHSAddRec->getFlags())) {
       // The structure of loop we are trying to calculate backedge count of:
       //
       //  left = left_start
@@ -13865,7 +13855,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howManyGreaterThans(
     return getCouldNotCompute();
 
   auto WrapType = IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW;
-  bool NoWrap = ControlsOnlyExit && any(IV->getNoWrapFlags(WrapType));
+  bool NoWrap = ControlsOnlyExit && any(IV->getFlags(WrapType));
   ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
 
   const SCEV *Stride = getNegativeSCEV(IV->getStepRecurrence(*this));
@@ -13958,8 +13948,8 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(const ConstantRange &Range,
     if (!SC->getValue()->isZero()) {
       SmallVector<SCEVUse, 4> Operands(operands());
       Operands[0] = SE.getZero(SC->getType());
-      const SCEV *Shifted = SE.getAddRecExpr(Operands, getLoop(),
-                                             getNoWrapFlags(FlagNW));
+      const SCEV *Shifted =
+          SE.getAddRecExpr(Operands, getLoop(), getFlags(FlagNW));
       if (const auto *ShiftedAddRec = dyn_cast<SCEVAddRecExpr>(Shifted))
         return ShiftedAddRec->getNumIterationsInRange(
             Range.subtract(SC->getAPInt()), SE);
@@ -14040,8 +14030,7 @@ SCEVAddRecExpr::getPostIncExpr(ScalarEvolution &SE) const {
   const SCEV *Last = getOperand(getNumOperands() - 1);
   assert(!Last->isZero() && "Recurrency with zero step?");
   Ops.push_back(Last);
-  return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, getLoop(),
-                                               SCEV::FlagAnyWrap));
+  return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, getLoop(), SCEV::FlagAny));
 }
 
 // Return true when S contains at least an undef value.
@@ -15287,7 +15276,7 @@ class SCEVPredicateRewriter : public SCEVRewriteVisitor<SCEVPredicateRewriter> {
       if (addOverflowAssumption(AR, SCEVWrapPredicate::IncrementNUSW))
         return SE.getAddRecExpr(SE.getZeroExtendExpr(AR->getStart(), Ty),
                                 SE.getSignExtendExpr(Step, Ty), L,
-                                AR->getNoWrapFlags());
+                                AR->getFlags());
     }
     return SE.getZeroExtendExpr(Operand, Expr->getType());
   }
@@ -15303,7 +15292,7 @@ class SCEVPredicateRewriter : public SCEVRewriteVisitor<SCEVPredicateRewriter> {
       if (addOverflowAssumption(AR, SCEVWrapPredicate::IncrementNSSW))
         return SE.getAddRecExpr(SE.getSignExtendExpr(AR->getStart(), Ty),
                                 SE.getSignExtendExpr(Step, Ty), L,
-                                AR->getNoWrapFlags());
+                                AR->getFlags());
     }
     return SE.getSignExtendExpr(Operand, Expr->getType());
   }
@@ -15503,7 +15492,7 @@ bool SCEVWrapPredicate::implies(const SCEVPredicate *N,
 }
 
 bool SCEVWrapPredicate::isAlwaysTrue() const {
-  SCEV::NoWrapFlags ScevFlags = AR->getNoWrapFlags();
+  SCEVFlags ScevFlags = AR->getFlags();
   IncrementWrapFlags IFlags = Flags;
 
   if (ScalarEvolution::setFlags(ScevFlags, SCEV::FlagNSW) == ScevFlags)
@@ -15525,7 +15514,7 @@ SCEVWrapPredicate::IncrementWrapFlags
 SCEVWrapPredicate::getImpliedFlags(const SCEVAddRecExpr *AR,
                                    ScalarEvolution &SE) {
   IncrementWrapFlags ImpliedFlags = IncrementAnyWrap;
-  SCEV::NoWrapFlags StaticFlags = AR->getNoWrapFlags();
+  SCEVFlags StaticFlags = AR->getFlags();
 
   // We can safely transfer the NSW flag as NSSW.
   if (ScalarEvolution::setFlags(StaticFlags, SCEV::FlagNSW) == StaticFlags)
@@ -16335,7 +16324,7 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
     const DenseMap<const SCEV *, const SCEV *> ⤅
     const SmallDenseSet<std::pair<const SCEV *, const SCEV *>> ≠
 
-    SCEV::NoWrapFlags FlagMask = SCEV::FlagAnyWrap;
+    SCEVFlags FlagMask = SCEV::FlagAny;
 
   public:
     SCEVLoopGuardRewriter(ScalarEvolution &SE,
@@ -16430,7 +16419,7 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
           if (const SCEV *Rewritten = RewriteSubtraction(Add))
             return SE.getAddExpr(
                 Expr->getOperand(0), Rewritten,
-                ScalarEvolution::maskFlags(Expr->getNoWrapFlags(), FlagMask));
+                ScalarEvolution::maskFlags(Expr->getFlags(), FlagMask));
           if (const SCEV *S = Map.lookup(Add))
             return SE.getAddExpr(Expr->getOperand(0), S);
         }
@@ -16462,10 +16451,10 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
       }
       // We are only replacing operands with equivalent values, so transfer the
       // flags from the original expression.
-      return !Changed ? Expr
-                      : SE.getAddExpr(Operands,
-                                      ScalarEvolution::maskFlags(
-                                          Expr->getNoWrapFlags(), FlagMask));
+      return !Changed
+                 ? Expr
+                 : SE.getAddExpr(Operands, ScalarEvolution::maskFlags(
+                                               Expr->getFlags(), FlagMask));
     }
 
     const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
@@ -16478,10 +16467,10 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
       }
       // We are only replacing operands with equivalent values, so transfer the
       // flags from the original expression.
-      return !Changed ? Expr
-                      : SE.getMulExpr(Operands,
-                                      ScalarEvolution::maskFlags(
-                                          Expr->getNoWrapFlags(), FlagMask));
+      return !Changed
+                 ? Expr
+                 : SE.getMulExpr(Operands, ScalarEvolution::maskFlags(
+                                               Expr->getFlags(), FlagMask));
     }
   };
 
diff --git a/llvm/lib/Analysis/ScalarEvolutionDivision.cpp b/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
index bd12be7929959..11f1bdebbec38 100644
--- a/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
@@ -138,10 +138,10 @@ void SCEVDivision::visitAddRecExpr(const SCEVAddRecExpr *Numerator) {
       Ty != StepQ->getType() || Ty != StepR->getType())
     return cannotDivide(Numerator);
 
-  Quotient = SE.getAddRecExpr(StartQ, StepQ, Numerator->getLoop(),
-                              SCEV::NoWrapFlags::FlagAnyWrap);
-  Remainder = SE.getAddRecExpr(StartR, StepR, Numerator->getLoop(),
-                               SCEV::NoWrapFlags::FlagAnyWrap);
+  Quotient =
+      SE.getAddRecExpr(StartQ, StepQ, Numerator->getLoop(), SCEVFlags::FlagAny);
+  Remainder =
+      SE.getAddRecExpr(StartR, StepR, Numerator->getLoop(), SCEVFlags::FlagAny);
 }
 
 void SCEVDivision::visitAddExpr(const SCEVAddExpr *Numerator) {
diff --git a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
index bfc2d6aafdbfc..3b9137938b4c2 100644
--- a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
@@ -52,7 +52,7 @@ NormalizeDenormalizeRewriter::visitAddRecExpr(const SCEVAddRecExpr *AR) {
             [&](SCEVUse Op) { return visit(Op.getPointer()); });
 
   if (!Pred(AR))
-    return SE.getAddRecExpr(Operands, AR->getLoop(), SCEV::FlagAnyWrap);
+    return SE.getAddRecExpr(Operands, AR->getLoop(), SCEV::FlagAny);
 
   // Normalization and denormalization are fancy names for decrementing and
   // incrementing a SCEV expression with respect to a set of loops.  Since
@@ -91,7 +91,7 @@ NormalizeDenormalizeRewriter::visitAddRecExpr(const SCEVAddRecExpr *AR) {
       Operands[i] = SE.getMinusSCEV(Operands[i], Operands[i + 1]);
   }
 
-  return SE.getAddRecExpr(Operands, AR->getLoop(), SCEV::FlagAnyWrap);
+  return SE.getAddRecExpr(Operands, AR->getLoop(), SCEV::FlagAny);
 }
 
 const SCEV *llvm::normalizeForPostIncUse(const SCEV *S,
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 08a4a2f95033e..066d64b68df1b 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -565,7 +565,7 @@ static void DoInitialMatch(const SCEV *S, Loop *L,
     DoInitialMatch(Start, L, Good, Bad, SE);
     DoInitialMatch(SE.getAddRecExpr(SE.getConstant(S->getType(), 0), Step,
                                     // FIXME: AR->getNoWrapFlags()
-                                    ARLoop, SCEV::FlagAnyWrap),
+                                    ARLoop, SCEV::FlagAny),
                    L, Good, Bad, SE);
     return;
   }
@@ -868,7 +868,7 @@ static const SCEV *getExactSDiv(const SCEV *LHS, const SCEV *RHS,
       // FlagNW is independent of the start value, step direction, and is
       // preserved with smaller magnitude steps.
       // FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
-      return SE.getAddRecExpr(Start, Step, AR->getLoop(), SCEV::FlagAnyWrap);
+      return SE.getAddRecExpr(Start, Step, AR->getLoop(), SCEV::FlagAny);
     }
     return nullptr;
   }
@@ -988,7 +988,7 @@ static Immediate ExtractImmediate(SCEVUse &S, ScalarEvolution &SE,
     if (Result.isNonZero())
       S = SE.getAddRecExpr(NewOps, AR->getLoop(),
                            // FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
-                           SCEV::FlagAnyWrap);
+                           SCEV::FlagAny);
     return Result;
   }
   return ExtractImmediateOperand({S}, SE, PreferScalable);
@@ -1014,7 +1014,7 @@ static GlobalValue *ExtractSymbol(SCEVUse &S, ScalarEvolution &SE) {
     if (Result)
       S = SE.getAddRecExpr(NewOps, AR->getLoop(),
                            // FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
-                           SCEV::FlagAnyWrap);
+                           SCEV::FlagAny);
     return Result;
   }
   return nullptr;
@@ -3942,7 +3942,7 @@ static const SCEV *CollectSubexprs(const SCEV *S, const SCEVConstant *C,
       return SE.getAddRecExpr(Remainder, Step,
                               cast<SCEVAddRecExpr>(S)->getLoop(),
                               // FIXME: AR->getNoWrapFlags(SCEV::FlagNW)
-                              SCEV::FlagAnyWrap);
+                              SCEV::FlagAny);
     }
   } else if (match(S, m_scev_Mul(m_SCEVConstant(Op0), m_SCEV(Op1)))) {
     // Break (C * (a + b + c)) into C*a + C*b + C*c.
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 93baf01173f98..71cf6a13f3083 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -276,9 +276,9 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
 /// InsertBinop - Insert the specified binary operator, doing a small amount
 /// of work to avoid inserting an obviously redundant operation, and hoisting
 /// to an outer loop when the opportunity is there and it is safe.
-Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
-                                 Value *LHS, Value *RHS,
-                                 SCEV::NoWrapFlags Flags, bool IsSafeToHoist) {
+Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
+                                 Value *RHS, SCEVFlags Flags,
+                                 bool IsSafeToHoist) {
   // Fold a binop with constant operands.
   if (Constant *CLHS = dyn_cast<Constant>(LHS))
     if (Constant *CRHS = dyn_cast<Constant>(RHS))
@@ -378,7 +378,7 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
 /// can be folded using target addressing modes.
 ///
 Value *SCEVExpander::expandAddToGEP(const SCEV *Offset, Value *V,
-                                    SCEV::NoWrapFlags Flags) {
+                                    SCEVFlags Flags) {
   assert(!isa<Instruction>(V) ||
          SE.DT.dominates(cast<Instruction>(V), &*Builder.GetInsertPoint()));
 
@@ -531,7 +531,7 @@ Value *SCEVExpander::visitAddExpr(SCEVUseT<const SCEVAddExpr *> S) {
   if (match(S, m_scev_URem(m_SCEV(URemLHS), m_SCEV(URemRHS), SE))) {
     Value *LHS = expand(URemLHS);
     Value *RHS = expand(URemRHS);
-    return InsertBinop(Instruction::URem, LHS, RHS, SCEV::FlagAnyWrap,
+    return InsertBinop(Instruction::URem, LHS, RHS, SCEV::FlagAny,
                        /*IsSafeToHoist*/ false);
   }
 
@@ -586,11 +586,11 @@ Value *SCEVExpander::visitAddExpr(SCEVUseT<const SCEVAddExpr *> S) {
             X = SE.getSCEV(U->getValue());
         NewOps.push_back(X);
       }
-      Sum = expandAddToGEP(SE.getAddExpr(NewOps), Sum, S.getNoWrapFlags());
+      Sum = expandAddToGEP(SE.getAddExpr(NewOps), Sum, S.getFlags());
     } else if (Op->isNonConstantNegative()) {
       // Instead of doing a negate and add, just do a subtract.
       Value *W = expand(SE.getNegativeSCEV(Op));
-      Sum = InsertBinop(Instruction::Sub, Sum, W, SCEV::FlagAnyWrap,
+      Sum = InsertBinop(Instruction::Sub, Sum, W, SCEV::FlagAny,
                         /*IsSafeToHoist*/ true);
       ++I;
     } else {
@@ -599,7 +599,7 @@ Value *SCEVExpander::visitAddExpr(SCEVUseT<const SCEVAddExpr *> S) {
       // Canonicalize a constant to the RHS.
       if (isa<Constant>(Sum))
         std::swap(Sum, W);
-      Sum = InsertBinop(Instruction::Add, Sum, W, S.getNoWrapFlags(),
+      Sum = InsertBinop(Instruction::Add, Sum, W, S.getFlags(),
                         /*IsSafeToHoist*/ true);
       ++I;
     }
@@ -623,7 +623,7 @@ Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
     unsigned BitWidth = Ty->getScalarSizeInBits();
     APInt Mask(APInt::getBitsSetFrom(BitWidth, ShAmtC));
     Value *Res = InsertBinop(Instruction::And, LHS, ConstantInt::get(Ty, Mask),
-                             SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
+                             SCEV::FlagAny, /*IsSafeToHoist*/ true);
     return Res;
   }
 
@@ -667,13 +667,13 @@ Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
     if (Exponent & 1)
       Result = P;
     for (uint64_t BinExp = 2; BinExp <= Exponent; BinExp <<= 1) {
-      P = InsertBinop(Instruction::Mul, P, P, SCEV::FlagAnyWrap,
+      P = InsertBinop(Instruction::Mul, P, P, SCEV::FlagAny,
                       /*IsSafeToHoist*/ true);
       if (Exponent & BinExp)
-        Result = Result ? InsertBinop(Instruction::Mul, Result, P,
-                                      SCEV::FlagAnyWrap,
-                                      /*IsSafeToHoist*/ true)
-                        : P;
+        Result = Result
+                     ? InsertBinop(Instruction::Mul, Result, P, SCEV::FlagAny,
+                                   /*IsSafeToHoist*/ true)
+                     : P;
     }
 
     I = E;
@@ -688,7 +688,7 @@ Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
     } else if (I->second->isAllOnesValue()) {
       // Instead of doing a multiply by negative one, just do a negate.
       Prod = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), Prod,
-                         SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
+                         SCEV::FlagAny, /*IsSafeToHoist*/ true);
       ++I;
     } else {
       // A simple mul.
@@ -699,7 +699,7 @@ Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
       if (match(W, m_Power2(RHS))) {
         // Canonicalize Prod*(1<<C) to Prod<<C.
         assert(!Ty->isVectorTy() && "vector types are not SCEVable");
-        auto NWFlags = S.getNoWrapFlags();
+        auto NWFlags = S.getFlags();
         // clear nsw flag if shl will produce poison value.
         if (RHS->logBase2() == RHS->getBitWidth() - 1)
           NWFlags = ScalarEvolution::clearFlags(NWFlags, SCEV::FlagNSW);
@@ -707,7 +707,7 @@ Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
                            ConstantInt::get(Ty, RHS->logBase2()), NWFlags,
                            /*IsSafeToHoist*/ true);
       } else {
-        Prod = InsertBinop(Instruction::Mul, Prod, W, S.getNoWrapFlags(),
+        Prod = InsertBinop(Instruction::Mul, Prod, W, S.getFlags(),
                            /*IsSafeToHoist*/ true);
       }
     }
@@ -723,7 +723,7 @@ Value *SCEVExpander::visitUDivExpr(SCEVUseT<const SCEVUDivExpr *> S) {
     if (RHS.isPowerOf2())
       return InsertBinop(Instruction::LShr, LHS,
                          ConstantInt::get(SC->getType(), RHS.logBase2()),
-                         SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
+                         SCEV::FlagAny, /*IsSafeToHoist*/ true);
   }
 
   const SCEV *RHSExpr = S->getRHS();
@@ -741,7 +741,7 @@ Value *SCEVExpander::visitUDivExpr(SCEVUseT<const SCEVUDivExpr *> S) {
       RHS = Builder.CreateIntrinsic(RHS->getType(), Intrinsic::umax,
                                     {RHS, ConstantInt::get(RHS->getType(), 1)});
   }
-  return InsertBinop(Instruction::UDiv, LHS, RHS, SCEV::FlagAnyWrap,
+  return InsertBinop(Instruction::UDiv, LHS, RHS, SCEV::FlagAny,
                      /*IsSafeToHoist*/ SE.isKnownNonZero(S->getRHS()));
 }
 
@@ -1366,7 +1366,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVUseT<const SCEVAddRecExpr *> S) {
     for (unsigned i = 0, e = S->getNumOperands(); i != e; ++i)
       NewOps[i] = SE.getAnyExtendExpr(S->getOperand(i), CanonicalIV->getType());
     Value *V = expand(
-        SE.getAddRecExpr(NewOps, S->getLoop(), S.getNoWrapFlags(SCEV::FlagNW)));
+        SE.getAddRecExpr(NewOps, S->getLoop(), S.getFlags(SCEV::FlagNW)));
     BasicBlock::iterator NewInsertPt =
         isa<Instruction>(V) ? findInsertPointAfter(cast<Instruction>(V),
                                                    &*Builder.GetInsertPoint())
@@ -1385,13 +1385,12 @@ Value *SCEVExpander::visitAddRecExpr(SCEVUseT<const SCEVAddRecExpr *> S) {
     if (isa<PointerType>(S->getType())) {
       Value *StartV = expand(SE.getPointerBase(S));
       return expandAddToGEP(SE.removePointerBase(S), StartV,
-                            S.getNoWrapFlags(SCEV::FlagNUW));
+                            S.getFlags(SCEV::FlagNUW));
     }
 
     SmallVector<SCEVUse, 4> NewOps(S->operands());
     NewOps[0] = SE.getConstant(Ty, 0);
-    const SCEV *Rest =
-        SE.getAddRecExpr(NewOps, L, S.getNoWrapFlags(SCEV::FlagNW));
+    const SCEV *Rest = SE.getAddRecExpr(NewOps, L, S.getFlags(SCEV::FlagNW));
 
     // Just do a normal add. Pre-expand the operands to suppress folding.
     //
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 0c080d9434ea8..b96ebe1025ead 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -523,7 +523,7 @@ class SCEVAddRecForUniformityRewriter
     const SCEV *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
     const SCEV *NewStart =
         SE.getAddExpr(Expr->getStart(), SCEVUse(ScaledOffset));
-    return SE.getAddRecExpr(NewStart, NewStep, TheLoop, SCEV::FlagAnyWrap);
+    return SE.getAddRecExpr(NewStart, NewStep, TheLoop, SCEV::FlagAny);
   }
 
   const SCEV *visit(const SCEV *S) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 6b2233f606f91..c3841c0a3a3a1 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -140,7 +140,7 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
     if (!L)
       return SE.getCouldNotCompute();
     return SE.getAddRecExpr(SE.getZero(RV->getType()), SE.getOne(RV->getType()),
-                            L, SCEV::FlagAnyWrap);
+                            L, SCEV::FlagAny);
   }
 
   if (isa<VPIRValue, VPSymbolicValue>(V)) {
@@ -167,16 +167,16 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
   VPValue *LHSVal, *RHSVal;
   if (match(V, m_Add(m_VPValue(LHSVal), m_VPValue(RHSVal))))
     return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
-      return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
+      return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAny, 0);
     });
   if (match(V, m_BinaryOr(m_VPValue(LHSVal), m_VPValue(RHSVal))))
     if (cast<VPRecipeWithIRFlags>(V->getDefiningRecipe())->isDisjoint())
       return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
-        return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
+        return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAny, 0);
       });
   if (match(V, m_Sub(m_VPValue(LHSVal), m_VPValue(RHSVal))))
     return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
-      return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
+      return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagAny, 0);
     });
   if (match(V, m_Not(m_VPValue(LHSVal)))) {
     // not X = xor X, -1 = -1 - X
@@ -186,7 +186,7 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
   }
   if (match(V, m_Mul(m_VPValue(LHSVal), m_VPValue(RHSVal))))
     return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
-      return SE.getMulExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
+      return SE.getMulExpr(Ops[0], Ops[1], SCEV::FlagAny, 0);
     });
   // Handle shl by constant: x << c is equivalent to x * (1 << c). A shift
   // amount >= the bit width produces poison; do not rewrite it, as
@@ -321,7 +321,7 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
             const SCEV *Start =
                 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
             const SCEV *AddRec =
-                SE.getAddRecExpr(Start, Step, L, SCEV::FlagAnyWrap);
+                SE.getAddRecExpr(Start, Step, L, SCEV::FlagAny);
             if (R->getTruncInst())
               return SE.getTruncateExpr(AddRec, R->getScalarType());
             return AddRec;
@@ -335,7 +335,7 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
             const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
             if (isa<SCEVCouldNotCompute>(Step))
               return SE.getCouldNotCompute();
-            return SE.getAddRecExpr(Start, Step, L, SCEV::FlagAnyWrap);
+            return SE.getAddRecExpr(Start, Step, L, SCEV::FlagAny);
           })
           .Case([&SE, &PSE, L](const VPDerivedIVRecipe *R) -> const SCEV * {
             const SCEV *Start = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
diff --git a/llvm/unittests/Analysis/IVDescriptorsTest.cpp b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
index 793b909116018..5665cf9bce0de 100644
--- a/llvm/unittests/Analysis/IVDescriptorsTest.cpp
+++ b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
@@ -678,6 +678,6 @@ for.end:
         EXPECT_EQ(Desc.getStepSCEV(), StepSCEV);
 
         // Check we don't add `nuw` when we have a negative GEP step.
-        EXPECT_EQ(Desc.getSCEVNoWrapFlags(), SCEV::FlagAnyWrap);
+        EXPECT_EQ(Desc.getSCEVNoWrapFlags(), SCEV::FlagAny);
       });
 }
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index d362403626387..a3524efdf8fe1 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -430,18 +430,18 @@ TEST_F(ScalarEvolutionsTest, SCEVAddExpr) {
   EXPECT_EQ(AddWithNUW->getNoWrapFlags(), SCEV::FlagNUW);
 
   const SCEV *AddWithAnyWrap =
-      SE.getAddExpr(SE.getSCEV(A3), SE.getSCEV(A4), SCEV::FlagAnyWrap);
+      SE.getAddExpr(SE.getSCEV(A3), SE.getSCEV(A4), SCEV::FlagAny);
   auto *AddWithAnyWrapNUW = cast<SCEVAddExpr>(
       SE.getAddExpr(AddWithAnyWrap, SE.getSCEV(A5), SCEV::FlagNUW));
   EXPECT_EQ(AddWithAnyWrapNUW->getNumOperands(), 3u);
-  EXPECT_EQ(AddWithAnyWrapNUW->getNoWrapFlags(), SCEV::FlagAnyWrap);
+  EXPECT_EQ(AddWithAnyWrapNUW->getNoWrapFlags(), SCEV::FlagAny);
 
   const SCEV *AddWithNSW = SE.getAddExpr(
       SE.getSCEV(A2), SE.getConstant(APInt(32, 99)), SCEV::FlagNSW);
   auto *AddWithNSW_NUW = cast<SCEVAddExpr>(
       SE.getAddExpr(AddWithNSW, SE.getSCEV(A5), SCEV::FlagNUW));
   EXPECT_EQ(AddWithNSW_NUW->getNumOperands(), 3u);
-  EXPECT_EQ(AddWithNSW_NUW->getNoWrapFlags(), SCEV::FlagAnyWrap);
+  EXPECT_EQ(AddWithNSW_NUW->getNoWrapFlags(), SCEV::FlagAny);
 
   const SCEV *AddWithNSWNUW =
       SE.getAddExpr(SE.getSCEV(A2), SE.getSCEV(A4),
@@ -455,7 +455,7 @@ TEST_F(ScalarEvolutionsTest, SCEVAddExpr) {
       SE.getAddExpr(AddWithNSW, SE.getSCEV(A6),
                     ScalarEvolution::setFlags(SCEV::FlagNUW, SCEV::FlagNSW)));
   EXPECT_EQ(AddWithNSW_NSWNUW->getNumOperands(), 3u);
-  EXPECT_EQ(AddWithNSW_NSWNUW->getNoWrapFlags(), SCEV::FlagAnyWrap);
+  EXPECT_EQ(AddWithNSW_NSWNUW->getNoWrapFlags(), SCEV::FlagAny);
 }
 
 static Instruction &GetInstByName(Function &F, StringRef Name) {
@@ -546,12 +546,12 @@ TEST_F(ScalarEvolutionsTest, SCEVNormalization) {
     auto GetAddRec = [&SE](const Loop *L,
                            std::initializer_list<const SCEV *> Ops) {
       SmallVector<SCEVUse, 4> OpsCopy(Ops.begin(), Ops.end());
-      return SE.getAddRecExpr(OpsCopy, L, SCEV::FlagAnyWrap);
+      return SE.getAddRecExpr(OpsCopy, L, SCEV::FlagAny);
     };
 
     auto GetAdd = [&SE](std::initializer_list<const SCEV *> Ops) {
       SmallVector<SCEVUse, 4> OpsCopy(Ops.begin(), Ops.end());
-      return SE.getAddExpr(OpsCopy, SCEV::FlagAnyWrap);
+      return SE.getAddExpr(OpsCopy, SCEV::FlagAny);
     };
 
     // We first populate the AddRecs vector with a few "interesting" SCEV
@@ -781,7 +781,7 @@ TEST_F(ScalarEvolutionsTest, SCEVExitLimitForgetLoop) {
   // that is relevant to this test.
   const SCEV *Five = SE.getConstant(APInt(/*numBits=*/64, 5));
   const SCEV *AR =
-      SE.getAddRecExpr(Five, SE.getOne(T_int64), Loop, SCEV::FlagAnyWrap);
+      SE.getAddRecExpr(Five, SE.getOne(T_int64), Loop, SCEV::FlagAny);
   const SCEV *ARAtLoopExit = SE.getSCEVAtScope(AR, nullptr);
   EXPECT_FALSE(isa<SCEVCouldNotCompute>(ARAtLoopExit));
   EXPECT_TRUE(isa<SCEVConstant>(ARAtLoopExit));
@@ -1309,8 +1309,8 @@ TEST_F(ScalarEvolutionsTest, SCEVUseDropsRedundantFlags) {
     // the flags the use provides stay the same.
     SCEVUse MixedFlags(NUWAdd, SCEV::FlagNUW | SCEV::FlagNSW);
     EXPECT_TRUE(MixedFlags.hasUseFlags());
-    EXPECT_FALSE(any(MixedFlags.getUseNoWrapFlags() & SCEV::FlagNUW));
-    EXPECT_TRUE(any(MixedFlags.getUseNoWrapFlags() & SCEV::FlagNSW));
+    EXPECT_FALSE(any(MixedFlags.getUseFlags() & SCEV::FlagNUW));
+    EXPECT_TRUE(any(MixedFlags.getUseFlags() & SCEV::FlagNSW));
     EXPECT_EQ(MixedFlags.getNoWrapFlags(SCEV::FlagNUW | SCEV::FlagNSW),
               SCEV::FlagNUW | SCEV::FlagNSW);
 
@@ -1330,7 +1330,7 @@ TEST_F(ScalarEvolutionsTest, SCEVUseDropsRedundantFlags) {
     // flags either, while FlagAnyWrap remains fine for them.
     const SCEV *ZExt =
         SE.getZeroExtendExpr(X, Type::getInt64Ty(F.getContext()));
-    EXPECT_FALSE(SCEVUse(ZExt, SCEV::FlagAnyWrap).hasUseFlags());
+    EXPECT_FALSE(SCEVUse(ZExt, SCEV::FlagAny).hasUseFlags());
 #ifndef NDEBUG
     EXPECT_DEATH((void)SCEVUse(ZExt, SCEV::FlagNUW),
                  "use flags require an expression that can carry no-wrap");
@@ -2204,7 +2204,7 @@ TEST_F(ScalarEvolutionsTest, PrintUseFlagsOfOperands) {
     SCEVUse UDiv = SE.getUDivExpr(NUWAdd, NSWAdd4);
     EXPECT_EQ(Rendered(UDiv), "((%a + %b)<u nuw> /u (4 + %a)<u nsw>)");
 
-    SCEVUse AR = SE.getAddRecExpr(NUWAdd, NSWAdd4, L, SCEV::FlagAnyWrap);
+    SCEVUse AR = SE.getAddRecExpr(NUWAdd, NSWAdd4, L, SCEV::FlagAny);
     EXPECT_EQ(Rendered(AR), "{(%a + %b)<u nuw>,+,(4 + %a)<u nsw>}<%loop>");
 
     // Casts print their operand as a use as well.
@@ -2261,8 +2261,8 @@ TEST_F(ScalarEvolutionsTest, OperandUseFlagsArePartOfIdentity) {
     EXPECT_NE(SE.getMulExpr(MulNSW, Z), SE.getMulExpr(Add, Z));
     EXPECT_NE(SE.getUDivExpr(MulNSW, Z), SE.getUDivExpr(Add, Z));
     EXPECT_NE(SE.getUMaxExpr(MulNSW, Z), SE.getUMaxExpr(Add, Z));
-    EXPECT_NE(SE.getAddRecExpr(MulNSW, Z, L, SCEV::FlagAnyWrap),
-              SE.getAddRecExpr(Add, Z, L, SCEV::FlagAnyWrap));
+    EXPECT_NE(SE.getAddRecExpr(MulNSW, Z, L, SCEV::FlagAny),
+              SE.getAddRecExpr(Add, Z, L, SCEV::FlagAny));
     SmallVector<SCEVUse, 2> FlaggedSeqOps = {MulNSW, Z};
     SmallVector<SCEVUse, 2> BareSeqOps = {Add, Z};
     EXPECT_NE(SE.getUMinExpr(FlaggedSeqOps, /*Sequential=*/true),
@@ -2313,7 +2313,7 @@ TEST_F(ScalarEvolutionsTest, CastsOfUsesWithNoWrapFlags) {
     auto CheckCast = [&Add](const SCEV *Cast, const SCEV *Canon) {
       SCEVUse Op = cast<SCEVCastExpr>(Cast)->getOperand();
       EXPECT_EQ(Op.getPointer(), Add.getPointer());
-      EXPECT_EQ(Op.getUseNoWrapFlags(), SCEV::FlagNUW | SCEV::FlagNW);
+      EXPECT_EQ(Op.getUseFlags(), SCEV::FlagNUW | SCEV::FlagNW);
       EXPECT_NE(Cast, Canon);
     };
     CheckCast(SE.getTruncateExpr(NUWAdd, I16), SE.getTruncateExpr(Add, I16));
@@ -2398,25 +2398,25 @@ TEST_F(ScalarEvolutionsTest, AddExprUseFlags) {
     Type *I32 = A->getType();
 
     // The sum is built as-is, so the use carries the requested flags.
-    SCEVUse Sum = SE.getAddExpr(A, B, {SCEV::FlagAnyWrap, SCEV::FlagNUW});
+    SCEVUse Sum = SE.getAddExpr(A, B, {SCEV::FlagAny, SCEV::FlagNUW});
     EXPECT_TRUE(Sum.hasUseFlags());
-    EXPECT_EQ(Sum.getUseNoWrapFlags(), SCEV::FlagNUW | SCEV::FlagNW);
+    EXPECT_EQ(Sum.getUseFlags(), SCEV::FlagNUW | SCEV::FlagNW);
 
     // Same as Sun, but without NUW use flags.
     const SCEV *BareSum = SE.getAddExpr(A, B);
     EXPECT_EQ(Sum.getPointer(), BareSum);
     EXPECT_EQ(cast<SCEVAddExpr>(BareSum)->getNoWrapFlags(SCEV::FlagNUW),
-              SCEV::FlagAnyWrap);
+              SCEV::FlagAny);
     EXPECT_EQ(Sum.getCanonical(), BareSum);
     EXPECT_FALSE(SCEVUse(BareSum).hasUseFlags());
 
     // Operands get sorted by complexity, so their order does not matter.
-    EXPECT_EQ(SE.getAddExpr(B, A, {SCEV::FlagAnyWrap, SCEV::FlagNUW}), Sum);
+    EXPECT_EQ(SE.getAddExpr(B, A, {SCEV::FlagAny, SCEV::FlagNUW}), Sum);
 
     // The same holds for sums of more than two operands.
     SmallVector<SCEVUse, 3> Ops = {Cc, B, A};
-    SCEVUse Sum3 = SE.getAddExpr(Ops, {SCEV::FlagAnyWrap, SCEV::FlagNSW});
-    EXPECT_EQ(Sum3.getUseNoWrapFlags(), SCEV::FlagNSW | SCEV::FlagNW);
+    SCEVUse Sum3 = SE.getAddExpr(Ops, {SCEV::FlagAny, SCEV::FlagNSW});
+    EXPECT_EQ(Sum3.getUseFlags(), SCEV::FlagNSW | SCEV::FlagNW);
     EXPECT_EQ(Sum3.getCanonical(), SE.getAddExpr(A, B, Cc));
 
     // Flags the expression already carries add nothing to the use.
@@ -2429,16 +2429,16 @@ TEST_F(ScalarEvolutionsTest, AddExprUseFlags) {
     // the requested sum, so none of them may carry its flags.
     auto CheckNoUseFlags = [](SCEVUse U) {
       EXPECT_FALSE(U.hasUseFlags());
-      EXPECT_EQ(U.getUseNoWrapFlags(), SCEV::FlagAnyWrap);
+      EXPECT_EQ(U.getUseFlags(), SCEV::FlagAny);
     };
     CheckNoUseFlags(SE.getAddExpr(SE.getConstant(APInt(32, 1)),
                                   SE.getConstant(APInt(32, 2)),
-                                  {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+                                  {SCEV::FlagAny, SCEV::FlagNUW}));
     CheckNoUseFlags(
-        SE.getAddExpr(A, SE.getZero(I32), {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
-    CheckNoUseFlags(SE.getAddExpr(A, SE.getAddExpr(B, Cc),
-                                  {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
-    CheckNoUseFlags(SE.getAddExpr(A, A, {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+        SE.getAddExpr(A, SE.getZero(I32), {SCEV::FlagAny, SCEV::FlagNUW}));
+    CheckNoUseFlags(
+        SE.getAddExpr(A, SE.getAddExpr(B, Cc), {SCEV::FlagAny, SCEV::FlagNUW}));
+    CheckNoUseFlags(SE.getAddExpr(A, A, {SCEV::FlagAny, SCEV::FlagNUW}));
 
     // SCEV flags are valid for all subsets and orders of the operands, so
     // use-specific flags can be preserved when folding constants. the requested
@@ -2446,14 +2446,14 @@ TEST_F(ScalarEvolutionsTest, AddExprUseFlags) {
     SmallVector<SCEVUse, 3> FoldedOps = {SE.getConstant(APInt(32, 1)),
                                          SE.getConstant(APInt(32, 2)), A};
     SCEVUse FoldedSum = SE.getAddExpr(
-        FoldedOps, {SCEV::FlagAnyWrap, SCEV::FlagNUW | SCEV::FlagNSW});
+        FoldedOps, {SCEV::FlagAny, SCEV::FlagNUW | SCEV::FlagNSW});
     EXPECT_EQ(FoldedSum.getCanonical(),
               SE.getAddExpr(SE.getConstant(I32, 3), A));
-    EXPECT_EQ(FoldedSum.getUseNoWrapFlags(),
+    EXPECT_EQ(FoldedSum.getUseFlags(),
               SCEV::FlagNUW | SCEV::FlagNSW | SCEV::FlagNW);
 
 #ifndef NDEBUG
-    EXPECT_DEATH((void)SE.getAddExpr(A, B, {SCEV::FlagAnyWrap, SCEV::FlagNW}),
+    EXPECT_DEATH((void)SE.getAddExpr(A, B, {SCEV::FlagAny, SCEV::FlagNW}),
                  "only nuw or nsw allowed");
 #endif
   });
@@ -2495,25 +2495,25 @@ TEST_F(ScalarEvolutionsTest, MulExprUseFlags) {
     const SCEV *Three = SE.getConstant(I32, 3);
 
     // The product is built as-is, use carries the requested flags.
-    SCEVUse Prod = SE.getMulExpr(A, B, {SCEV::FlagAnyWrap, SCEV::FlagNUW});
+    SCEVUse Prod = SE.getMulExpr(A, B, {SCEV::FlagAny, SCEV::FlagNUW});
     EXPECT_TRUE(Prod.hasUseFlags());
-    EXPECT_EQ(Prod.getUseNoWrapFlags(), SCEV::FlagNUW | SCEV::FlagNW);
+    EXPECT_EQ(Prod.getUseFlags(), SCEV::FlagNUW | SCEV::FlagNW);
 
     // Same as Prod, but without NUW use flags.
     const SCEV *BareProd = SE.getMulExpr(A, B);
     EXPECT_EQ(Prod.getPointer(), BareProd);
     EXPECT_EQ(cast<SCEVMulExpr>(BareProd)->getNoWrapFlags(SCEV::FlagNUW),
-              SCEV::FlagAnyWrap);
+              SCEV::FlagAny);
     EXPECT_EQ(Prod.getCanonical(), BareProd);
     EXPECT_FALSE(SCEVUse(BareProd).hasUseFlags());
 
     // Operands get sorted by complexity, so their order does not matter.
-    EXPECT_EQ(SE.getMulExpr(B, A, {SCEV::FlagAnyWrap, SCEV::FlagNUW}), Prod);
+    EXPECT_EQ(SE.getMulExpr(B, A, {SCEV::FlagAny, SCEV::FlagNUW}), Prod);
 
     // The same holds for products of more than two operands.
     SmallVector<SCEVUse, 3> Ops = {Cc, B, A};
-    SCEVUse Prod3 = SE.getMulExpr(Ops, {SCEV::FlagAnyWrap, SCEV::FlagNSW});
-    EXPECT_EQ(Prod3.getUseNoWrapFlags(), SCEV::FlagNSW | SCEV::FlagNW);
+    SCEVUse Prod3 = SE.getMulExpr(Ops, {SCEV::FlagAny, SCEV::FlagNSW});
+    EXPECT_EQ(Prod3.getUseFlags(), SCEV::FlagNSW | SCEV::FlagNW);
     EXPECT_EQ(Prod3.getCanonical(), SE.getMulExpr(A, B, Cc));
 
     // Flags the expression already carries add nothing to the use.
@@ -2527,32 +2527,31 @@ TEST_F(ScalarEvolutionsTest, MulExprUseFlags) {
     // carry its flags.
     auto CheckNoUseFlags = [](SCEVUse U) {
       EXPECT_FALSE(U.hasUseFlags());
-      EXPECT_EQ(U.getUseNoWrapFlags(), SCEV::FlagAnyWrap);
+      EXPECT_EQ(U.getUseFlags(), SCEV::FlagAny);
     };
+    CheckNoUseFlags(SE.getMulExpr(Two, Three, {SCEV::FlagAny, SCEV::FlagNUW}));
     CheckNoUseFlags(
-        SE.getMulExpr(Two, Three, {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+        SE.getMulExpr(A, SE.getOne(I32), {SCEV::FlagAny, SCEV::FlagNUW}));
     CheckNoUseFlags(
-        SE.getMulExpr(A, SE.getOne(I32), {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+        SE.getMulExpr(A, SE.getZero(I32), {SCEV::FlagAny, SCEV::FlagNUW}));
     CheckNoUseFlags(
-        SE.getMulExpr(A, SE.getZero(I32), {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
-    CheckNoUseFlags(SE.getMulExpr(A, SE.getMulExpr(B, Cc),
-                                  {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+        SE.getMulExpr(A, SE.getMulExpr(B, Cc), {SCEV::FlagAny, SCEV::FlagNUW}));
     CheckNoUseFlags(SE.getMulExpr(Two, SE.getAddExpr(SE.getOne(I32), A),
-                                  {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
-    CheckNoUseFlags(SE.getMulExpr(Two, IV, {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+                                  {SCEV::FlagAny, SCEV::FlagNUW}));
+    CheckNoUseFlags(SE.getMulExpr(Two, IV, {SCEV::FlagAny, SCEV::FlagNUW}));
 
     // SCEV flags are valid for all subsets and orders of the operands, so
     // use-specific flags can be preserved when folding constants.
     SmallVector<SCEVUse, 3> FoldedOps = {Two, Three, A};
     SCEVUse FoldedProd = SE.getMulExpr(
-        FoldedOps, {SCEV::FlagAnyWrap, SCEV::FlagNUW | SCEV::FlagNSW});
+        FoldedOps, {SCEV::FlagAny, SCEV::FlagNUW | SCEV::FlagNSW});
     EXPECT_EQ(FoldedProd.getCanonical(),
               SE.getMulExpr(SE.getConstant(I32, 6), A));
-    EXPECT_EQ(FoldedProd.getUseNoWrapFlags(),
+    EXPECT_EQ(FoldedProd.getUseFlags(),
               SCEV::FlagNUW | SCEV::FlagNSW | SCEV::FlagNW);
 
 #ifndef NDEBUG
-    EXPECT_DEATH((void)SE.getMulExpr(A, B, {SCEV::FlagAnyWrap, SCEV::FlagNW}),
+    EXPECT_DEATH((void)SE.getMulExpr(A, B, {SCEV::FlagAny, SCEV::FlagNW}),
                  "only nuw or nsw allowed");
 #endif
   });
@@ -2600,31 +2599,29 @@ TEST_F(ScalarEvolutionsTest, AddRecExprUseFlags) {
         LI.getLoopFor(getInstructionByName(F, "iv.2")->getParent());
 
     // The recurrence is built as-is, so the use carries the requested flags.
-    SCEVUse AR = SE.getAddRecExpr(A, B, L1, {SCEV::FlagAnyWrap, SCEV::FlagNUW});
+    SCEVUse AR = SE.getAddRecExpr(A, B, L1, {SCEV::FlagAny, SCEV::FlagNUW});
     EXPECT_TRUE(AR.hasUseFlags());
-    EXPECT_EQ(AR.getUseNoWrapFlags(), SCEV::FlagNUW | SCEV::FlagNW);
+    EXPECT_EQ(AR.getUseFlags(), SCEV::FlagNUW | SCEV::FlagNW);
 
     // Same as AR, but without NUW use flags.
-    const SCEV *BareAR = SE.getAddRecExpr(A, B, L1, SCEV::FlagAnyWrap);
+    const SCEV *BareAR = SE.getAddRecExpr(A, B, L1, SCEV::FlagAny);
     EXPECT_EQ(AR.getPointer(), BareAR);
-    EXPECT_EQ(cast<SCEVAddRecExpr>(BareAR)->getNoWrapFlags(),
-              SCEV::FlagAnyWrap);
+    EXPECT_EQ(cast<SCEVAddRecExpr>(BareAR)->getNoWrapFlags(), SCEV::FlagAny);
     EXPECT_EQ(AR.getCanonical(), BareAR);
 
     // Recurrence are not commutative, different operand orders must not re-use
     // UseFlags.
     SCEVUse Swapped =
-        SE.getAddRecExpr(B, A, L1, {SCEV::FlagAnyWrap, SCEV::FlagNSW});
+        SE.getAddRecExpr(B, A, L1, {SCEV::FlagAny, SCEV::FlagNSW});
     EXPECT_NE(Swapped.getPointer(), AR.getPointer());
-    EXPECT_EQ(Swapped.getUseNoWrapFlags(), SCEV::FlagNSW | SCEV::FlagNW);
+    EXPECT_EQ(Swapped.getUseFlags(), SCEV::FlagNSW | SCEV::FlagNW);
 
     // The same holds for recurrences with more than two operands.
     SmallVector<SCEVUse, 3> Ops = {A, B, Cc};
-    SCEVUse AR3 = SE.getAddRecExpr(Ops, L1, {SCEV::FlagAnyWrap, SCEV::FlagNSW});
-    EXPECT_EQ(AR3.getUseNoWrapFlags(), SCEV::FlagNSW | SCEV::FlagNW);
+    SCEVUse AR3 = SE.getAddRecExpr(Ops, L1, {SCEV::FlagAny, SCEV::FlagNSW});
+    EXPECT_EQ(AR3.getUseFlags(), SCEV::FlagNSW | SCEV::FlagNW);
     SmallVector<SCEVUse, 3> BareOps = {A, B, Cc};
-    EXPECT_EQ(AR3.getCanonical(),
-              SE.getAddRecExpr(BareOps, L1, SCEV::FlagAnyWrap));
+    EXPECT_EQ(AR3.getCanonical(), SE.getAddRecExpr(BareOps, L1, SCEV::FlagAny));
 
     // Flags the expression already carries add nothing to the use.
     SCEVUse NUWAR = SE.getAddRecExpr(A, Cc, L1, {SCEV::FlagNUW, SCEV::FlagNUW});
@@ -2636,25 +2633,25 @@ TEST_F(ScalarEvolutionsTest, AddRecExprUseFlags) {
     // different AddRec, so none of them may carry the provided use flags.
     auto CheckNoUseFlags = [](SCEVUse U) {
       EXPECT_FALSE(U.hasUseFlags());
-      EXPECT_EQ(U.getUseNoWrapFlags(), SCEV::FlagAnyWrap);
+      EXPECT_EQ(U.getUseFlags(), SCEV::FlagAny);
     };
     CheckNoUseFlags(SE.getAddRecExpr(A, SE.getZero(I32), L1,
-                                     {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+                                     {SCEV::FlagAny, SCEV::FlagNUW}));
     SmallVector<SCEVUse, 3> OpsWithZeroStep = {A, B, SE.getZero(I32)};
-    CheckNoUseFlags(SE.getAddRecExpr(OpsWithZeroStep, L1,
-                                     {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
-    const SCEV *StepAR = SE.getAddRecExpr(B, Cc, L1, SCEV::FlagAnyWrap);
     CheckNoUseFlags(
-        SE.getAddRecExpr(A, StepAR, L1, {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+        SE.getAddRecExpr(OpsWithZeroStep, L1, {SCEV::FlagAny, SCEV::FlagNUW}));
+    const SCEV *StepAR = SE.getAddRecExpr(B, Cc, L1, SCEV::FlagAny);
+    CheckNoUseFlags(
+        SE.getAddRecExpr(A, StepAR, L1, {SCEV::FlagAny, SCEV::FlagNUW}));
 
     // A zero step folds the recurrence away, use flags must not be applied to
     // the result.
     CheckNoUseFlags(SE.getAddRecExpr(BareAR, SE.getZero(I32), L2,
-                                     {SCEV::FlagAnyWrap, SCEV::FlagNUW}));
+                                     {SCEV::FlagAny, SCEV::FlagNUW}));
 
 #ifndef NDEBUG
     EXPECT_DEATH(
-        (void)SE.getAddRecExpr(A, B, L1, {SCEV::FlagAnyWrap, SCEV::FlagNW}),
+        (void)SE.getAddRecExpr(A, B, L1, {SCEV::FlagAny, SCEV::FlagNW}),
         "only nuw or nsw allowed");
 #endif
   });
diff --git a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
index f2c0ad7d26a3c..c149e76d990a0 100644
--- a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
@@ -669,7 +669,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandInsertCanonicalIV) {
   // Expand {5,+,1}
   auto GetAR2 = [&](ScalarEvolution &SE, Loop *L) -> const SCEV * {
     return SE.getAddRecExpr(SE.getConstant(APInt(ARBitWidth, 5)),
-                            SE.getOne(ARType), L, SCEV::FlagAnyWrap);
+                            SE.getOne(ARType), L, SCEV::FlagAny);
   };
   TestNoCanonicalIV(GetAR2);
   TestNarrowCanonicalIV(GetAR2);
@@ -874,7 +874,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
   auto GetAR3 = [&](ScalarEvolution &SE, Loop *L) -> const SCEVAddRecExpr * {
     SmallVector<SCEVUse, 3> Ops = {SE.getConstant(APInt(ARBitWidth, 5)),
                                    SE.getOne(ARType), SE.getOne(ARType)};
-    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAnyWrap));
+    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAny));
   };
   TestNoCanonicalIV(GetAR3);
   TestNarrowCanonicalIV(GetAR3);
@@ -885,7 +885,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
     SmallVector<SCEVUse, 4> Ops = {SE.getConstant(APInt(ARBitWidth, 5)),
                                    SE.getOne(ARType), SE.getOne(ARType),
                                    SE.getOne(ARType)};
-    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAnyWrap));
+    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAny));
   };
   TestNoCanonicalIV(GetAR4);
   TestNarrowCanonicalIV(GetAR4);
@@ -896,7 +896,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
     SmallVector<SCEVUse, 5> Ops = {SE.getConstant(APInt(ARBitWidth, 5)),
                                    SE.getOne(ARType), SE.getOne(ARType),
                                    SE.getOne(ARType), SE.getOne(ARType)};
-    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAnyWrap));
+    return cast<SCEVAddRecExpr>(SE.getAddRecExpr(Ops, L, SCEV::FlagAny));
   };
   TestNoCanonicalIV(GetAR5);
   TestNarrowCanonicalIV(GetAR5);
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 38943f2557cf2..1ee7c43960373 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1384,7 +1384,7 @@ class SCEVSensitiveParameterRewriter final
     const SCEV *Start = visit(E->getStart());
     const SCEV *AddRec = SE.getAddRecExpr(SE.getConstant(E->getType(), 0),
                                           visit(E->getStepRecurrence(SE)),
-                                          E->getLoop(), SCEV::FlagAnyWrap);
+                                          E->getLoop(), SCEV::FlagAny);
     return SE.getAddExpr(Start, AddRec);
   }
 
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index 50027f898b174..cfbc1010cfa19 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -978,9 +978,9 @@ void IslNodeBuilder::generateCopyStmt(
 Value *IslNodeBuilder::materializeNonScopLoopInductionVariable(const Loop *L) {
   assert(!OutsideLoopIterations.contains(L) &&
          "trying to materialize loop induction variable twice");
-  const SCEV *OuterLIV = SE.getAddRecExpr(SE.getUnknown(Builder.getInt64(0)),
-                                          SE.getUnknown(Builder.getInt64(1)), L,
-                                          SCEV::FlagAnyWrap);
+  const SCEV *OuterLIV =
+      SE.getAddRecExpr(SE.getUnknown(Builder.getInt64(0)),
+                       SE.getUnknown(Builder.getInt64(1)), L, SCEV::FlagAny);
   Value *V = generateSCEV(OuterLIV);
   OutsideLoopIterations[L] = SE.getUnknown(V);
   return V;
diff --git a/polly/lib/Support/SCEVAffinator.cpp b/polly/lib/Support/SCEVAffinator.cpp
index 07155486bd1e1..cf1a0843f2c81 100644
--- a/polly/lib/Support/SCEVAffinator.cpp
+++ b/polly/lib/Support/SCEVAffinator.cpp
@@ -59,10 +59,10 @@ static bool isTooComplex(PWACtx PWAC) {
 }
 
 /// Return the flag describing the possible wrapping of @p Expr.
-static SCEV::NoWrapFlags getNoWrapFlags(const SCEV *Expr) {
+static SCEVFlags getNoWrapFlags(const SCEV *Expr) {
   if (auto *NAry = dyn_cast<SCEVNAryExpr>(Expr))
-    return NAry->getNoWrapFlags();
-  return SCEV::NoWrapMask;
+    return NAry->getFlags();
+  return SCEV::NoFlagMask;
 }
 
 static PWACtx combine(PWACtx PWAC0, PWACtx PWAC1,
@@ -404,7 +404,7 @@ PWACtx SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) {
 PWACtx SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) {
   assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
 
-  auto Flags = Expr->getNoWrapFlags();
+  auto Flags = Expr->getFlags();
 
   // Directly generate isl_pw_aff for Expr if 'start' is zero.
   if (Expr->getStart()->isZero()) {
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index ad62406d85e7e..ff3a10c4a1c2e 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -269,7 +269,7 @@ class SCEVValidator : public SCEVVisitor<SCEVValidator, ValidatorResult> {
     // if 'start' is not zero.
     const SCEV *ZeroStartExpr = SE.getAddRecExpr(
         SE.getConstant(Expr->getStart()->getType(), 0),
-        Expr->getStepRecurrence(SE), Expr->getLoop(), Expr->getNoWrapFlags());
+        Expr->getStepRecurrence(SE), Expr->getLoop(), Expr->getFlags());
 
     ValidatorResult ZeroStartResult =
         ValidatorResult(SCEVType::PARAM, ZeroStartExpr);
@@ -687,9 +687,8 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
     const SCEV *StartExpr = AddRec->getStart();
     if (StartExpr->isZero()) {
       auto StepPair = extractConstantFactor(AddRec->getStepRecurrence(SE), SE);
-      const SCEV *LeftOverAddRec =
-          SE.getAddRecExpr(StartExpr, StepPair.second, AddRec->getLoop(),
-                           AddRec->getNoWrapFlags());
+      const SCEV *LeftOverAddRec = SE.getAddRecExpr(
+          StartExpr, StepPair.second, AddRec->getLoop(), AddRec->getFlags());
       return std::make_pair(StepPair.first, LeftOverAddRec);
     }
     return std::make_pair(ConstPart, S);
@@ -717,7 +716,7 @@ polly::extractConstantFactor(const SCEV *S, ScalarEvolution &SE) {
         return std::make_pair(ConstPart, S);
     }
 
-    const SCEV *NewAdd = SE.getAddExpr(LeftOvers, Add->getNoWrapFlags());
+    const SCEV *NewAdd = SE.getAddExpr(LeftOvers, Add->getFlags());
     return std::make_pair(Factor, NewAdd);
   }
 
diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp
index 20473c231341f..6fb8086c60d59 100644
--- a/polly/lib/Support/ScopHelper.cpp
+++ b/polly/lib/Support/ScopHelper.cpp
@@ -433,7 +433,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
     const Loop *L = E->getLoop();
     const SCEV *GenLRepl = LoopMap ? LoopMap->lookup(L) : nullptr;
     if (!GenLRepl)
-      return GenSE.getAddRecExpr(NewOps, L, E->getNoWrapFlags());
+      return GenSE.getAddRecExpr(NewOps, L, E->getFlags());
 
     // evaluateAtIteration replaces the SCEVAddrExpr with a direct calculation.
     const SCEV *Evaluated =



More information about the llvm-commits mailing list