diff options
| author | Cliff Click <cliffc@acm.org> | 2024-01-15 10:00:55 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-15 18:00:55 +0000 |
| commit | fc4639291f736553e96eaec5fc7b4c82645db129 (patch) | |
| tree | ddcc4a397ee4d51b365273465595fc70dcfafceb /chapter08/src/main/java | |
| parent | ab8b1f298dcef84026f6b8e04576111126e8c68a (diff) | |
| download | Simple-fc4639291f736553e96eaec5fc7b4c82645db129.tar.gz Simple-fc4639291f736553e96eaec5fc7b4c82645db129.zip | |
Some minor fixes found via fuzzing (#60)
Diffstat (limited to 'chapter08/src/main/java')
4 files changed, 19 insertions, 10 deletions
diff --git a/chapter08/src/main/java/com/seaofnodes/simple/node/IfNode.java b/chapter08/src/main/java/com/seaofnodes/simple/node/IfNode.java index e573010d..1d1da4fa 100644 --- a/chapter08/src/main/java/com/seaofnodes/simple/node/IfNode.java +++ b/chapter08/src/main/java/com/seaofnodes/simple/node/IfNode.java @@ -46,7 +46,7 @@ public class IfNode extends MultiNode { return prior instanceof ProjNode proj // Repeated test, dominated on one side. Test result is the same. ? (proj._idx==0 ? TypeTuple.IF_TRUE : TypeTuple.IF_FALSE) - : null; // Repeated test not dominated on one side + : dom._type; // Repeated test not dominated on one side return TypeTuple.IF_BOTH; } diff --git a/chapter08/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter08/src/main/java/com/seaofnodes/simple/node/Node.java index 22b6f264..fd312c3d 100644 --- a/chapter08/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter08/src/main/java/com/seaofnodes/simple/node/Node.java @@ -140,10 +140,8 @@ public abstract class Node { sb.append("\n"); } - public final String p(int depth) { - return IRPrinter.prettyPrint(this,depth); - } - + public String p(int depth) { return IRPrinter.prettyPrint(this,depth); } + public boolean isMultiHead() { return false; } public boolean isMultiTail() { return false; } diff --git a/chapter08/src/main/java/com/seaofnodes/simple/node/PhiNode.java b/chapter08/src/main/java/com/seaofnodes/simple/node/PhiNode.java index e6cf338b..975630d0 100644 --- a/chapter08/src/main/java/com/seaofnodes/simple/node/PhiNode.java +++ b/chapter08/src/main/java/com/seaofnodes/simple/node/PhiNode.java @@ -85,10 +85,13 @@ public class PhiNode extends Node { */ private Node singleUniqueInput() { Node live = null; - for( int i=1; i<nIns(); i++ ) + for( int i=1; i<nIns(); i++ ) { + if( region() instanceof LoopNode loop && loop.entry()._type == Type.XCONTROL ) + return null; // Dead entry loops just ignore and let the loop collapse if( region().in(i)._type != Type.XCONTROL && in(i) != this ) if( live == null || live == in(i) ) live = in(i); else return null; + } return live; } diff --git a/chapter08/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter08/src/main/java/com/seaofnodes/simple/node/ScopeNode.java index 3c4a2088..a6a7f536 100644 --- a/chapter08/src/main/java/com/seaofnodes/simple/node/ScopeNode.java +++ b/chapter08/src/main/java/com/seaofnodes/simple/node/ScopeNode.java @@ -202,14 +202,22 @@ public class ScopeNode extends Node { PhiNode phi = (PhiNode)in(i); assert phi.region()==ctrl && phi.in(2)==null; phi.setDef(2,back.in(i)); - // Do an eager useless-phi removal - Node in = phi.peephole(); - if( in != phi ) - phi.subsume(in); } if( exit.in(i) == this ) // Replace a lazy-phi on the exit path also exit.setDef(i,in(i)); } back.kill(); // Loop backedge is dead + // Now one-time do a useless-phi removal + for( int i=1; i<nIns(); i++ ) { + if( in(i) instanceof PhiNode phi ) { + // Do an eager useless-phi removal + Node in = phi.peephole(); + if( in != phi ) { + phi.subsume(in); + setDef(i,in); // Set the update back into Scope + } + } + } + } } |
