From d5352268a0a1355262eed78e3263c18486fb9d8a Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 2 Oct 2026 11:20:00 -0700 Subject: Fix bug loop tree depth on inf loops --- .../src/main/java/com/seaofnodes/simple/codegen/BuildLRG.java | 9 +++++++-- chapter21/src/main/java/com/seaofnodes/simple/codegen/IFG.java | 3 +++ .../src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java | 6 +++++- .../src/main/java/com/seaofnodes/simple/node/CFGNode.java | 10 +++++++++- .../src/main/java/com/seaofnodes/simple/node/LoopNode.java | 10 +++++----- 5 files changed, 29 insertions(+), 9 deletions(-) (limited to 'chapter21/src/main/java') diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/BuildLRG.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/BuildLRG.java index f4ce4366..2319714b 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/BuildLRG.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/BuildLRG.java @@ -1,6 +1,7 @@ package com.seaofnodes.simple.codegen; import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeMem; abstract public class BuildLRG { @@ -16,8 +17,10 @@ abstract public class BuildLRG { public static boolean run(int round, RegAlloc alloc) { for( Node bb : alloc._code._cfg ) for( Node n : bb.outs() ) { + // A synthetic never-exit value has no runtime definition. + if( n._type==Type.TOP ) continue; if( n instanceof PhiNode phi && !(phi._type instanceof TypeMem) ) { - // All Phi inputs end up with the same LRG. + // All real Phi inputs end up with the same LRG. // Pass 1: find any pre-existing LRG, to avoid make-then-Union a LRG LRG lrg = alloc.lrg(phi); if( lrg == null ) @@ -30,7 +33,9 @@ abstract public class BuildLRG { // Pass 2: everybody uses the same LRG lrg=alloc.union(lrg,phi); for( int i=phi instanceof ParmNode ? 2 : 1; i