From bf3e5632ddf21c109f7ef0f61bcc62e2ed0f9d49 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 19 Sep 2026 10:30:13 -0700 Subject: Handle double-negation preserving not-null knowledge --- chapter11/src/main/java/com/seaofnodes/simple/node/ScopeNode.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'chapter11/src/main/java') diff --git a/chapter11/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter11/src/main/java/com/seaofnodes/simple/node/ScopeNode.java index 843ce733..455f4b3a 100644 --- a/chapter11/src/main/java/com/seaofnodes/simple/node/ScopeNode.java +++ b/chapter11/src/main/java/com/seaofnodes/simple/node/ScopeNode.java @@ -254,6 +254,13 @@ public class ScopeNode extends Node { // combinations, and replaces the variable with the upcast variant. public Node upcast( Node ctrl, Node pred, boolean invert ) { if( ctrl._type==Type.XCONTROL ) return null; + // A single negation is handled below. For !!p (including p != null), + // also refine the underlying p without changing the Boolean result. + if( pred instanceof NotNode not && not.in(1) instanceof NotNode ) { + pred.keep(); // Recursive peepholes may rediscover this Not. + upcast(ctrl,not.in(1),!invert); + pred.unkeep(); + } // Invert the If conditional if( invert ) pred = pred instanceof NotNode not ? not.in(1) : IterPeeps.add(new NotNode(pred).peephole()); -- cgit v1.2.3