From db3ca780c26b78cbe129a5c1bdf0d8ff7d867d1b Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 20 Sep 2026 10:04:48 -0700 Subject: Unify GCM across chapters Remove the _anti field. Remove the isPinned() call. Add a copyEmpty call. --- .../java/com/seaofnodes/simple/Chapter18Test.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'chapter23/src/test') diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter23/src/test/java/com/seaofnodes/simple/Chapter18Test.java index 41b7d139..8e0181b3 100644 --- a/chapter23/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/chapter23/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -11,6 +11,44 @@ import static org.junit.Assert.*; import static org.junit.Assert.fail; public class Chapter18Test { + @Test public void testFunctionLocalConstantChains() { + String src = "val f = { int x -> x ? f(x-1)*305420988+x/305420988 : 1; }; "+ + "val g = { int x -> x ? g(x-1)/305420988+x*305420988 : 1; }; "+ + "return f(arg)+g(arg);"; + CodeGen code = new CodeGen(src); + code.driver(CodeGen.Phase.Schedule,"riscv","SystemV"); + var owners = new java.util.IdentityHashMap(); + code._stop.walk(n -> { + if( !(n instanceof com.seaofnodes.simple.node.cpus.riscv.AddIRISC add) || + !(add.in(1) instanceof com.seaofnodes.simple.node.cpus.riscv.LUI upper) || + ((TypeInteger)upper._con).value()+((add._imm12<<20)>>20)!=305420988 ) + return null; + CFGNode fun = n.cfg0(); + while( fun!=null && !(fun instanceof FunNode) ) fun = fun.idom(); + assertTrue("Constant must belong to a function",fun instanceof FunNode); + assertNull("Share one constant chain within each function",owners.put(fun,true)); + // Follow all parts of a machine constant, including shared inputs. + var todo = new java.util.ArrayList(); + var seen = new java.util.IdentityHashMap(); + todo.add(n); + for( int j=0; j=2); + } + @Test public void testReachableMixedReturns() { for( String[] test : new String[][] { {"if(arg) return 7; else return 2.5;", "No common type amongst int and f64"}, -- cgit v1.2.3