summaryrefslogtreecommitdiff
path: root/chapter25/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter25/src/main/java')
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/Parser.java3
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java12
2 files changed, 10 insertions, 5 deletions
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/Parser.java b/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
index 2b6e5ddf..5453ee05 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/Parser.java
@@ -849,8 +849,9 @@ public class Parser {
// Immediately fail e.g. `arg ? 7 : ptr`
ParseException err;
if( !fside.equals("else") && (err=ret.err()) !=null ) throw err;
+ ret.keep();
r.peephole();
- return ret;
+ return ret.unkeep();
}
/**
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java
index 4112a977..70f678cb 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java
@@ -144,19 +144,23 @@ public class PhiNode extends Node {
return null;
if( !(r.in(3-nzIdx) instanceof CProjNode z && z._idx==1 && z.ctrl()==iff) )
return null;
- Node n = cast.in(1);
- while( n instanceof GuardNode guard ) {
+ // Predicate was guarded?
+ Node n = cast.in(1), tested = null;
+ while( true ) {
+ if( iff.pred()==n ) tested = n;
+ if( !(n instanceof GuardNode guard && guard._nonZero) ) break;
n = guard.in(1);
- throw Utils.TODO("test and remove TODO");
}
CFGNode early = CFGNode.earlyCFG(n);
- return iff.pred()==cast.in(1) && (early==null || early.dominates(r)) ? n : null;
+ return tested!=null && (early==null || early.dominates(r)) ? n : null;
}
// Same op on all Phi paths; all ops have only the Phi as a use.
// None have a control input.
private boolean same_op() {
Node busy=null;
+ if( in(1) instanceof ConstantNode )
+ return false;
for( int i=1; i<nIns(); i++ ) {
Node op = in(i);
if( in(1).getClass() != op.getClass() || op.in(0)!=null || in(1).nIns() != op.nIns() )