From 5b07c027577503f4d9ecb7ea6c950cb24a144347 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 11 Sep 2026 16:56:07 -0700 Subject: Removing a phi-of-guard, remove nested guards --- .../src/main/java/com/seaofnodes/simple/node/PhiNode.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'chapter25/src/main/java/com') 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 2b6d2666..17868faf 100644 --- a/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java +++ b/chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java @@ -125,13 +125,19 @@ public class PhiNode extends Node { // If merging Phi(ZERO, guardNZ(N)) - we are losing the cast JOIN effects, so just remove. if( nIns()==3 ) { - if( in(1) instanceof GuardNode cast && cast._nonZero && in(2)._type.makeZero()==in(2)._type && cast.in(1)!=this ) return cast.in(1); - if( in(2) instanceof GuardNode cast && cast._nonZero && in(1)._type.makeZero()==in(1)._type && cast.in(1)!=this ) return cast.in(1); + if( in(1) instanceof GuardNode cast && cast._nonZero && in(2)._type.makeZero()==in(2)._type && cast.in(1)!=this ) return unguard(cast.in(1)); + if( in(2) instanceof GuardNode cast && cast._nonZero && in(1)._type.makeZero()==in(1)._type && cast.in(1)!=this ) return unguard(cast.in(1)); } return null; } + private static Node unguard(Node n) { + while( n instanceof GuardNode guard ) + n = guard.in(1); + return n; + } + // Same op on all Phi paths; all ops have only the Phi as a use. // None have a control input. private boolean same_op() { -- cgit v1.2.3