summaryrefslogtreecommitdiff
path: root/chapter13/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'chapter13/src/main/java/com')
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/ScopeNode.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
index 843ce733..455f4b3a 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
+++ b/chapter13/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());