diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-05 15:38:06 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-05 15:38:06 -0700 |
| commit | 81b654d76444d747fdf1d053760e507b50f26e18 (patch) | |
| tree | 594fa806fc31d848f172d0413de0e431fde6e22a /chapter22/src/test | |
| parent | 3b8ad2977ef3911aed7c681037e4640dca59749b (diff) | |
| download | Simple-81b654d76444d747fdf1d053760e507b50f26e18.tar.gz Simple-81b654d76444d747fdf1d053760e507b50f26e18.zip | |
Small peep to drop simple store-updates out of loops
Diffstat (limited to 'chapter22/src/test')
6 files changed, 22 insertions, 13 deletions
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java index a38e93c1..439333ca 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java @@ -36,7 +36,8 @@ public class Chapter11Test { var stop = code._stop; int[] phis = {0}; stop.walk(n -> { - if (n instanceof MemPhiNode) phis[0]++; + // Store sinking can replace field memory Phis with value Phis. + if (n instanceof PhiNode) phis[0]++; if (n instanceof MemMergeNode m && m.in(1) instanceof BulkMemPhiNode b) for(int a=b._aliases.nextSetBit(0); a>=0; a=b._aliases.nextSetBit(a+1)) assertTrue(a<m.nIns() && m.in(a)!=null); @@ -44,7 +45,7 @@ public class Chapter11Test { !(n instanceof MemPhiNode) && !(n instanceof BulkMemPhiNode) && !(n instanceof ParmNode)); return null; }); - assertTrue(phis[0]>=3); + assertTrue(phis[0]>=4); // Three fields and the loop counter. assertEquals("S{x=1,y=2,z=3}",Eval2.eval(code,4)); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java index e7b72e0a..dee7d928 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java @@ -385,13 +385,21 @@ return sq(arg) + sq(3); private static java.util.ArrayList<String> memoryPhis(Node stop) { var phis = new java.util.ArrayList<String>(); - stop.walk(n -> { + // Count only definitions reachable from Stop, as instruction selection does. + // A dead Phi cycle can still appear through the reverse use edges. + var seen = new java.util.BitSet(); + var work = new java.util.ArrayList<Node>(); + work.add(stop); + for( int i=0; i<work.size(); i++ ) { + Node n = work.get(i); + if( n==null || seen.get(n._nid) ) continue; + seen.set(n._nid); + for( Node def : n._inputs ) work.add(def); if( n instanceof MemPhiNode phi ) phis.add("alias:"+phi._alias); if( n instanceof BulkMemPhiNode phi ) phis.add("bulk:"+phi._aliases); assertFalse(n instanceof PhiNode && n.isMem() && !(n instanceof MemPhiNode) && !(n instanceof BulkMemPhiNode) && !(n instanceof ParmNode)); - return null; - }); + } java.util.Collections.sort(phis); return phis; } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java index d5521c03..2ec29f99 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java @@ -242,7 +242,7 @@ hashCode(s); for( String cpu : new String[]{"x86_64_v2","riscv","arm"} ) new CodeGen(src,com.seaofnodes.simple.type.TypeInteger.BOT,0) .driver(CodeGen.Phase.Encoding,cpu,"SystemV"); - testTarget(src,"x86_64_v2", "SystemV",9,null); + testTarget(src,"x86_64_v2", "SystemV",0,null); testTarget(src,"riscv" , "SystemV",1,null); testTarget(src,"arm" , "SystemV",0,null); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 3d74f7a5..2c91de0d 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -310,8 +310,8 @@ public class Chapter21Test { @Test public void testInfinite() { String src = "struct S { int i; }; !S !s = new S; while(1) s.i++;"; testCPU(src,"x86_64_v2", "SystemV",0,"return Top;"); - testCPU(src,"riscv" , "SystemV",2,"return Top;"); - testCPU(src,"arm" , "SystemV",2,"return Top;"); + testCPU(src,"riscv" , "SystemV",0,"return Top;"); + testCPU(src,"arm" , "SystemV",0,"return Top;"); } @Test diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java index 30152640..2d94b8f0 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java @@ -181,8 +181,8 @@ public class Chapter22Test { @Test public void testInfiniteReturn() { String src = "struct S { int i; }; !S !s = new S; while(1) s.i++; return s.i;"; testCPU(src,"x86_64_v2","SystemV",0,"return Top;"); - testCPU(src,"riscv","SystemV",2,"return Top;"); - testCPU(src,"arm","SystemV",2,"return Top;"); + testCPU(src,"riscv","SystemV",0,"return Top;"); + testCPU(src,"arm","SystemV",0,"return Top;"); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java b/chapter22/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java index 2776898f..4bd36256 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/MemoryEncodingTest.java @@ -142,12 +142,12 @@ public class MemoryEncodingTest { } @Test public void testNeverMemory() { - // A synthetic exit must retain both precise slices of a no-exit loop. + // A varying pointer prevents store sinking: the synthetic exit needs both slices. for( String target : new String[]{"x86_64_v2","riscv","arm"} ) { CodeGen code = new CodeGen(""" struct S { int x; int y; }; - !S !a=new S; - if( arg ) while( 1 ) { a.x+=arg; a.y+=a.x; } + !S !a=new S; !S !b=new S; !S !p=a; + if( arg ) while( 1 ) { p.x+=arg; p.y+=p.x; p=p==a ? b : a; } return a.x+a.y; """).driver(CodeGen.Phase.LoopTree); assertNotNull(code._stop.walk(n -> { |
