summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2023-10-30 09:01:57 -0700
committerDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2023-11-01 18:56:50 +0000
commit4410e4e3d7a4b9e0424de7678633e2a7240695cd (patch)
treeb7a9944f86abd8f0cb1eb986d9fd2db0cf68792a
parentb59828ac09a88310640d8b8d3d95a8be0cee1187 (diff)
downloadSimple-4410e4e3d7a4b9e0424de7678633e2a7240695cd.tar.gz
Simple-4410e4e3d7a4b9e0424de7678633e2a7240695cd.zip
Bug fix last peephole
-rw-r--r--chapter05/src/main/java/com/seaofnodes/simple/node/AddNode.java4
-rw-r--r--chapter05/src/main/java/com/seaofnodes/simple/node/PhiNode.java5
-rw-r--r--chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java9
3 files changed, 10 insertions, 8 deletions
diff --git a/chapter05/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter05/src/main/java/com/seaofnodes/simple/node/AddNode.java
index 7cb0f822..1e9cc6c9 100644
--- a/chapter05/src/main/java/com/seaofnodes/simple/node/AddNode.java
+++ b/chapter05/src/main/java/com/seaofnodes/simple/node/AddNode.java
@@ -79,9 +79,9 @@ public class AddNode extends Node {
// Push constant up through the phi: x + (phi con0+con0 con1+con1...)
// Note that this is the exact reverse of Phi pulling a common op
- // down to reduce total op-count. We don't get in a endless push-
+ // down to reduce total op-count. We don't get in an endless push-
// up push-down peephole cycle because the constants all fold first.
- (t2.isConstant() || (rhs instanceof PhiNode && rhs.all_cons()) ) ) {
+ (t2.isConstant() || (rhs instanceof PhiNode && phi.in(0) == rhs.in(0) && rhs.all_cons()) ) ) {
Node[] ns = new Node[phi.nIns()];
ns[0] = phi.in(0);
// Push constant up through the phi: x + (phi con0+con0 con1+con1...)
diff --git a/chapter05/src/main/java/com/seaofnodes/simple/node/PhiNode.java b/chapter05/src/main/java/com/seaofnodes/simple/node/PhiNode.java
index 4334ac10..8e0c9a79 100644
--- a/chapter05/src/main/java/com/seaofnodes/simple/node/PhiNode.java
+++ b/chapter05/src/main/java/com/seaofnodes/simple/node/PhiNode.java
@@ -50,11 +50,6 @@ public class PhiNode extends Node {
}
Node phi_lhs = new PhiNode(lhss).peephole();
Node phi_rhs = new PhiNode(rhss).peephole();
- //if( phi_lhs instanceof PhiNode && phi_rhs instanceof PhiNode ) {
- // phi_lhs.kill();
- // phi_rhs.kill();
- // return null; // No progress, no profit
- //}
return op.copy(phi_lhs,phi_rhs);
}
diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 7089e000..a4bf89ec 100644
--- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -69,7 +69,14 @@ return c;
StopNode stop = parser.parse();
assertEquals("return Phi(Region33,Phi(Region21,2,3),Phi(Region31,4,5));", stop.toString());
}
-
+
+ @Test
+ public void testChapter5Merge4() {
+ Parser parser = new Parser("int a=0;int b=0;if(arg)a=1;if(arg==0)b=2;return arg+a+b;#showGraph;", TypeInteger.BOT);
+ StopNode stop = parser.parse();
+ assertEquals("return ((arg+Phi(Region13,1,0))+Phi(Region23,2,0));", stop.toString());
+ }
+
@Test
public void testChapter5True() {
StopNode stop = new Parser("return true;").parse();