1 /* 2 * Copyright (c) 2016, 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 8078262 27 * @summary Tests correct dominator information after loop peeling. 28 * @run main/othervm -Xcomp -XX:CompileCommand=compileonly,TestLoopPeeling::test* TestLoopPeeling 29 */ 30 public class TestLoopPeeling { 31 32 public int[] array = new int[100]; 33 34 public static void main(String args[]) { 35 TestLoopPeeling test = new TestLoopPeeling(); 36 try { 37 test.testArrayAccess(0, 1); 38 test.testArrayAllocation(0, 1); 39 } catch (Exception e) { 40 // Ignore exceptions 41 } 42 } 43 44 public void testArrayAccess(int index, int inc) { 45 int storeIndex = -1; 46 47 for (; index < 10; index += inc) { 48 // This loop invariant check triggers loop peeling because it can 49 // be moved out of the loop (see 'IdealLoopTree::policy_peeling'). 50 if (inc == 42) return; 51 52 // This loop variant usage of LShiftL( ConvI2L( Phi(storeIndex) ) ) 53 // prevents the split if optimization that would otherwise clone the 54 // LShiftL and ConvI2L nodes and assign them to their corresponding array 55 // address computation (see 'PhaseIdealLoop::split_if_with_blocks_post'). 56 if (storeIndex > 0 && array[storeIndex] == 42) return; 57 58 if (index == 42) { 59 // This store and the corresponding range check are moved out of the 60 // loop and both used after old loop and the peeled iteration exit. 61 // For the peeled iteration, storeIndex is always -1 and the ConvI2L 62 // is replaced by TOP. However, the range check is not folded because 63 // we don't do the split if optimization in PhaseIdealLoop2. 64 // As a result, we have a (dead) control path from the peeled iteration 65 // to the StoreI but the data path is removed. 66 array[storeIndex] = 1; 67 return; 68 } 69 70 storeIndex++; 71 } 72 } 73 74 public byte[] testArrayAllocation(int index, int inc) { 75 int allocationCount = -1; 76 byte[] result; 77 78 for (; index < 10; index += inc) { 79 // This loop invariant check triggers loop peeling because it can 80 // be moved out of the loop (see 'IdealLoopTree::policy_peeling'). 81 if (inc == 42) return null; 82 83 if (index == 42) { 84 // This allocation and the corresponding size check are moved out of the 85 // loop and both used after old loop and the peeled iteration exit. 86 // For the peeled iteration, allocationCount is always -1 and the ConvI2L 87 // is replaced by TOP. However, the size check is not folded because 88 // we don't do the split if optimization in PhaseIdealLoop2. 89 // As a result, we have a (dead) control path from the peeled iteration 90 // to the allocation but the data path is removed. 91 result = new byte[allocationCount]; 92 return result; 93 } 94 95 allocationCount++; 96 } 97 return null; 98 } 99 } 100