annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java @ 22941:4311a0d2fd36

Backout ccdecd8cc1f2: Don't register unchanged stamps
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 03 Nov 2015 15:13:15 -0800
parents ccdecd8cc1f2
children 86bee10c31b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.phases.common;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
22790
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
25 import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateReprofile;
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
26 import static jdk.vm.ci.meta.DeoptimizationReason.UnreachedCode;
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
27
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
28 import java.util.ArrayDeque;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
29 import java.util.ArrayList;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
30 import java.util.Collections;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
31 import java.util.Deque;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
32 import java.util.Iterator;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
33 import java.util.List;
22921
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
34 import java.util.function.BiConsumer;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
35 import java.util.function.Function;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36
22790
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
37 import jdk.vm.ci.meta.JavaConstant;
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
38 import jdk.vm.ci.meta.TriState;
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents: 21898
diff changeset
39
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
40 import com.oracle.graal.compiler.common.cfg.AbstractControlFlowGraph;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
41 import com.oracle.graal.compiler.common.cfg.BlockMap;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
42 import com.oracle.graal.compiler.common.type.ArithmeticOpTable;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
43 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.BinaryOp;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
44 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.BinaryOp.And;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
45 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.BinaryOp.Or;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
46 import com.oracle.graal.compiler.common.type.IntegerStamp;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
47 import com.oracle.graal.compiler.common.type.Stamp;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
48 import com.oracle.graal.compiler.common.type.StampFactory;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
49 import com.oracle.graal.debug.Debug;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
50 import com.oracle.graal.debug.DebugMetric;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
51 import com.oracle.graal.graph.Node;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
52 import com.oracle.graal.graph.NodeMap;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
53 import com.oracle.graal.nodeinfo.InputType;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
54 import com.oracle.graal.nodes.AbstractBeginNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
55 import com.oracle.graal.nodes.BeginNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
56 import com.oracle.graal.nodes.BinaryOpLogicNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
57 import com.oracle.graal.nodes.ConditionAnchorNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
58 import com.oracle.graal.nodes.DeoptimizeNode;
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
59 import com.oracle.graal.nodes.DeoptimizingGuard;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
60 import com.oracle.graal.nodes.FixedGuardNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
61 import com.oracle.graal.nodes.FixedNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
62 import com.oracle.graal.nodes.GuardNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
63 import com.oracle.graal.nodes.GuardProxyNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
64 import com.oracle.graal.nodes.IfNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
65 import com.oracle.graal.nodes.LogicNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
66 import com.oracle.graal.nodes.LoopExitNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
67 import com.oracle.graal.nodes.PiNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
68 import com.oracle.graal.nodes.ShortCircuitOrNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
69 import com.oracle.graal.nodes.StructuredGraph;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
70 import com.oracle.graal.nodes.UnaryOpLogicNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
71 import com.oracle.graal.nodes.ValueNode;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
72 import com.oracle.graal.nodes.calc.AndNode;
22884
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
73 import com.oracle.graal.nodes.calc.BinaryArithmeticNode;
22921
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
74 import com.oracle.graal.nodes.calc.BinaryNode;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
75 import com.oracle.graal.nodes.calc.IntegerEqualsNode;
22921
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
76 import com.oracle.graal.nodes.calc.UnaryNode;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
77 import com.oracle.graal.nodes.cfg.Block;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
78 import com.oracle.graal.nodes.cfg.ControlFlowGraph;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
79 import com.oracle.graal.nodes.extended.GuardingNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
80 import com.oracle.graal.nodes.extended.IntegerSwitchNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
81 import com.oracle.graal.nodes.extended.LoadHubNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
82 import com.oracle.graal.nodes.extended.ValueAnchorNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
83 import com.oracle.graal.nodes.java.CheckCastNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
84 import com.oracle.graal.nodes.java.TypeSwitchNode;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
85 import com.oracle.graal.nodes.spi.NodeWithState;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
86 import com.oracle.graal.nodes.util.GraphUtil;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
87 import com.oracle.graal.phases.Phase;
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
88 import com.oracle.graal.phases.common.LoweringPhase.Frame;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
89 import com.oracle.graal.phases.schedule.SchedulePhase;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 public class DominatorConditionalEliminationPhase extends Phase {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 private static final DebugMetric metricStampsRegistered = Debug.metric("StampsRegistered");
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94 private static final DebugMetric metricStampsFound = Debug.metric("StampsFound");
19721
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
95 private final boolean fullSchedule;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96
19721
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
97 public DominatorConditionalEliminationPhase(boolean fullSchedule) {
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
98 this.fullSchedule = fullSchedule;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 private static final class InfoElement {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
102 private final Stamp stamp;
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
103 private final ValueNode guard;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 public InfoElement(Stamp stamp, ValueNode guard) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 this.stamp = stamp;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
107 this.guard = guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 public Stamp getStamp() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111 return stamp;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 public ValueNode getGuard() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 return guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 }
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
117
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
118 @Override
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
119 public String toString() {
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
120 return stamp + " -> " + guard;
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
121 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 private static final class Info {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
125 private final ArrayList<InfoElement> infos;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 public Info() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 infos = new ArrayList<>();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 public Iterable<InfoElement> getElements() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 return infos;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 public void pushElement(InfoElement element) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 infos.add(element);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 public void popElement() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 infos.remove(infos.size() - 1);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 @Override
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
145 @SuppressWarnings("try")
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 protected void run(StructuredGraph graph) {
19721
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
147
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
148 try (Debug.Scope s = Debug.scope("DominatorConditionalElimination")) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
149 Function<Block, Iterable<? extends Node>> blockToNodes;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
150 Function<Node, Block> nodeToBlock;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
151 Block startBlock;
19721
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
152
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
153 if (fullSchedule) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
154 SchedulePhase schedule = new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
155 schedule.apply(graph);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
156 ControlFlowGraph cfg = schedule.getCFG();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
157 cfg.computePostdominators();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
158 blockToNodes = b -> schedule.getBlockToNodesMap().get(b);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
159 nodeToBlock = n -> schedule.getNodeToBlockMap().get(n);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
160 startBlock = cfg.getStartBlock();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
161 } else {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
162 ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
163 cfg.computePostdominators();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
164 BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
165 for (Block b : cfg.getBlocks()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
166 ArrayList<FixedNode> curNodes = new ArrayList<>();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
167 for (FixedNode node : b.getNodes()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
168 if (node instanceof AbstractBeginNode || node instanceof FixedGuardNode || node instanceof CheckCastNode || node instanceof ConditionAnchorNode || node instanceof IfNode) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
169 curNodes.add(node);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
170 }
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
171 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
172 nodes.put(b, curNodes);
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
173 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
174 blockToNodes = b -> nodes.get(b);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
175 nodeToBlock = n -> cfg.blockFor(n);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
176 startBlock = cfg.getStartBlock();
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
177 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
178
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
179 Instance instance = new Instance(graph, blockToNodes, nodeToBlock);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
180 instance.processBlock(startBlock);
19721
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19719
diff changeset
181 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
184 static class PendingTest {
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
185 private final LogicNode condition;
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
186 private final DeoptimizingGuard guard;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
187
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
188 public PendingTest(LogicNode condition, DeoptimizingGuard guard) {
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
189 this.condition = condition;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
190 this.guard = guard;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
191 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
192 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
193
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 private static class Instance {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195
21619
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
196 private NodeMap<Info> map;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
197 private Deque<LoopExitNode> loopExits;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 private final Function<Block, Iterable<? extends Node>> blockToNodes;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 private final Function<Node, Block> nodeToBlock;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
201 /**
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
202 * Tests which may be eliminated because post dominating tests to prove a broader condition.
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
203 */
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
204 private Deque<PendingTest> pendingTests;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
205
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 public Instance(StructuredGraph graph, Function<Block, Iterable<? extends Node>> blockToNodes, Function<Node, Block> nodeToBlock) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 map = graph.createNodeMap();
20040
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19950
diff changeset
208 loopExits = new ArrayDeque<>();
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 this.blockToNodes = blockToNodes;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 this.nodeToBlock = nodeToBlock;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
211 pendingTests = new ArrayDeque<>();
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213
20931
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
214 public void processBlock(Block startBlock) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
215 LoweringPhase.processBlock(new InstanceFrame(startBlock, null));
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
216 }
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
217
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
218 public class InstanceFrame extends LoweringPhase.Frame<InstanceFrame> {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 List<Runnable> undoOperations = new ArrayList<>();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220
20931
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
221 public InstanceFrame(Block block, InstanceFrame parent) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
222 super(block, parent);
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
223 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224
20931
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
225 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
226 public Frame<?> enter(Block b) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
227 return new InstanceFrame(b, this);
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
228 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229
20931
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
230 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
231 public void preprocess() {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
232 Instance.this.preprocess(block, undoOperations);
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
233 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234
20931
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
235 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
236 public void postprocess() {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
237 Instance.postprocess(undoOperations);
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
238 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
241 private static void postprocess(List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
242 for (Runnable r : undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
243 r.run();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
244 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
245 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
246
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
247 private void preprocess(Block block, List<Runnable> undoOperations) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
248 AbstractBeginNode beginNode = block.getBeginNode();
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
249 if (beginNode instanceof LoopExitNode && beginNode.isAlive()) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
250 LoopExitNode loopExitNode = (LoopExitNode) beginNode;
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
251 this.loopExits.push(loopExitNode);
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
252 undoOperations.add(() -> loopExits.pop());
21619
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
253 } else if (block.getDominator() != null &&
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
254 (block.getDominator().getLoopDepth() > block.getLoopDepth() || (block.getDominator().getLoopDepth() == block.getLoopDepth() && block.getDominator().getLoop() != block.getLoop()))) {
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
255 // We are exiting the loop, but there is not a single loop exit block along our
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
256 // dominator tree (e.g., we are a merge of two loop exits).
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
257 final NodeMap<Info> oldMap = map;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
258 final Deque<LoopExitNode> oldLoopExits = loopExits;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
259 map = map.graph().createNodeMap();
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
260 loopExits = new ArrayDeque<>();
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
261 undoOperations.add(() -> {
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
262 map = oldMap;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
263 loopExits = oldLoopExits;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
264 });
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
265 }
22890
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
266
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
267 // For now conservatively collect guards only within the same block.
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
268 pendingTests.clear();
19731
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
269 for (Node n : blockToNodes.apply(block)) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
270 if (n.isAlive()) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19728
diff changeset
271 processNode(n, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
275
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
276 private void processNode(Node node, List<Runnable> undoOperations) {
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
277 if (node instanceof NodeWithState && !(node instanceof GuardingNode)) {
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
278 pendingTests.clear();
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
279 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280 if (node instanceof AbstractBeginNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
281 processAbstractBegin((AbstractBeginNode) node, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
282 } else if (node instanceof FixedGuardNode) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
283 processFixedGuard((FixedGuardNode) node, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
284 } else if (node instanceof GuardNode) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
285 processGuard((GuardNode) node, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
286 } else if (node instanceof CheckCastNode) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
287 processCheckCast((CheckCastNode) node);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
288 } else if (node instanceof ConditionAnchorNode) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
289 processConditionAnchor((ConditionAnchorNode) node);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
290 } else if (node instanceof IfNode) {
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
291 processIf((IfNode) node, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
292 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
293 return;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
294 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
297 private void processCheckCast(CheckCastNode node) {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
298 for (InfoElement infoElement : getInfoElements(node.object())) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
299 TriState result = node.tryFold(infoElement.getStamp());
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
300 if (result.isKnown()) {
21039
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
301 if (rewireGuards(infoElement.getGuard(), result.toBoolean(), (guard, checkCastResult) -> {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
302 if (checkCastResult) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
303 PiNode piNode = node.graph().unique(new PiNode(node.object(), node.stamp(), guard));
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
304 node.replaceAtUsages(piNode);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
305 GraphUtil.unlinkFixedNode(node);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
306 node.safeDelete();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
307 } else {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
308 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode));
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
309 node.replaceAtPredecessor(deopt);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
310 GraphUtil.killCFG(node);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
311 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
312 return true;
21039
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
313 })) {
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
314 return;
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
315 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 }
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
317 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
318 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
320 private void processIf(IfNode node, List<Runnable> undoOperations) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
321 tryProofCondition(node.condition(), (guard, result) -> {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
322 AbstractBeginNode survivingSuccessor = node.getSuccessor(result);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
323 survivingSuccessor.replaceAtUsages(InputType.Guard, guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324 survivingSuccessor.replaceAtPredecessor(null);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
325 node.replaceAtPredecessor(survivingSuccessor);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
326 GraphUtil.killCFG(node);
21585
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
327 if (survivingSuccessor instanceof BeginNode) {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
328 undoOperations.add(() -> {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
329 if (survivingSuccessor.isAlive()) {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
330 ((BeginNode) survivingSuccessor).trySimplify();
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
331 }
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
332 });
19728
4df907480030 Simplify begin node immediately after removing if node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
333 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
334 return true;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
335 });
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
336 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
337
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
338 private void registerNewCondition(LogicNode condition, boolean negated, ValueNode guard, List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339 if (condition instanceof UnaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
340 UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) condition;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341 Stamp newStamp = unaryLogicNode.getSucceedingStampForValue(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342 registerNewStamp(unaryLogicNode.getValue(), newStamp, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
343 } else if (condition instanceof BinaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
344 BinaryOpLogicNode binaryOpLogicNode = (BinaryOpLogicNode) condition;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
345 ValueNode x = binaryOpLogicNode.getX();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
346 if (!x.isConstant()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
347 Stamp newStampX = binaryOpLogicNode.getSucceedingStampForX(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
348 registerNewStamp(x, newStampX, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
349 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
350
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351 ValueNode y = binaryOpLogicNode.getY();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
352 if (!y.isConstant()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 Stamp newStampY = binaryOpLogicNode.getSucceedingStampForY(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 registerNewStamp(y, newStampY, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
356 if (condition instanceof IntegerEqualsNode && guard instanceof DeoptimizingGuard && !negated) {
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
357 if (y.isConstant() && x instanceof AndNode) {
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
358 AndNode and = (AndNode) x;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
359 if (and.getY() == y) {
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
360 /*
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
361 * This 'and' proves something about some of the bits in and.getX().
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
362 * It's equivalent to or'ing in the mask value since those values are
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
363 * known to be set.
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
364 */
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
365 BinaryOp<Or> op = ArithmeticOpTable.forStamp(x.stamp()).getOr();
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
366 IntegerStamp newStampX = (IntegerStamp) op.foldStamp(and.getX().stamp(), y.stamp());
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
367 registerNewStamp(and.getX(), newStampX, guard, undoOperations);
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
368 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
369 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
370 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
372 if (guard instanceof DeoptimizingGuard) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
373 pendingTests.push(new PendingTest(condition, (DeoptimizingGuard) guard));
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
374 }
21036
953666b61a23 Always register stamps for the condition itself
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 20934
diff changeset
375 registerCondition(condition, negated, guard, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
376 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377
22921
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
378 /**
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
379 * Checks for safe nodes when moving pending tests up.
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
380 */
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
381 static class InputFilter implements BiConsumer<Node, Node> {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
382 boolean ok;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
383 private ValueNode value;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
384
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
385 InputFilter(ValueNode value) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
386 this.value = value;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
387 this.ok = true;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
388 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
389
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
390 public void accept(Node node, Node curNode) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
391 if (!(curNode instanceof ValueNode)) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
392 ok = false;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
393 return;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
394 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
395 ValueNode curValue = (ValueNode) curNode;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
396 if (curValue.isConstant() || curValue == value) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
397 return;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
398 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
399 if (curValue instanceof BinaryNode || curValue instanceof UnaryNode) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
400 curValue.acceptInputs(this);
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
401 } else {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
402 ok = false;
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
403 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
404 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
405 }
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
406
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
407 private boolean foldPendingTest(DeoptimizingGuard thisGuard, ValueNode original, Stamp newStamp, GuardRewirer rewireGuardFunction) {
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
408 for (PendingTest pending : pendingTests) {
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
409 TriState result = TriState.UNKNOWN;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
410 if (pending.condition instanceof UnaryOpLogicNode) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
411 UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) pending.condition;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
412 if (unaryLogicNode.getValue() == original) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
413 result = unaryLogicNode.tryFold(newStamp);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
414 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
415 } else if (pending.condition instanceof BinaryOpLogicNode) {
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
416 BinaryOpLogicNode binaryOpLogicNode = (BinaryOpLogicNode) pending.condition;
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
417 ValueNode x = binaryOpLogicNode.getX();
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
418 ValueNode y = binaryOpLogicNode.getY();
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
419 if (binaryOpLogicNode.getX() == original) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
420 result = binaryOpLogicNode.tryFold(newStamp, binaryOpLogicNode.getY().stamp());
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
421 } else if (binaryOpLogicNode instanceof IntegerEqualsNode && y.isConstant() && x instanceof AndNode) {
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
422 AndNode and = (AndNode) x;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
423 if (and.getY() == y && and.getX() == original) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
424 BinaryOp<And> andOp = ArithmeticOpTable.forStamp(newStamp).getAnd();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
425 result = binaryOpLogicNode.tryFold(andOp.foldStamp(newStamp, y.stamp()), y.stamp());
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
426 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
427 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
428 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
429 if (result.isKnown()) {
22921
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
430 /*
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
431 * The test case be folded using the information available but the test can only
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
432 * be moved up if we're sure there's no schedule dependence. For now limit it to
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
433 * the original node and constants.
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
434 */
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
435 InputFilter v = new InputFilter(original);
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
436 thisGuard.getCondition().acceptInputs(v);
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
437 if (v.ok && foldGuard(thisGuard, pending.guard, result, rewireGuardFunction)) {
21c01c87ddfb Be more conservative when moving tests upward
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22919
diff changeset
438 Debug.log("foldPendingTest %s %s %1s", result, newStamp, pending.condition);
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
439 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
440 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
441 }
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
442 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
443 return false;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
444 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
445
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
446 private boolean foldGuard(DeoptimizingGuard thisGuard, DeoptimizingGuard otherGuard, TriState testResult, GuardRewirer rewireGuardFunction) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
447 if (otherGuard.getAction() == thisGuard.getAction() && otherGuard.getReason() == thisGuard.getReason() && otherGuard.getSpeculation() == thisGuard.getSpeculation()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
448 LogicNode condition = (LogicNode) thisGuard.getCondition().copyWithInputs();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
449 GuardRewirer rewirer = (guard, result) -> {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
450 if (rewireGuardFunction.rewire(guard, result)) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
451 otherGuard.setCondition(condition, thisGuard.isNegated());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
452 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
453 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
454 condition.safeDelete();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
455 return false;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
456 };
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
457 // Move the later test up
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
458 Debug.log("Folding guard %s %s %1s %s %1s %s\n", testResult, otherGuard, otherGuard.getCondition(), thisGuard, thisGuard.getCondition(), thisGuard.asNode().graph());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
459 return rewireGuards(otherGuard.asNode(), !thisGuard.isNegated(), rewirer);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
460 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
461 return false;
22885
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
462 }
dc1551f0833e Fold post dominating bit tests into earlier guards
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22884
diff changeset
463
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 private void registerCondition(LogicNode condition, boolean negated, ValueNode guard, List<Runnable> undoOperations) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
465 registerNewStamp(condition, negated ? StampFactory.contradiction() : StampFactory.tautology(), guard, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
466 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
467
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
468 private Iterable<InfoElement> getInfoElements(ValueNode proxiedValue) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
469 ValueNode value = GraphUtil.unproxify(proxiedValue);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
470 Info info = map.get(value);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
471 if (info == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
472 return Collections.emptyList();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
473 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
474 return info.getElements();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
475 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
476 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
478 private boolean rewireGuards(ValueNode guard, boolean result, GuardRewirer rewireGuardFunction) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
479 assert guard instanceof GuardingNode;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
480 metricStampsFound.increment();
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
481 ValueNode proxiedGuard = proxyGuard(guard);
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
482 return rewireGuardFunction.rewire(proxiedGuard, result);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
483 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
484
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
485 private ValueNode proxyGuard(ValueNode guard) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486 ValueNode proxiedGuard = guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487 if (!this.loopExits.isEmpty()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488 while (proxiedGuard instanceof GuardProxyNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489 proxiedGuard = ((GuardProxyNode) proxiedGuard).value();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
490 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 Block guardBlock = nodeToBlock.apply(proxiedGuard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
492 assert guardBlock != null;
20040
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19950
diff changeset
493 for (Iterator<LoopExitNode> iter = loopExits.descendingIterator(); iter.hasNext();) {
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19950
diff changeset
494 LoopExitNode loopExitNode = iter.next();
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
495 Block loopExitBlock = nodeToBlock.apply(loopExitNode);
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
496 if (guardBlock != loopExitBlock && AbstractControlFlowGraph.dominates(guardBlock, loopExitBlock)) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
497 Block loopBeginBlock = nodeToBlock.apply(loopExitNode.loopBegin());
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
498 if (!AbstractControlFlowGraph.dominates(guardBlock, loopBeginBlock) || guardBlock == loopBeginBlock) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
499 proxiedGuard = proxiedGuard.graph().unique(new GuardProxyNode((GuardingNode) proxiedGuard, loopExitNode));
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
500 }
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
501 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
502 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
503 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
504 return proxiedGuard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
505 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
507 @FunctionalInterface
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
508 private interface GuardRewirer {
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
509 /**
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
510 * Called if the condition could be proven to have a constant value ({@code result})
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
511 * under {@code guard}.
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
512 *
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
513 * Return whether a transformation could be applied.
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
514 */
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
515 boolean rewire(ValueNode guard, boolean result);
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
516 }
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
517
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
518 private boolean tryProofCondition(LogicNode node, GuardRewirer rewireGuardFunction) {
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
519 return tryProofGuardCondition(null, node, rewireGuardFunction);
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
520 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
521
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
522 private boolean tryProofGuardCondition(DeoptimizingGuard thisGuard, LogicNode node, GuardRewirer rewireGuardFunction) {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
523 for (InfoElement infoElement : getInfoElements(node)) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
524 Stamp stamp = infoElement.getStamp();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
525 JavaConstant constant = (JavaConstant) stamp.asConstant();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
526 if (constant != null) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
527 return rewireGuards(infoElement.getGuard(), constant.asBoolean(), rewireGuardFunction);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
528 }
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
529 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
530 if (node instanceof UnaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
531 UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) node;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
532 ValueNode value = unaryLogicNode.getValue();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
533 for (InfoElement infoElement : getInfoElements(value)) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
534 Stamp stamp = infoElement.getStamp();
19724
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
535 TriState result = unaryLogicNode.tryFold(stamp);
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
536 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
537 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
538 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
539 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
540 if (thisGuard != null && unaryLogicNode.stamp() instanceof IntegerStamp) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
541 Stamp newStamp = unaryLogicNode.getSucceedingStampForValue(thisGuard.isNegated());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
542 if (newStamp != null && foldPendingTest(thisGuard, unaryLogicNode.getValue(), newStamp, rewireGuardFunction)) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
543 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
544 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
545
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
546 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
547 } else if (node instanceof BinaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
548 BinaryOpLogicNode binaryOpLogicNode = (BinaryOpLogicNode) node;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
549 for (InfoElement infoElement : getInfoElements(binaryOpLogicNode)) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
550 if (infoElement.getStamp().equals(StampFactory.contradiction())) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
551 return rewireGuards(infoElement.getGuard(), false, rewireGuardFunction);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
552 } else if (infoElement.getStamp().equals(StampFactory.tautology())) {
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
553 return rewireGuards(infoElement.getGuard(), true, rewireGuardFunction);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
554 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
555 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
556
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
557 ValueNode x = binaryOpLogicNode.getX();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
558 ValueNode y = binaryOpLogicNode.getY();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
559 for (InfoElement infoElement : getInfoElements(x)) {
19724
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
560 TriState result = binaryOpLogicNode.tryFold(infoElement.getStamp(), y.stamp());
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
561 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
562 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
563 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
564 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
565
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
566 for (InfoElement infoElement : getInfoElements(y)) {
19724
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
567 TriState result = binaryOpLogicNode.tryFold(x.stamp(), infoElement.getStamp());
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
568 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19723
diff changeset
569 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
570 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
571 }
22884
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
572 /*
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
573 * For complex expressions involving constants, see if it's possible to fold the
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
574 * tests by using stamps one level up in the expression. For instance, (x + n < y)
22890
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
575 * might fold if something is known about x and all other values are constants. The
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
576 * reason for the constant restriction is that if more than 1 real value is involved
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
577 * the code might need to adopt multiple guards to have proper dependences.
22884
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
578 */
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
579 if (x instanceof BinaryArithmeticNode<?> && y.isConstant()) {
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
580 BinaryArithmeticNode<?> binary = (BinaryArithmeticNode<?>) x;
22890
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
581 if (binary.getY().isConstant()) {
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
582 for (InfoElement infoElement : getInfoElements(binary.getX())) {
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
583 Stamp newStampX = binary.tryFoldStamp(infoElement.getStamp(), binary.getY().stamp());
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
584 TriState result = binaryOpLogicNode.tryFold(newStampX, y.stamp());
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
585 if (result.isKnown()) {
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
586 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
a2bf47587cc1 Correct guard logic to only rely on constants
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22885
diff changeset
587 }
22884
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
588 }
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
589 }
2fe4e3511d97 Look into expressions when performing conditional elimination
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22872
diff changeset
590 }
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
591 if (thisGuard != null && binaryOpLogicNode instanceof IntegerEqualsNode && !thisGuard.isNegated()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
592 if (y.isConstant() && x instanceof AndNode) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
593 AndNode and = (AndNode) x;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
594 if (and.getY() == y) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
595 /*
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
596 * This 'and' proves something about some of the bits in and.getX().
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
597 * It's equivalent to or'ing in the mask value since those values are
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
598 * known to be set.
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
599 */
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
600 BinaryOp<Or> op = ArithmeticOpTable.forStamp(x.stamp()).getOr();
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
601 IntegerStamp newStampX = (IntegerStamp) op.foldStamp(and.getX().stamp(), y.stamp());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
602 if (foldPendingTest(thisGuard, and.getX(), newStampX, rewireGuardFunction)) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
603 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
604 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
605 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
606 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
607 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
608 if (thisGuard != null) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
609 if (!x.isConstant()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
610 Stamp newStampX = binaryOpLogicNode.getSucceedingStampForX(thisGuard.isNegated());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
611 if (newStampX != null && foldPendingTest(thisGuard, x, newStampX, rewireGuardFunction)) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
612 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
613 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
614 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
615 if (!y.isConstant()) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
616 Stamp newStampY = binaryOpLogicNode.getSucceedingStampForY(thisGuard.isNegated());
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
617 if (newStampY != null && foldPendingTest(thisGuard, y, newStampY, rewireGuardFunction)) {
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
618 return true;
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
619 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
620 }
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
621 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
622 } else if (node instanceof ShortCircuitOrNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
623 final ShortCircuitOrNode shortCircuitOrNode = (ShortCircuitOrNode) node;
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
624 if (this.loopExits.isEmpty()) {
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
625 return tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> {
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
626 if (result == !shortCircuitOrNode.isXNegated()) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
627 return rewireGuards(guard, true, rewireGuardFunction);
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
628 } else {
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
629 return tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> {
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
630 if (innerGuard == guard) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
631 return rewireGuards(guard, innerResult ^ shortCircuitOrNode.isYNegated(), rewireGuardFunction);
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
632 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
633 return false;
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
634 });
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
635 }
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
636 });
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
637 }
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
638 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
639
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
640 return false;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
641 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
642
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
643 private void registerNewStamp(ValueNode proxiedValue, Stamp newStamp, ValueNode guard, List<Runnable> undoOperations) {
22941
4311a0d2fd36 Backout ccdecd8cc1f2: Don't register unchanged stamps
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22938
diff changeset
644 if (newStamp != null) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
645 ValueNode value = GraphUtil.unproxify(proxiedValue);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
646 Info info = map.get(value);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
647 if (info == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
648 info = new Info();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
649 map.set(value, info);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
650 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
651 metricStampsRegistered.increment();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
652 final Info finalInfo = info;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
653 finalInfo.pushElement(new InfoElement(newStamp, guard));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
654 undoOperations.add(() -> finalInfo.popElement());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
655 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
656 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
657
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
658 private void processConditionAnchor(ConditionAnchorNode node) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
659 tryProofCondition(node.condition(), (guard, result) -> {
19950
212566f9cd69 Dom-based ConditionalElimination: fix fliped check in processConditionAnchor
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19762
diff changeset
660 if (result != node.isNegated()) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
661 node.replaceAtUsages(guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
662 GraphUtil.unlinkFixedNode(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
663 GraphUtil.killWithUnusedFloatingInputs(node);
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
664 } else {
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
665 ValueAnchorNode valueAnchor = node.graph().add(new ValueAnchorNode(null));
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
666 node.replaceAtUsages(valueAnchor);
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
667 node.graph().replaceFixedWithFixed(node, valueAnchor);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
668 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
669 return true;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
670 });
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
671 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
672
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
673 private void processGuard(GuardNode node, List<Runnable> undoOperations) {
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
674 if (!tryProofGuardCondition(node, node.getCondition(), (guard, result) -> {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
675 if (result != node.isNegated()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
676 node.replaceAndDelete(guard);
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
677 } else {
22909
5ce3e8996c83 Add unifying DeoptimizingGuard interface for AbstractFixedGuardNode and GuardNode
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22899
diff changeset
678 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.getAction(), node.getReason(), node.getSpeculation()));
20174
56f721367c0d conditional elimination: use begin node from guard anchor instead of node to block map
Andreas Woess <andreas.woess@oracle.com>
parents: 20040
diff changeset
679 AbstractBeginNode beginNode = (AbstractBeginNode) node.getAnchor();
19762
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
680 FixedNode next = beginNode.next();
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19731
diff changeset
681 beginNode.setNext(deopt);
19719
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
682 GraphUtil.killCFG(next);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
683 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
684 return true;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
685 })) {
22909
5ce3e8996c83 Add unifying DeoptimizingGuard interface for AbstractFixedGuardNode and GuardNode
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22899
diff changeset
686 registerNewCondition(node.getCondition(), node.isNegated(), node, undoOperations);
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
687 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
688 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
689
19723
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
690 private void processFixedGuard(FixedGuardNode node, List<Runnable> undoOperations) {
22919
6b81cca49187 Fix machinery for elimination of pending tests
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22909
diff changeset
691 if (!tryProofGuardCondition(node, node.condition(), (guard, result) -> {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
692 if (result != node.isNegated()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
693 node.replaceAtUsages(guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
694 GraphUtil.unlinkFixedNode(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
695 GraphUtil.killWithUnusedFloatingInputs(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
696 } else {
21898
6714387f5323 Make it possible to use a speculation in a FixedGuard
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21619
diff changeset
697 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.getAction(), node.getReason(), node.getSpeculation()));
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
698 deopt.setStateBefore(node.stateBefore());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
699 node.replaceAtPredecessor(deopt);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
700 GraphUtil.killCFG(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
701 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
702 return true;
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
703 })) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
704 registerNewCondition(node.condition(), node.isNegated(), node, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
705 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
706 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
707
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
708 private void processAbstractBegin(AbstractBeginNode beginNode, List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
709 Node predecessor = beginNode.predecessor();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
710 if (predecessor instanceof IfNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
711 IfNode ifNode = (IfNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
712 boolean negated = (ifNode.falseSuccessor() == beginNode);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
713 LogicNode condition = ifNode.condition();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
714 registerNewCondition(condition, negated, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
715 } else if (predecessor instanceof TypeSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
716 TypeSwitchNode typeSwitch = (TypeSwitchNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
717 processTypeSwitch(beginNode, undoOperations, predecessor, typeSwitch);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
718 } else if (predecessor instanceof IntegerSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
719 IntegerSwitchNode integerSwitchNode = (IntegerSwitchNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
720 processIntegerSwitch(beginNode, undoOperations, predecessor, integerSwitchNode);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
721 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
722 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
723
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
724 private void processIntegerSwitch(AbstractBeginNode beginNode, List<Runnable> undoOperations, Node predecessor, IntegerSwitchNode integerSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
725 Stamp stamp = null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
726 for (int i = 0; i < integerSwitchNode.keyCount(); i++) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
727 if (integerSwitchNode.keySuccessor(i) == predecessor) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
728 if (stamp == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
729 stamp = StampFactory.forConstant(integerSwitchNode.keyAt(i));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
730 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
731 stamp = stamp.meet(StampFactory.forConstant(integerSwitchNode.keyAt(i)));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
732 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
733 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
734 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
735
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
736 if (stamp != null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
737 registerNewStamp(integerSwitchNode.value(), stamp, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
738 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
739 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
740
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
741 private void processTypeSwitch(AbstractBeginNode beginNode, List<Runnable> undoOperations, Node predecessor, TypeSwitchNode typeSwitch) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
742 ValueNode hub = typeSwitch.value();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
743 if (hub instanceof LoadHubNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
744 LoadHubNode loadHub = (LoadHubNode) hub;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
745 Stamp stamp = null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
746 for (int i = 0; i < typeSwitch.keyCount(); i++) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
747 if (typeSwitch.keySuccessor(i) == predecessor) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
748 if (stamp == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
749 stamp = StampFactory.exactNonNull(typeSwitch.typeAt(i));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
750 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
751 stamp = stamp.meet(StampFactory.exactNonNull(typeSwitch.typeAt(i)));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
752 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
753 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
754 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
755 if (stamp != null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
756 registerNewStamp(loadHub.getValue(), stamp, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
757 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
758 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
759 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
760 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
761 }