summaryrefslogtreecommitdiff
path: root/chapter10/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'chapter10/src/main/java/com')
-rw-r--r--chapter10/src/main/java/com/seaofnodes/simple/node/Node.java2
-rw-r--r--chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java10
2 files changed, 11 insertions, 1 deletions
diff --git a/chapter10/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter10/src/main/java/com/seaofnodes/simple/node/Node.java
index 5c9b283e..bb698860 100644
--- a/chapter10/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter10/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -358,7 +358,7 @@ public abstract class Node {
private Node deadCodeElim(Node m) {
// If self is going dead and not being returned here (Nodes returned
// from peephole commonly have no uses (yet)), then kill self.
- if( m != this && isUnused() ) {
+ if( m != this && isUnused() && !isDead() ) {
// Killing self - and since self recursively kills self's inputs we
// might end up killing 'm', which we are returning as a live Node.
// So we add a bogus extra null output edge to stop kill().
diff --git a/chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java b/chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java
index c4bd1572..42501118 100644
--- a/chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java
+++ b/chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java
@@ -35,6 +35,7 @@ public class RegionNode extends Node {
@Override
public Node idealize() {
if( inProgress() ) return null;
+ // Delete dead paths into a Region
int path = findDeadInput();
if( path != 0 &&
// Do not delete the entry path of a loop (ok to remove the back
@@ -61,6 +62,15 @@ public class RegionNode extends Node {
// If down to a single input, become that input
if( nIns()==2 && !hasPhi() )
return in(1); // Collapse if no Phis; 1-input Phis will collapse on their own
+
+ // If a CFG diamond with no merging, delete: "if( pred ) {} else {};"
+ if( !hasPhi() && // No Phi users, just a control user
+ in(1) instanceof ProjNode p1 &&
+ in(2) instanceof ProjNode p2 &&
+ p1.in(0)==p2.in(0) &&
+ p1.in(0) instanceof IfNode iff )
+ return iff.ctrl();
+
return null;
}