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