RFR: 8273021: C2: Improve Add and Xor ideal optimizations [v3]
Yi Yang
yyang at openjdk.java.net
Fri Sep 10 07:36:00 UTC 2021
On Fri, 10 Sep 2021 06:14:57 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:
>> Do you mean declared within loop body? I've changed but it looks like a perference problem.
>
> Yes, in Java, local variables should be declared as close as possible to the point they are first used at (see, for example, [Google's Java Style Guide](https://google.github.io/styleguide/javaguide.html#s4.8.2-variable-declarations)). The declaration does not affect performance.
>
> Here's how I would write the loop to improve readability:
>
> for (int j = 0; j < 50_000; j++) {
> int i = random.nextInt();
> long l = random.nextLong();
> Asserts.assertTrue(test1(i) == -i);
> Asserts.assertTrue(test2(i) == -i);
> Asserts.assertTrue(test3(l) == -l);
> ...
>
> Summary: No need to use negative initial value for loop induction variable (as it is not even used), increase number of iterations to ensure C2 compilation (you are running without `-Xbatch`), use same random numbers per loop iteration, use more intuitive variable names.
>
> But these are just code style details, feel free to ignore.
Thanks for patient. I agree with your comment that using 0 as initial value and increasing iterations. :)
I try to use `a` and `b` as variable names since `long l` looks like `long 1`
-------------
PR: https://git.openjdk.java.net/jdk/pull/5266
More information about the hotspot-compiler-dev
mailing list