RFR: 8276162: Optimise unsigned comparison pattern
Mai Đặng Quân Anh
duke at openjdk.java.net
Fri Oct 29 09:48:34 UTC 2021
On Mon, 25 Oct 2021 10:15:42 GMT, Mai Đặng Quân Anh <duke at openjdk.java.net> wrote:
> This patch changes operations in the form `x +- Integer.MIN_VALUE <=> y +- Integer.MIN_VALUE`, which is a pattern used to do unsigned comparisons, into `x u<=> y`.
>
> In addition to being basic operations, they may be utilised to implement range checks such as the methods in `jdk.internal.util.Preconditions`, or in places where the compiler cannot deduce the non-negativeness of the bound as in `java.util.ArrayList`.
>
> Thank you very much.
I created a simple benchmark, the benchmark is run on Intel i7-7700HQ, the result is as follow:
Before:
Benchmark Mode Cnt Score Error Units
App.runInt avgt 25 3.963 ± 0.181 ns/op
App.runLong avgt 25 4.431 ± 0.101 ns/op
After:
Benchmark Mode Cnt Score Error Units
App.runInt avgt 25 3.678 ± 0.192 ns/op
App.runLong avgt 25 3.814 ± 0.085 ns/op
This is the source code of the benchmark:
package io.github.merykitty.simplebenchmark;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
@BenchmarkMode(Mode.AverageTime)
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public class App {
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public long test(int arg0, int arg1) {
return arg0 + Integer.MIN_VALUE < arg1 + Integer.MIN_VALUE ? 1 : 0;
}
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public long test(long arg0, long arg1) {
return arg0 + Long.MIN_VALUE < arg1 + Long.MIN_VALUE ? 1 : 0;
}
@Benchmark
public void runInt() {
test(0, -1);
test(-1, 0);
}
@Benchmark
public void runLong() {
test(0L, -1L);
test(-1L, 0L);
}
public static void main( String[] args ) throws IOException {
org.openjdk.jmh.Main.main(args);
}
}
Do I need to add the benchmark to the patch? If yes then where should I put it in?
Thank you very much.
I have just pushed the microbenchmark, I am not sure what to put in the copyright line, though.
The check failure seems to be due to this PR does not refer to an existing issue.
Thank you very much.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6101
More information about the hotspot-compiler-dev
mailing list