summaryrefslogtreecommitdiff
path: root/chapter20/src
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-20 14:49:32 -0700
committerCliff Click <cliffc@acm.org>2026-09-20 14:49:32 -0700
commit0487ef57a2b7f80fd6f9ed3f6aeea0b0ec88e89f (patch)
treece84334450dbe54ca9ea3c7f39419730b4f86678 /chapter20/src
parent4f3d4859e9096ab8f15c3e9eb02d154c268b108d (diff)
downloadSimple-0487ef57a2b7f80fd6f9ed3f6aeea0b0ec88e89f.tar.gz
Simple-0487ef57a2b7f80fd6f9ed3f6aeea0b0ec88e89f.zip
Add back copy coaleascing in ch21
Minor arm encoding fix.
Diffstat (limited to 'chapter20/src')
-rw-r--r--chapter20/src/main/java/com/seaofnodes/simple/node/ReturnNode.java2
-rw-r--r--chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java17
2 files changed, 18 insertions, 1 deletions
diff --git a/chapter20/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/chapter20/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
index 0220b571..b767b69b 100644
--- a/chapter20/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
+++ b/chapter20/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
@@ -48,7 +48,7 @@ public class ReturnNode extends CFGNode {
@Override
public Type compute() {
if( inProgress () ) return TypeTuple.RET; // In progress
- if( _fun.isDead() ) return TypeTuple.RET.dual(); // Dead another way
+ // Inlining can delete the entry while callers still use this return.
return TypeTuple.make(ctrl()._type,mem()._type,expr()._type);
}
diff --git a/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
index 8e9b0272..00a8407f 100644
--- a/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
+++ b/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
@@ -10,6 +10,23 @@ import static com.seaofnodes.simple.Main.PORTS;
import static org.junit.Assert.*;
public class Chapter20Test {
+ @Test public void testInlinedReturnValue() {
+ String src = """
+struct S { int x; };
+val f = { S s -> s.x = g(); };
+val g = { -> 123; };
+S !s = new S;
+return f(s);
+""";
+ // The entry of g can disappear before its Return is folded into f.
+ // Exercise both worklist orders; deleting the entry does not kill 123.
+ for( int seed=0; seed<64; seed++ ) {
+ CodeGen code = new CodeGen(src,com.seaofnodes.simple.type.TypeInteger.BOT,seed).parse().opto().typeCheck();
+ assertEquals("seed "+seed, "123", Eval2.eval(code,0));
+ }
+ }
+
+
@org.junit.Rule public final org.junit.rules.ErrorCollector _errors = new org.junit.rules.ErrorCollector();
@Test public void testAllocatorMasks() { com.seaofnodes.simple.codegen.RegAllocTestSupport.masks(); }
@Test public void testAllocatorUnion() { com.seaofnodes.simple.codegen.RegAllocTestSupport.union(); }