[PATCH] D109553: [SCEV] Attempt to define what flags are legal on a SCEV

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 9 15:54:27 PDT 2021


reames created this revision.
reames added reviewers: efriedma, nikic, mkazantsev, skatkov, lebedev.ri, fhahn.
Herald added subscribers: bollu, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

This is a comment only change, inspired by the discussion on D106852 <https://reviews.llvm.org/D106852>.

This is my attempt to define what the current semantics are closest too.  The existence of D106852 <https://reviews.llvm.org/D106852> does imply these semantics are not 100% correct, but that piece of code is the only place I can find in current code which violates them.

If we accept these semantics, then the resolution to D106852 <https://reviews.llvm.org/D106852> becomes obvious, if painful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109553

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h


Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -112,6 +112,25 @@
   /// 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 describes 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 no earlier than the header of the associated
+  ///   loop.  If any operand is loop varying (per these definition rules),
+  ///   than the SCEVAddRec is defined only after all operands are defined.
+  /// * 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 existance of any
+  /// instruction within the defined scope.
   enum NoWrapFlags {
     FlagAnyWrap = 0,    // No guarantee.
     FlagNW = (1 << 0),  // No self-wrap.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109553.371739.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210909/b7ec683b/attachment.bin>


More information about the llvm-commits mailing list