001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.compiler.test; 024 025import org.junit.*; 026 027import com.oracle.graal.api.directives.*; 028import com.oracle.graal.nodes.*; 029import com.oracle.graal.nodes.StructuredGraph.*; 030import com.oracle.graal.nodes.spi.*; 031import com.oracle.graal.phases.common.*; 032import com.oracle.graal.phases.tiers.*; 033 034/** 035 * This test checks the combined action of 036 * {@link com.oracle.graal.phases.common.DominatorConditionalEliminationPhase} and 037 * {@link com.oracle.graal.phases.common.LoweringPhase}. The lowering phase needs to introduce the 038 * null checks at the correct places for the dominator conditional elimination phase to pick them 039 * up. 040 */ 041public class ConditionalEliminationTest10 extends ConditionalEliminationTestBase { 042 043 private static class TestClass { 044 int x; 045 } 046 047 @SuppressWarnings("all") 048 public static int testSnippet(int a, TestClass t) { 049 int result = 0; 050 if (a == 0) { 051 GraalDirectives.controlFlowAnchor(); 052 result = t.x; 053 } 054 GraalDirectives.controlFlowAnchor(); 055 return result + t.x; 056 } 057 058 @Test 059 public void test1() { 060 StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES); 061 PhaseContext context = new PhaseContext(getProviders()); 062 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); 063 Assert.assertEquals(2, graph.getNodes().filter(GuardNode.class).count()); 064 new DominatorConditionalEliminationPhase(true).apply(graph, context); 065 Assert.assertEquals(1, graph.getNodes().filter(GuardNode.class).count()); 066 } 067}