From 81b654d76444d747fdf1d053760e507b50f26e18 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 5 Oct 2026 15:38:06 -0700 Subject: Small peep to drop simple store-updates out of loops --- .../src/test/java/com/seaofnodes/simple/Chapter11Test.java | 5 +++-- .../src/test/java/com/seaofnodes/simple/Chapter19Test.java | 14 +++++++++++--- .../src/test/java/com/seaofnodes/simple/Chapter20Test.java | 2 +- .../src/test/java/com/seaofnodes/simple/Chapter21Test.java | 4 ++-- .../src/test/java/com/seaofnodes/simple/Chapter22Test.java | 4 ++-- .../java/com/seaofnodes/simple/MemoryEncodingTest.java | 6 +++--- 6 files changed, 22 insertions(+), 13 deletions(-) (limited to 'chapter22/src/test/java') 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=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 memoryPhis(Node stop) { var phis = new java.util.ArrayList(); - 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(); + work.add(stop); + for( int i=0; i { -- cgit v1.2.3