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 | |
| 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')
3 files changed, 17 insertions, 8 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() ) diff --git a/chapter25/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter25/src/test/java/com/seaofnodes/simple/FuzzerWrap.java index a4532eb2..3aaa290a 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/FuzzerWrap.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/FuzzerWrap.java @@ -20,12 +20,16 @@ public class FuzzerWrap { -6359653295501938199L, // monotonicity, escape is dead 6506797708065910879L, // missing ModeNode._mode is optimistic 650692970082394944L, // recursive bulk mem split + 8335100609598232836L, // ternary result killed by region cleanup + 2520958273643234516L, // nested guard merge + -3772838984504063325L, // fuzzer regression }; private static final long[] OPEN_FAILING_SEEDS = { - 8335100609598232836L, - 2520958273643234516L, - -3772838984504063325L, + -4628356252269023530L, + -4022199781524079249L, + 8824787517620928178L, + -673501011619761901L, }; |
