summaryrefslogtreecommitdiff
path: root/chapter13/src/test
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-10-19 10:40:35 -0700
committerCliff Click <cliffc@acm.org>2026-10-19 10:40:35 -0700
commite7eb2db06d1b9c529f94f2da3a087c83c0498e05 (patch)
tree17a21219c7a28017b361bdeec011dda0afc562dc /chapter13/src/test
parentef8d9c4630db6af79c25526c8e80c54a48df4e39 (diff)
downloadSimple-e7eb2db06d1b9c529f94f2da3a087c83c0498e05.tar.gz
Simple-e7eb2db06d1b9c529f94f2da3a087c83c0498e05.zip
Turn off Store GVN with explaination
Diffstat (limited to 'chapter13/src/test')
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index 6649c0b0..7fa9978d 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -11,6 +11,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter10Test {
+ @Test public void testConditionalStoreSharing() {
+ // Sharing the writes on two of three paths must not write on the third.
+ // Return the object so Load forwarding cannot hide the physical Store.
+ String src = """
+ struct S { int x; };
+ S a = new S;
+ a.x = 10;
+ if (arg == 1) a.x = 9;
+ else if (arg == 2) a.x = 9;
+ return a;
+ """;
+ var stop = new Parser(src).parse().iterate();
+ for( int arg : new int[]{0,1,2,3} ) {
+ long expected = (arg==1 || arg==2) ? 9 : 10;
+ var obj = (com.seaofnodes.simple.evaluator.Evaluator.Obj)
+ com.seaofnodes.simple.evaluator.Evaluator.evaluate(stop,arg);
+ assertEquals(expected,obj.fields()[0]);
+ }
+ }
+
@Test public void testDeadReferenceReturn() {
for( String body : new String[] {
"return new S; return 0;",
@@ -540,14 +560,14 @@ return 0;
assertEquals(3L,Evaluator.evaluate(stop,3));
}
- @Test public void testDropStores() {
+ @Test public void testKeepBranchStores() {
StopNode stop = new Parser("""
struct S { int x; }
S s = new S;
if (arg) s.x=arg+1; else s.x=arg+2;
return s;
""").parse().iterate();
- // These chapters still bind struct Stores to branch control.
+ // Two branch Stores plus the initial zero Store.
assertEquals(3,countMemoryNodes(stop,StoreNode.class,new BitSet()));
assertEquals(2L,((Evaluator.Obj)Evaluator.evaluate(stop,0)).fields()[0]);
assertEquals(4L,((Evaluator.Obj)Evaluator.evaluate(stop,3)).fields()[0]);