Skip to content

Commit 845d43a

Browse files
author
Fei Gao
committed
Add a case in the C2 IR test framework
Change-Id: Ia2372ed06fcc7c88285461a1b013898d9327c18e
1 parent 7430320 commit 845d43a

File tree

7 files changed

+245
-164
lines changed

7 files changed

+245
-164
lines changed

src/hotspot/share/opto/subnode.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1899,11 +1899,7 @@ Node* AbsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
18991899
Node* in1 = in(1);
19001900
// Convert "abs(0-x)" into "abs(x)"
19011901
if (in1->is_Sub() && phase->type(in1->in(1))->is_zero_type()) {
1902-
set_req(1, in1->in(2));
1903-
PhaseIterGVN* igvn = phase->is_IterGVN();
1904-
if (igvn) {
1905-
igvn->_worklist.push(in1);
1906-
}
1902+
set_req_X(1, in1->in(2), phase);
19071903
return this;
19081904
}
19091905
return NULL;

src/hotspot/share/opto/subnode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it

src/hotspot/share/opto/type.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it

test/hotspot/jtreg/compiler/c2/TestAbs.java

Lines changed: 4 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -21,151 +21,17 @@
2121
* questions.
2222
*/
2323

24+
package compiler.c2;
25+
2426
/*
2527
* @test
26-
* @bug 8248445 8276673
27-
* @summary Abs nodes detection and optimization in C2
28-
* @library /test/lib
28+
* @bug 8248445
29+
* @summary Use of AbsI / AbsL nodes should be limited to supported platforms
2930
* @requires vm.debug == true
3031
*
3132
* @run main/othervm -XX:-TieredCompilation -Xbatch -XX:CompileOnly=java.lang.Math::abs compiler.c2.TestAbs
32-
* @run main/othervm -XX:-TieredCompilation compiler.c2.TestAbs
3333
*/
34-
35-
package compiler.c2;
36-
import jdk.test.lib.Asserts;
37-
3834
public class TestAbs {
39-
private static int SIZE = 500;
40-
41-
public static char [] cspecial = {
42-
0, 42, 128, 256, 1024, 4096, 65535
43-
};
44-
45-
public static int [] ispecial = {
46-
0, Integer.MAX_VALUE, Integer.MIN_VALUE, -42, 42, -1, 1
47-
};
48-
49-
public static long [] lspecial = {
50-
0, Long.MAX_VALUE, Long.MIN_VALUE, -42, 42, -1, 1
51-
};
52-
53-
public static float [] fspecial = {
54-
0.0f,
55-
-0.0f,
56-
Float.MAX_VALUE,
57-
Float.MIN_VALUE,
58-
-Float.MAX_VALUE,
59-
-Float.MIN_VALUE,
60-
Float.NaN,
61-
Float.POSITIVE_INFINITY,
62-
Float.NEGATIVE_INFINITY,
63-
Integer.MAX_VALUE,
64-
Integer.MIN_VALUE,
65-
Long.MAX_VALUE,
66-
Long.MIN_VALUE,
67-
-1.0f,
68-
1.0f,
69-
-42.0f,
70-
42.0f
71-
};
72-
73-
public static double [] dspecial = {
74-
0.0,
75-
-0.0,
76-
Double.MAX_VALUE,
77-
Double.MIN_VALUE,
78-
-Double.MAX_VALUE,
79-
-Double.MIN_VALUE,
80-
Double.NaN,
81-
Double.POSITIVE_INFINITY,
82-
Double.NEGATIVE_INFINITY,
83-
Integer.MAX_VALUE,
84-
Integer.MIN_VALUE,
85-
Long.MIN_VALUE,
86-
Long.MAX_VALUE,
87-
-1,
88-
1,
89-
42,
90-
-42,
91-
Math.PI,
92-
Math.E,
93-
Float.MAX_VALUE,
94-
Float.MIN_VALUE,
95-
-Float.MAX_VALUE,
96-
-Float.MIN_VALUE,
97-
Float.NaN,
98-
Float.POSITIVE_INFINITY,
99-
Float.NEGATIVE_INFINITY
100-
};
101-
102-
public static void testAbsConstant() {
103-
// Test abs(constant) optimization for int
104-
Asserts.assertEquals(Integer.MAX_VALUE, Math.abs(Integer.MAX_VALUE));
105-
Asserts.assertEquals(Integer.MIN_VALUE, Math.abs(Integer.MIN_VALUE));
106-
Asserts.assertEquals(Integer.MAX_VALUE, Math.abs(-Integer.MAX_VALUE));
107-
108-
// Test abs(constant) optimization for long
109-
Asserts.assertEquals(Long.MAX_VALUE, Math.abs(Long.MAX_VALUE));
110-
Asserts.assertEquals(Long.MIN_VALUE, Math.abs(Long.MIN_VALUE));
111-
Asserts.assertEquals(Long.MAX_VALUE, Math.abs(-Long.MAX_VALUE));
112-
113-
// Test abs(constant) optimization for float
114-
Asserts.assertEquals(Float.NaN, Math.abs(Float.NaN));
115-
Asserts.assertEquals(Float.POSITIVE_INFINITY, Math.abs(Float.NEGATIVE_INFINITY));
116-
Asserts.assertEquals(Float.POSITIVE_INFINITY, Math.abs(Float.POSITIVE_INFINITY));
117-
Asserts.assertEquals(0.0f, Math.abs(0.0f));
118-
Asserts.assertEquals(0.0f, Math.abs(-0.0f));
119-
Asserts.assertEquals(Float.MAX_VALUE, Math.abs(Float.MAX_VALUE));
120-
Asserts.assertEquals(Float.MIN_VALUE, Math.abs(Float.MIN_VALUE));
121-
Asserts.assertEquals(Float.MAX_VALUE, Math.abs(-Float.MAX_VALUE));
122-
Asserts.assertEquals(Float.MIN_VALUE, Math.abs(-Float.MIN_VALUE));
123-
124-
// Test abs(constant) optimization for double
125-
Asserts.assertEquals(Double.NaN, Math.abs(Double.NaN));
126-
Asserts.assertEquals(Double.POSITIVE_INFINITY, Math.abs(Double.NEGATIVE_INFINITY));
127-
Asserts.assertEquals(Double.POSITIVE_INFINITY, Math.abs(Double.POSITIVE_INFINITY));
128-
Asserts.assertEquals(0.0, Math.abs(0.0));
129-
Asserts.assertEquals(0.0, Math.abs(-0.0));
130-
Asserts.assertEquals(Double.MAX_VALUE, Math.abs(Double.MAX_VALUE));
131-
Asserts.assertEquals(Double.MIN_VALUE, Math.abs(Double.MIN_VALUE));
132-
Asserts.assertEquals(Double.MAX_VALUE, Math.abs(-Double.MAX_VALUE));
133-
Asserts.assertEquals(Double.MIN_VALUE, Math.abs(-Double.MIN_VALUE));
134-
}
135-
136-
private static void testAbsTransformInt(int[] a) {
137-
for (int i = 0; i < a.length; i++) {
138-
Asserts.assertEquals(Math.abs(Math.abs(a[i])), Math.abs(a[i]));
139-
Asserts.assertEquals(Math.abs(0 - a[i]), Math.abs(a[i]));
140-
}
141-
}
142-
143-
private static void testAbsTransformLong(long[] a) {
144-
for (int i = 0; i < a.length; i++) {
145-
Asserts.assertEquals(Math.abs(Math.abs(a[i])), Math.abs(a[i]));
146-
Asserts.assertEquals(Math.abs(0 - a[i]), Math.abs(a[i]));
147-
}
148-
}
149-
150-
private static void testAbsTransformFloat(float[] a) {
151-
for (int i = 0; i < a.length; i++) {
152-
Asserts.assertEquals(Math.abs(Math.abs(a[i])), Math.abs(a[i]));
153-
Asserts.assertEquals(Math.abs(0 - a[i]), Math.abs(a[i]));
154-
}
155-
}
156-
157-
private static void testAbsTransformDouble(double[] a) {
158-
for (int i = 0; i < a.length; i++) {
159-
Asserts.assertEquals(Math.abs(Math.abs(a[i])), Math.abs(a[i]));
160-
Asserts.assertEquals(Math.abs(0 - a[i]), Math.abs(a[i]));
161-
}
162-
}
163-
164-
private static void testAbsOptChar(char[] a) {
165-
for (int i = 0; i < a.length; i++) {
166-
Asserts.assertEquals(a[i], (char) Math.abs(a[i]));
167-
}
168-
}
16935

17036
public static void test() {
17137
// java.lang.Math.abs() collapses into AbsI/AbsL nodes on platforms that support the correspondent nodes
@@ -179,20 +45,7 @@ public static void test() {
17945
public static void main(String args[]) {
18046
for (int i = 0; i < 20_000; i++) {
18147
test();
182-
183-
testAbsConstant();
184-
185-
// Verify abs(abs(x)) = abs(x) for all types
186-
// Verify abs(0-x) = abs(x) for all types
187-
testAbsTransformInt(ispecial);
188-
testAbsTransformLong(lspecial);
189-
testAbsTransformFloat(fspecial);
190-
testAbsTransformDouble(dspecial);
191-
192-
// Verify abs(non-negative_value) = non-negative_value
193-
testAbsOptChar(cspecial);
19448
}
195-
19649
}
19750
}
19851

0 commit comments

Comments
 (0)