From dd907c2d86eaaad0910e7bfe3f0d25e5caf8bdf7 Mon Sep 17 00:00:00 2001 From: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Date: Sat, 26 Sep 2026 06:35:22 +0800 Subject: Extend and backport SubNode peephole (#254) * Extend and backport SubNode peephole * Add tests * Restrict subtraction zero peepholes to integer operands Require resolved integer mode in chapter 25 so zero subtraction preserves floating-point signed zero. Keep nonnumeric operands in the graph for subtraction diagnostics. Add signed-zero coverage from chapter 12 and null-subtraction diagnostics from chapter 22. Confirmed the regressions fail on the original PR. Full Make suites pass in chapters 4-25 (5462 tests), including fresh chapter 25 sys.o compilation. --------- Co-authored-by: Cliff Click --- .../java/com/seaofnodes/simple/Chapter04Test.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'chapter04/src/test/java/com') diff --git a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java index 28912d5d..74682310 100644 --- a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java +++ b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java @@ -50,6 +50,34 @@ public class Chapter04Test { assertEquals("return arg;", ret.print()); } + @Test + public void testSub0() { + Parser parser = new Parser("return arg-0;"); + ReturnNode ret = parser.parse(); + assertEquals("return arg;", ret.print()); + } + + @Test + public void test0Sub() { + Parser parser = new Parser("return 0-arg;"); + ReturnNode ret = parser.parse(); + assertEquals("return (-arg);", ret.print()); + } + + @Test + public void testSubNeg() { + Parser parser = new Parser("return 3--arg;"); + ReturnNode ret = parser.parse(); + assertEquals("return (arg+3);", ret.print()); + } + + @Test + public void testNegSub() { + Parser parser = new Parser("return -arg-3;"); + ReturnNode ret = parser.parse(); + assertEquals("return (-(arg+3));", ret.print()); + } + @Test public void testVarArg() { Parser parser = new Parser("return arg; ", TypeInteger.BOT); -- cgit v1.2.3