diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-16 16:23:52 -0800 |
| commit | 0b263f550d5e54d050f58f6b315b092944c9eff9 (patch) | |
| tree | aff564cf11711c41a6f94f17ffbc480e1b228da1 /src/test/java/com/seaofnodes/simple/Chapter05Test.java | |
| parent | 790268f4a1f6122376c34059f1633c1017436363 (diff) | |
| download | Simple-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/Chapter05Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter05Test.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/src/test/java/com/seaofnodes/simple/Chapter05Test.java index ed4a54bd..9f733da5 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -202,19 +202,17 @@ return a; catch( RuntimeException e ) { assertEquals("Undefined name 'ififif'",e.getMessage()); } } - private static <N extends Node> N init(N n) { n._type=n.compute(); return n; } - @Test public void testDoublingBeforeAndAfterStrengthReduction() { - for( boolean reduced : new boolean[]{false,true} ) + for( boolean shift : new boolean[]{false,true} ) for( boolean reverse : new boolean[]{false,true} ) { CodeGen code = new CodeGen(""); - Node ctrl = init(new CProjNode(code._start,0,"Ctrl")); - RegionNode region = init(new RegionNode(null,null,ctrl,ctrl)); - Node p = code.con(TypeInteger.BOT); - Node i = init(new MinusNode(p)); - Node twice = reduced ? init(new ShlNode(null,p,code.con(1))) : init(new AddNode(p,p,(byte)1)); - Node sum = init(new AddNode(i,p,(byte)1)); - PhiNode phi = init(new PhiNode("sum",region,reverse ? sum : twice,reverse ? twice : sum)); + Node ctrl = new CProjNode(code._start,0,"Ctrl").init(); + RegionNode region = new RegionNode(null,null,ctrl,ctrl).init(); + Node p = code.con(TypeInteger.BOT), i = code.con(TypeInteger.I32); + Node twice = shift ? new ShlNode(null,p,code.con(1)).init() + : new AddNode(p,p,(byte)1).init(); + Node sum = new AddNode(i,p,(byte)1).init(); + PhiNode phi = new PhiNode("sum",region,reverse ? sum : twice,reverse ? twice : sum).init(); phi.keep(); Node factored = phi.idealize(); assertTrue(factored instanceof AddNode); @@ -225,4 +223,17 @@ return a; phi.unkeep(); } } + + @Test public void testOtherShiftIsNotDoubling() { + CodeGen code = new CodeGen(""); + Node ctrl = new CProjNode(code._start,0,"Ctrl").init(); + RegionNode region = new RegionNode(null,null,ctrl,ctrl).init(); + Node p = code.con(TypeInteger.BOT), i = code.con(TypeInteger.I32); + Node shift = new ShlNode(null,p,code.con(2)).init(); + Node sum = new AddNode(i,p,(byte)1).init(); + PhiNode phi = new PhiNode("sum",region,shift,sum).init(); + phi.keep(); + assertNull(phi.idealize()); + phi.unkeep(); + } } |
