summaryrefslogtreecommitdiff
path: root/chapter21/src/main
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-04-01 14:26:46 -0700
committerCliff Click <cliffc@acm.org>2025-04-01 14:26:46 -0700
commitf691d2de7217b04844da51c2c6ecc0fd9137c7d6 (patch)
tree3489dbcf5e9cedbd8aecd90c0602468eed4fa46b /chapter21/src/main
parentd8a39c7063ecaa26a3bb962b730837a678ed4d93 (diff)
downloadSimple-f691d2de7217b04844da51c2c6ecc0fd9137c7d6.tar.gz
Simple-f691d2de7217b04844da51c2c6ecc0fd9137c7d6.zip
RA tighter def of being "in" or "out" of loop
Diffstat (limited to 'chapter21/src/main')
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
index 1a4d0120..4162bece 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java
@@ -442,6 +442,22 @@ public class RegAlloc {
int min = (int)ld;
int max = (int)(ld>>32);
int d = cfg.loopDepth();
+ // if n will lower the min loop and is in the tail end of the loop
+ // header, splitting "around" the loop will not help. Treat n as being
+ // in the loop.
+ if( d < min ) {
+ if( cfg.uctrl() instanceof LoopNode loop && loop.entry()==cfg ) {
+ for( int i=cfg.nOuts()-2; i>=0; i-- ) {
+ Node out = cfg.out(i);
+ if( n==out )
+ { d = loop.loopDepth(); break; } // Treat n as being "in the loop"
+ if( !((out instanceof MachNode mach && mach.isClone()) || out instanceof SplitNode ) )
+ break; // Treat b as "normal", out of loop
+ }
+ }
+ }
+
+ // lower min, raise max, and re-fold
min = Math.min(min,d);
max = Math.max(max,d);
return ((long)max<<32) | min;