On Tue, 12 May 2026 14:38:09 GMT, Kangcheng Xu <[email protected]> wrote:

> Hi,
> 
> This PR adds intrinsics to `Preconditions.checkFromToIndex()` and 
> `Preconditions.checkFromIndexSize()` to produced optimized IR that uses 
> `RangeCheck` node instead of implicit comparisons. 
> `Preconditions.checkIndex()` is also refactored (without additional 
> optimizations) to use the same helper function.
> 
> Some common patterns where calling `checkFromToIndex` or `checkFromIndexSize` 
> in a loop can have range checks in main loop eliminated completely and, 
> therefore, enables empty loop removal.
> 
> IR and correctness tests are included and passing. Additional tests on 
> `Preconditions.checkIndex()` were also added.
> 
> Thanks!
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

![micro 
benchmark](https://github.com/user-attachments/assets/011846ce-bc4b-4d2c-b8b3-d4d6b157a437)

In terms of benchmark, I've observed the following:

1. a significant higher throughput for `checkFromToIndex()` and 
`checkFromIndexSize()` cases. Range checks are successfully hoisted out and 
eliminated where possible. 
2. One-check-before-loop and array-copy are baseline tests. They shows 
intrinsification doesn't introduce regression when it can't benefit from range 
check removals, and both implementations are on par. 
3. interestingly, `checkIndex()` is slightly worse with the refactor, but they 
even out as the number of operations scale.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/31138#issuecomment-5343235738

Reply via email to