Skip to content

Commit

Permalink
UF LRGs can be null during coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffclick committed Feb 13, 2025
1 parent 9951333 commit faa8cbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.seaofnodes.simple.Utils;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeMem;

abstract public class BuildLRG {
// Compute live ranges in a single forwards pass. Every def is a new live
Expand Down Expand Up @@ -32,7 +33,7 @@ public static boolean run(int round, RegAlloc alloc) {
}
}

} else if( n instanceof PhiNode phi ) {
} else if( n instanceof PhiNode phi && !(phi._type instanceof TypeMem) ) {
// All 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public static boolean color(int round, RegAlloc alloc) {
swap(color_stack,sptr,pickRisky(color_stack,sptr));
// Pick a trivial lrg, and (temporarily) remove from the IFG.
LRG lrg = color_stack[sptr++];
if( lrg==null ) continue;
// If sptr was swork, then pulled an at-risk lrg
if( sptr > swork )
swork = sptr;
Expand All @@ -310,6 +311,7 @@ public static boolean color(int round, RegAlloc alloc) {
// Reverse simplify (unstack the color stack), and set colors (registers) for live ranges
while( sptr > 1 ) {
LRG lrg = color_stack[--sptr];
if( lrg==null ) continue;
RegMaskRW rmask = lrg._mask.copy();
// Walk neighbors and remove adjacent colors
if( lrg._adj!=null ) {
Expand Down
16 changes: 16 additions & 0 deletions chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ public void testAlloc2() {
assertEquals("return .[];", code.print());
}

@Test
public void testArray1() {
CodeGen code = new CodeGen(
"""
int[] !ary = new int[arg];
// Fill [0,1,2,3,4,...]
for( int i=0; i<ary#; i++ )
ary[i] = i;
// Fill [0,1,3,6,10,...]
for( int i=0; i<ary#-1; i++ )
ary[i+1] += ary[i];
return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6
""");
code.parse().opto().typeCheck().instSelect("x86_64_v2", "SystemV").GCM().localSched().regAlloc();
assertEquals("return .[];", code.print());
}
}

0 comments on commit faa8cbf

Please sign in to comment.