1+ /*
2+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation.
8+ *
9+ * This code is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+ * version 2 for more details (a copy is included in the LICENSE file that
13+ * accompanied this code).
14+ *
15+ * You should have received a copy of the GNU General Public License version
16+ * 2 along with this work; if not, write to the Free Software Foundation,
17+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+ *
19+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+ * or visit www.oracle.com if you need additional information or have any
21+ * questions.
22+ */
23+
24+ /*
25+ * @test
26+ * @bug 8371558
27+ * @summary An expression of the form "abs(0-x)" should be transformed to "abs(x)".
28+ * This test ensures that updates to the Sub node’s inputs propagate as
29+ * expected and that the optimization is not missed.
30+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -Xcomp
31+ * -XX:CompileCommand=compileonly,compiler.c2.TestMissingOptAbsZeroMinusX::test*
32+ * -XX:VerifyIterativeGVN=1110 compiler.c2.TestMissingOptAbsZeroMinusX
33+ * @run main compiler.c2.TestMissingOptAbsZeroMinusX
34+ *
35+ */
36+
37+ package compiler .c2 ;
38+
39+ public class TestMissingOptAbsZeroMinusX {
40+ static int a ;
41+ static boolean b ;
42+
43+ public static void main (String [] strArr ) {
44+ // no known reproducer for AbsL
45+ testAbsI ();
46+ testAbsF ();
47+ testAbsD ();
48+ }
49+
50+ static void testAbsI () {
51+ int d = 4 ;
52+ for (int i = 8 ; i < 133 ; i += 3 ) {
53+ d -= a ;
54+ b = (d != Math .abs (d ));
55+ for (long f = 3 ; f < 127 ; f ++) {
56+ for (int e = 1 ; e < 3 ; e ++) {}
57+ }
58+ d = 0 ;
59+ }
60+ }
61+
62+ static void testAbsF () {
63+ float d = 12.3f ;
64+ for (int i = 8 ; i < 133 ; i += 3 ) {
65+ d -= a ;
66+ b = (d != Math .abs (d ));
67+ for (long f = 3 ; f < 127 ; f ++) {
68+ for (int e = 1 ; e < 3 ; e ++) {}
69+ }
70+ d = 0.0f ;
71+ }
72+ }
73+
74+ static void testAbsD () {
75+ double d = 12.3 ;
76+ for (int i = 8 ; i < 133 ; i += 3 ) {
77+ d -= a ;
78+ b = (d != Math .abs (d ));
79+ for (long f = 3 ; f < 127 ; f ++) {
80+ for (int e = 1 ; e < 3 ; e ++) {}
81+ }
82+ d = 0.0 ;
83+ }
84+ }
85+ }
0 commit comments