Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8325995

Fold simple comparisons of add/sub

XMLWordPrintable

      For example, we can fold `x - 1 < x` -> `true`, if we can prove that `x - 1` does not overflow.

      This is a very common pattern:

      ```
      for (i = 0; i < arr.length; ++i) {
        foo(arr[i])
      }
      ```

      We hoist out loop predicate:
      ```
      if (arr.length - 1 >= arr.length) { trap(); }
      for (i = 0; i < arr.length; ++i) {
        foo(arr[i])
      }
      ```

      We know `arr.length - 1` never overflows because `arr.length` is non-negative. We can fold away that check.

            jcao Joshua Cao
            jcao Joshua Cao
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: