[llvm] c4048d8 - [SCEV] Attempt to define what flags are legal on a SCEV

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 14 13:13:55 PDT 2021


Author: Philip Reames
Date: 2021-09-14T13:13:49-07:00
New Revision: c4048d8f50aaf2c4c13b8d3e138abc34a22da754

URL: https://github.com/llvm/llvm-project/commit/c4048d8f50aaf2c4c13b8d3e138abc34a22da754
DIFF: https://github.com/llvm/llvm-project/commit/c4048d8f50aaf2c4c13b8d3e138abc34a22da754.diff

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

This is an attempt to define what the current semantics are closest too.  Unfortunately, the current implementation does appear to be inconsistent with all semantic variants we've considered.  This semantics is the one which seems to be closest to the spirit of the code, and that matched several long time contributors mental models of how the code "should work".

https://bugs.llvm.org/show_bug.cgi?id=51817 tracks the list of currently known violations of these rules.  A series of follow up patches will be addressing each now that we've defined them to be bugs.

Differential Revision: https://reviews.llvm.org/D109553

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 098a076536f6d..feb867a66a509 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -112,6 +112,24 @@ class SCEV : public FoldingSetNode {
   /// 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.
   enum NoWrapFlags {
     FlagAnyWrap = 0,    // No guarantee.
     FlagNW = (1 << 0),  // No self-wrap.


        


More information about the llvm-commits mailing list