diff options
| author | Cliff Click <cliffc@acm.org> | 2024-05-31 16:24:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-01 00:24:00 +0100 |
| commit | a749c244bea3e2774d453165cbd18ed52863a8f5 (patch) | |
| tree | 474dffca66656232ee09b5ecdf284354ec8127af /chapter10/src | |
| parent | d91dc657cce857d90389eefd9dd62d7c00ee0710 (diff) | |
| download | Simple-a749c244bea3e2774d453165cbd18ed52863a8f5.tar.gz Simple-a749c244bea3e2774d453165cbd18ed52863a8f5.zip | |
peep dead CFG diamond (#83)
Diffstat (limited to 'chapter10/src')
| -rw-r--r-- | chapter10/src/main/java/com/seaofnodes/simple/node/Node.java | 2 | ||||
| -rw-r--r-- | chapter10/src/main/java/com/seaofnodes/simple/node/RegionNode.java | 10 |
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; } |
