From 3652f49f679de25a2544225d6a3600a63b693ba0 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Wed, 13 Nov 2024 16:12:16 -0800 Subject: Bug fix loop depth on infinite split-tail loops --- .../src/main/java/com/seaofnodes/simple/node/IfNode.java | 3 +++ .../main/java/com/seaofnodes/simple/node/LoopNode.java | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'chapter17/src/main/java') diff --git a/chapter17/src/main/java/com/seaofnodes/simple/node/IfNode.java b/chapter17/src/main/java/com/seaofnodes/simple/node/IfNode.java index 41de4c82..2f3798d7 100644 --- a/chapter17/src/main/java/com/seaofnodes/simple/node/IfNode.java +++ b/chapter17/src/main/java/com/seaofnodes/simple/node/IfNode.java @@ -43,6 +43,9 @@ public class IfNode extends CFGNode implements MultiNode { // Else true branch is reachable if( t.isConstant() ) return t.makeInit()==t ? TypeTuple.IF_FALSE : TypeTuple.IF_TRUE; + // Integers allow non-zero ranges: "1-65535" + if( t.makeZero().meet(t) != t ) + return TypeTuple.IF_TRUE; return TypeTuple.IF_BOTH; } diff --git a/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java b/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java index 27134420..e5f34833 100644 --- a/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java +++ b/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java @@ -39,15 +39,12 @@ public class LoopNode extends RegionNode { for( CFGNode idom = back(); idom!=this; idom = idom.idom() ) { // Walk idom in loop, setting depth idom._loopDepth = _loopDepth; - // Loop exit hits the CProj before the If, instead of jumping from - // Region directly to If. - if( idom instanceof CProjNode proj ) { - assert proj.in(0) instanceof IfNode; // Loop exit test - // Find the loop exit CProj, and set loop_depth - for( Node use : proj.in(0)._outputs ) - if( use instanceof CProjNode proj2 && proj2 != idom ) - proj2._loopDepth = _loopDepth-1; - } + // Mark backedge loop depth. The loop exit hits the CProj before the + // If, instead of jumping from Region directly to If. The other + // arm is either a loop exit OR if this is a split tail the other + // arm leads to a inner loop. + if( idom instanceof CProjNode cproj ) + break; } return _loopDepth; } @@ -62,7 +59,6 @@ public class LoopNode extends RegionNode { while( x != this ) { if( x instanceof CProjNode exit && exit.in(0) instanceof IfNode iff ) { CFGNode other = iff.cproj(1-exit._idx); - //if( !(other.out(0) instanceof LoopNode loop) || loop.entry()==exit ) if( other.loopDepth() < loopDepth() ) return; // Found an exit, not an infinite loop } -- cgit v1.2.3