diff options
| author | Cliff Click <cliffc@acm.org> | 2026-09-11 16:56:07 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-09-11 16:56:07 -0700 |
| commit | 5b07c027577503f4d9ecb7ea6c950cb24a144347 (patch) | |
| tree | 6501296eb5399b84498bd581dbe0488e54cc1761 /chapter25/src | |
| parent | 5d1e4944f474191bedbd61b311114e361cd7ed32 (diff) | |
| download | Simple-5b07c027577503f4d9ecb7ea6c950cb24a144347.tar.gz Simple-5b07c027577503f4d9ecb7ea6c950cb24a144347.zip | |
Removing a phi-of-guard, remove nested guards
Diffstat (limited to 'chapter25/src')
| -rw-r--r-- | chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java | 10 | ||||
| -rw-r--r-- | chapter25/src/test/java/com/seaofnodes/simple/Eval2.java | 2 |
2 files changed, 9 insertions, 3 deletions
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() { diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java b/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java index f8d8fe18..715c499e 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/Eval2.java @@ -283,7 +283,7 @@ public abstract class Eval2 { case GuardNode guard -> val(guard.in(1)); case ConstantNode con -> con(con._con); case DivNode div -> div.mode()==1 - ? (Object)(x(div.in(1)) / x(div.in(2))) + ? (Object)(x(div.in(2))==0 ? 0L : x(div.in(1)) / x(div.in(2))) : (Object)((d(div.in(2))==0 ? 0D : d(div.in(1))) / d(div.in(2))); case EscapeNode esc -> esc(esc); case FunPtrNode fptr -> con(fptr._con); |
