New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8273021: C2: Improve Add and Xor ideal optimizations #5266
Changes from 5 commits
159f3ca
2f6ceb3
ff3087a
7bfda74
e8a930b
aee3a8b
cceb061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2021, Alibaba Group Holding Limited. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8273021 | ||
* @summary C2: Improve Add and Xor ideal optimizations | ||
* @library /test/lib | ||
* @run main/othervm -XX:-TieredCompilation -XX:TieredStopAtLevel=4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* -XX:CompileCommand=dontinline,compiler.c2.TestAddXorIdeal::test* | ||
* compiler.c2.TestAddXorIdeal | ||
*/ | ||
package compiler.c2; | ||
|
||
import java.util.Random; | ||
|
||
import jdk.test.lib.Asserts; | ||
|
||
public class TestAddXorIdeal { | ||
|
||
public static int test1(int x) { | ||
return ~x + 1; | ||
} | ||
|
||
public static int test2(int x) { | ||
return ~(x - 1); | ||
} | ||
|
||
public static long test3(long x) { | ||
return ~x + 1L; | ||
} | ||
|
||
public static long test4(long x) { | ||
return ~(x - 1L); | ||
} | ||
|
||
public static int test5(int x) { | ||
return 1 + ~x; | ||
} | ||
|
||
public static int test6(int x) { | ||
return ~(-1 + x); | ||
} | ||
|
||
public static long test7(long x) { | ||
return 1L + ~x; | ||
} | ||
|
||
public static long test8(long x) { | ||
return ~(-1L + x); | ||
} | ||
|
||
public static void main(String... args) { | ||
Random random = new Random(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That does make sense. Changed. |
||
int n = 0; | ||
long n1 = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be declared in the loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean declared within loop body? I've changed but it looks like a perference problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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). The declaration does not affect performance. Here's how I would write the loop to improve readability:
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 But these are just code style details, feel free to ignore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for patient. I agree with your comment that using 0 as initial value and increasing iterations. :) I try to use |
||
for (int i = -5_000; i < 5_000; i++) { | ||
n = random.nextInt(); | ||
Asserts.assertTrue(test1(i + n) == -(i + n)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you are using random numbers, can't you simply check |
||
n = random.nextInt(); | ||
Asserts.assertTrue(test2(i - n) == -(i - n)); | ||
n1 = random.nextLong(); | ||
Asserts.assertTrue(test3(i + n1) == -(i + n1)); | ||
n1 = random.nextLong(); | ||
Asserts.assertTrue(test4(i - n1) == -(i - n1)); | ||
n = random.nextInt(); | ||
Asserts.assertTrue(test5(i + n) == -(i + n)); | ||
n = random.nextInt(); | ||
Asserts.assertTrue(test6(i - n) == -(i - n)); | ||
n1 = random.nextLong(); | ||
Asserts.assertTrue(test7(i + n1) == -(i + n1)); | ||
n1 = random.nextLong(); | ||
Asserts.assertTrue(test8(i - n1) == -(i - n1)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test needs
* @key randomness