--- old/src/hotspot/share/opto/loopTransform.cpp 2019-08-21 16:33:55.327800773 +0800 +++ new/src/hotspot/share/opto/loopTransform.cpp 2019-08-21 16:33:55.215798859 +0800 @@ -831,6 +831,15 @@ return false; } + // Protect against over-unrolling with SuperWordLoopUnrollAnalysis. + if (SuperWordLoopUnrollAnalysis && + !cl->is_vectorized_loop() && + future_unroll_cnt > LoopUnrollMin && + cl->profile_trip_cnt() != COUNT_UNKNOWN && + (uint)(2 * cl->unrolled_count()) > cl->trip_count()) { + return false; + } + Node *init_n = cl->init_trip(); Node *limit_n = cl->limit(); int stride_con = cl->stride_con(); --- /dev/null 2019-08-21 16:04:56.746381791 +0800 +++ new/test/hotspot/jtreg/compiler/loopopts/superword/RunTestSuperWordOverunrolling.java 2019-08-21 16:33:55.487803508 +0800 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019, Loongson Technology Co. Ltd. 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 8227505 + * @summary SuperWordLoopUnrollAnalysis may over unrolling + * @library /test/lib + * @compile TestSuperWordOverunrolling.java + * @run main/othervm compiler.loopopts.superword.RunTestSuperWordOverunrolling + * + */ + +package compiler.loopopts.superword; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class RunTestSuperWordOverunrolling { + + public static void main(String[] args) throws Exception { + test(); + } + + private static void test() throws Exception { + ProcessBuilder pb; + OutputAnalyzer analyzer; + pb = ProcessTools.createJavaProcessBuilder("-XX:+IgnoreUnrecognizedVMOptions", + "-Xbatch", + "-XX:+TraceLoopOpts", + "-XX:-TieredCompilation", + "-XX:CompileCommand=quiet", + "-XX:CompileOnly=compiler.loopopts.superword.TestSuperWordOverunrolling::execute", + "compiler.loopopts.superword.TestSuperWordOverunrolling"); + analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldNotContain("Unroll 16"); + } +} --- /dev/null 2019-08-21 16:04:56.746381791 +0800 +++ new/test/hotspot/jtreg/compiler/loopopts/superword/TestSuperWordOverunrolling.java 2019-08-21 16:33:55.771808362 +0800 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019, Loongson Technology Co. Ltd. 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. + */ + +package compiler.loopopts.superword; + +public class TestSuperWordOverunrolling { + public static void main(String[] args) { + double sum = 0.0; + long start = System.currentTimeMillis(); + for (int i = 0; i < 5; i++) { + sum += execute(128); + } + long end = System.currentTimeMillis(); + System.out.println("sum = " + sum + "; time = " + (end - start) + "ms"); + } + + public static double execute(int num_iterations) { + int M = 63; + byte[][] G = new byte[M][M]; + + int Mm1 = M-1; + for (int p = 0; p < num_iterations; p++) { + for (int i = 1; i < Mm1; i++) { + for (int j = 1; j < Mm1; j++) + G[i][j] = G[i-1][j]; + } + } + + return G[3][2]; + } +}