[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 20:41:34 PST 2023


mkazantsev requested changes to this revision.
mkazantsev added inline comments.
This revision now requires changes to proceed.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:15077
+    //  '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)',
----------------
This is not correct (`c + 1` may overflow). Why didn't you just keep it as 
```
//  'min(a, b) >  c'   ->   '(a > c) && (b > c)';
```
?


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:15079
+    //  '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
----------------
Same


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:15121
+      default:
+        llvm_unreachable("Unexpected expression type");
+      }
----------------
Why do you think that eq/ne cannot come here?


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:15144
+    case CmpInst::ICMP_SLT: {
+      const SCEV *RHSMinusOne = getMinusSCEV(RHS, getOne(RHS->getType()));
+      // smax(a, b) <s c -> (a <=s c - 1) && (b <=s c - 1)
----------------
Bug when `RHS = SINT_MIN`.


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

https://reviews.llvm.org/D145230



More information about the llvm-commits mailing list