[PATCH] D145230: [ScalarEvolution] Apply loop guards against min/max for its arguments

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 21:16:43 PST 2023


mkazantsev added inline comments.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:15074-15081
+    // If \p Expr is a min/max expression, adds a pair of rewrites of its
+    // arguments based on the following rules:
+    //  'min(a, b) >= c'   ->   '(a >= c) && (b >= c)',
+    //  'min(a, b) >  c'   ->   '(a >= c + 1) && (b >= c + 1)',
+    //  'max(a, b) <= c'   ->   '(a <= c) && (b <= c)',
+    //  'max(a, b) <  c'   ->   '(a <= c - 1) && (b <= c - 1)'.
+    // \p RHS has to be either the unchanged RHS of the current guard, or plus
----------------
This comment is out of place. You are not constructing `c + 1` or `c - 1` here, it is done in the caller code. Here enough to say that
```
min(a, b) > c     ->   (a > c) && (b > c); // same for >=
max(a, b) < c     ->   (a < c) && (b < c); // same for <=
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145230/new/

https://reviews.llvm.org/D145230



More information about the llvm-commits mailing list