[llvm] [SCEV] Move NoWrapFlags definition outside SCEV scope, use for SCEVUse. (PR #190199)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 08:59:26 PDT 2026
================
@@ -66,19 +66,66 @@ enum SCEVTypes : unsigned short;
LLVM_ABI extern bool VerifySCEV;
+/// NoWrapFlags are bitfield indices into SCEV's SubclassData.
+///
+/// Add and Mul expressions may have no-unsigned-wrap <NUW> or
+/// no-signed-wrap <NSW> properties, which are derived from the IR
+/// operator. NSW is a misnomer that we use to mean no signed overflow or
+/// underflow.
+///
+/// AddRec expressions may have a no-self-wraparound <NW> property if, in
+/// the integer domain, abs(step) * max-iteration(loop) <=
+/// unsigned-max(bitwidth). This means that the recurrence will never reach
+/// its start value if the step is non-zero. Computing the same value on
+/// each iteration is not considered wrapping, and recurrences with step = 0
+/// are trivially <NW>. <NW> is independent of the sign of step and the
+/// value the add recurrence starts with.
+///
+/// Note that NUW and NSW are also valid properties of a recurrence, and
+/// either implies NW. For convenience, NW will be set for a recurrence
+/// whenever either NUW or NSW are set.
+///
+/// We require that the flag on a SCEV apply to the entire scope in which
+/// that SCEV is defined. A SCEV's scope is set of locations dominated by
+/// a defining location, which is in turn described by the following rules:
+/// * A SCEVUnknown is at the point of definition of the Value.
+/// * A SCEVConstant is defined at all points.
+/// * A SCEVAddRec is defined starting with the header of the associated
+/// loop.
+/// * All other SCEVs are defined at the earlest point all operands are
+/// defined.
+///
+/// The above rules describe a maximally hoisted form (without regards to
+/// potential control dependence). A SCEV is defined anywhere a
+/// corresponding instruction could be defined in said maximally hoisted
+/// form. Note that SCEVUDivExpr (currently the only expression type which
+/// 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.
+namespace SCEVWrap {
+enum NoWrapFlags {
----------------
nikic wrote:
namespace + enum is a bit weird. Can we make this `enum class SCEVNoWrapFlags` or so?
https://github.com/llvm/llvm-project/pull/190199
More information about the llvm-commits
mailing list