summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/PhiNode.java10
-rw-r--r--chapter25/src/test/java/com/seaofnodes/simple/Eval2.java2
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);