summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/SchedulingTest.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-08-10 11:11:18 -0700
committerCliff Click <cliffc@acm.org>2026-11-16 16:23:52 -0800
commit0b263f550d5e54d050f58f6b315b092944c9eff9 (patch)
treeaff564cf11711c41a6f94f17ffbc480e1b228da1 /src/test/java/com/seaofnodes/simple/SchedulingTest.java
parent790268f4a1f6122376c34059f1633c1017436363 (diff)
downloadSimple-linear-chapter32.tar.gz
Simple-linear-chapter32.zip
Chapter 32: Compiler Internal Speedupslinear-chapter32linear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: Jun Kawasaki <jun784@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/SchedulingTest.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/SchedulingTest.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/com/seaofnodes/simple/SchedulingTest.java b/src/test/java/com/seaofnodes/simple/SchedulingTest.java
index 16e12b0f..28b84ee1 100644
--- a/src/test/java/com/seaofnodes/simple/SchedulingTest.java
+++ b/src/test/java/com/seaofnodes/simple/SchedulingTest.java
@@ -1,8 +1,47 @@
package com.seaofnodes.simple;
import org.junit.Test;
+import com.seaofnodes.simple.codegen.CodeGen;
+import com.seaofnodes.simple.codegen.IterPeeps;
+import com.seaofnodes.simple.node.*;
+import com.seaofnodes.simple.type.*;
+import static org.junit.Assert.*;
public class SchedulingTest {
+ @Test public void verifierAllowsLoadAfterMemoryMerge() {
+ CodeGen code = loadAfterMemoryMerge();
+ assertTrue(IterPeeps.schedulableUses(code));
+ }
+
+ @Test public void verifierRejectsLoadUsedBeforeMemoryMerge() {
+ CodeGen code = loadAfterMemoryMerge();
+ ReturnNode ret = (ReturnNode)code._stop.walk(n -> n instanceof ReturnNode ? n : null);
+ LoadNode load = (LoadNode)ret.expr();
+ // The load may move below its check, but cannot serve a use above its memory.
+ ret.setDef(0,load.in(0));
+ try {
+ IterPeeps.schedulableUses(code);
+ fail("A load cannot execute before its memory is available");
+ } catch( AssertionError error ) {
+ assertTrue(error.getMessage(),error.getMessage().contains("Unschedulable data node LoadNode"));
+ }
+ }
+
+ private static CodeGen loadAfterMemoryMerge() {
+ CodeGen code = new CodeGen("return arg;").parse();
+ ReturnNode ret = (ReturnNode)code._stop.walk(n -> n instanceof ReturnNode ? n : null);
+ Node ctrl = ret.ctrl();
+ IfNode iff = new IfNode(ctrl,ret.expr()).init();
+ Node yes = new CProjNode(iff,0,"True").init();
+ Node no = new CProjNode(iff,1,"False").init();
+ RegionNode region = new RegionNode(null,null,yes,no).init();
+ Node phi = new BulkMemPhiNode("mem",region,ret.mem(),ret.mem()).init();
+ Node mem = new MemMergeNode(null,phi).init();
+ Node load = new LoadNode(null,"[]",2,ctrl,mem,code.con(TypeMemPtr.BOT),code.con(TypeInteger.ZERO)).init();
+ ret.setDef(0,region);
+ ret.setDef(2,load);
+ return code;
+ }
@Test public void nativeFoldedLoadsWithLaterOperands() throws Exception {
TestC.runSYS("""
val compare_noInline={ i64[] a, int flag ->