1 /*
   2  * Copyright (c) 2015, 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         new TestLoopPeeling().test(0, 1);
  36     }
  37 
  38     public void test(int index, int inc) {
  39         int storeIndex = -1;
  40 
  41         for (; index < 10; index += inc) {
  42             // This loop invariant check triggers loop peeling because it can
  43             // be moved out of the loop (see 'IdealLoopTree::policy_peeling').
  44             if (inc == 42) return;
  45 
  46             // This loop variant usage of LShiftL( ConvI2L( Phi(storeIndex) ) )
  47             // prevents the split if optimization that would otherwise clone the
  48             // LShiftL and ConvI2L nodes and assign them to their corresponding array
  49             // address computation (see 'PhaseIdealLoop::split_if_with_blocks_post').
  50             if (storeIndex > 0 && array[storeIndex] == 42) return;
  51 
  52             if (index == 42) {
  53                 // This store and the corresponding range check are moved out of the
  54                 // loop and both used after old loop and the peeled iteration exit.
  55                 // For the peeled iteration, storeIndex is always -1 and the ConvI2L
  56                 // is replaced by TOP. However, the range check is not folded because
  57                 // we don't do the split if optimization in PhaseIdealLoop2.
  58                 // As a result, we have a (dead) control path from the peeled iteration
  59                 // to the StoreI but the data path is removed.
  60                 array[storeIndex] = 1;
  61                 return;
  62             }
  63 
  64             storeIndex++;
  65         }
  66 
  67         // Second store to 'array'
  68         //array[storeIndex] = 1;
  69     }
  70 }