summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chapter18/src/main/java/com/seaofnodes/simple/Parser.java2
-rw-r--r--chapter18/src/main/java/com/seaofnodes/simple/node/LoopNode.java17
-rw-r--r--chapter18/src/main/java/com/seaofnodes/simple/node/RegionNode.java13
3 files changed, 11 insertions, 21 deletions
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
index 4f19dda2..03ae978a 100644
--- a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java
@@ -1301,6 +1301,7 @@ public class Parser {
if( matchx("++") || matchx("--") ) {
if( f._final && !f._fname.equals("[]") )
throw error("Cannot reassign final '"+f._fname+"'");
+ load.keep();
int delta = _lexer.peek(-1)=='+' ? 1 : -1; // Pre vs post
Node val = f._type instanceof TypeFloat
? peep(new AddFNode(load,con(TypeFloat.constant(delta))))
@@ -1311,6 +1312,7 @@ public class Parser {
// done via the type system.
if( base.isAry() ) st.setDef(0,ctrl());
memAlias(f._alias, peep(st));
+ load.unkeep();
// And use the original loaded value as the result
} else expr.unkill();
off.unkill();
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/node/LoopNode.java b/chapter18/src/main/java/com/seaofnodes/simple/node/LoopNode.java
index a31c8ac8..f70a1012 100644
--- a/chapter18/src/main/java/com/seaofnodes/simple/node/LoopNode.java
+++ b/chapter18/src/main/java/com/seaofnodes/simple/node/LoopNode.java
@@ -23,23 +23,6 @@ public class LoopNode extends RegionNode {
return entry()._type;
}
- @Override
- public Node idealize() {
- if( inProgress() ) return null;
- // Dead infinite loops with NO control flow out stick around - as a
- // dead infinite loop, to signal that control stops and spins here.
- if( nIns()==2 && !hasPhi() && !hasCFG() )
- return null;
- return super.idealize();
- }
-
- private boolean hasCFG() {
- for( Node phi : _outputs )
- if( phi instanceof CFGNode )
- return true;
- return false;
- }
-
// Bypass Region idom, same as the default idom() using use in(1) instead of in(0)
@Override public int idepth() { return _idepth==0 ? (_idepth=idom().idepth()+1) : _idepth; }
// Bypass Region idom, same as the default idom() using use in(1) instead of in(0)
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/node/RegionNode.java b/chapter18/src/main/java/com/seaofnodes/simple/node/RegionNode.java
index d8e24964..ea053c02 100644
--- a/chapter18/src/main/java/com/seaofnodes/simple/node/RegionNode.java
+++ b/chapter18/src/main/java/com/seaofnodes/simple/node/RegionNode.java
@@ -68,13 +68,18 @@ public class RegionNode extends CFGNode {
return in(1); // Collapse if no Phis; 1-input Phis will collapse on their own
// If a CFG diamond with no merging, delete: "if( pred ) {} else {};"
- if( !_disablePeephole &&
- !hasPhi() && // No Phi users, just a control user
+ if( !_disablePeephole && // Optional
+ !hasPhi() && // No Phi users, just a control user
in(1) instanceof CProjNode p1 &&
in(2) instanceof CProjNode p2 &&
p1.in(0).addDep(this)==p2.in(0).addDep(this) &&
- p1.in(0) instanceof IfNode iff )
- return iff.ctrl();
+ p1.in(0) instanceof IfNode iff ) {
+ // Replace with the iff.ctrl directly
+ if( nIns()==3 ) return iff.ctrl();
+ // Just delete the path for fat Regions
+ setDef(1,iff.ctrl());
+ return delDef(2);
+ }
return null;
}