diff options
| author | Cliff Click <cliffc@acm.org> | 2026-09-14 09:08:05 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-09-14 09:08:05 -0700 |
| commit | 86339c69320760c5b1acae681b9938d4c9f897f6 (patch) | |
| tree | 7bec44f669f28d2736b6abe95ee9d0f5298bc5eb /chapter25/src/main/java/com | |
| parent | 56889e162ce25b16978708c6037ddf2961e89546 (diff) | |
| download | Simple-86339c69320760c5b1acae681b9938d4c9f897f6.tar.gz Simple-86339c69320760c5b1acae681b9938d4c9f897f6.zip | |
Refinement on guard removal
Fix keep/unkeep balance.
Always fuzz small.
Diffstat (limited to 'chapter25/src/main/java/com')
| -rw-r--r-- | chapter25/src/main/java/com/seaofnodes/simple/Parser.java | 3 | ||||
| -rw-r--r-- | chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java | 12 |
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() ) |
