diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-05 09:35:31 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-05 09:35:31 -0700 |
| commit | 3e950abc9eb2bcafbb36761ace5fcf5707a503a3 (patch) | |
| tree | 263244543dc0a63d454b16521a30ccb4526f58e1 /chapter19/src/main | |
| parent | 9b3ad43f7aa2ec6d5f61fb9ff3c432101a5fba52 (diff) | |
| download | Simple-3e950abc9eb2bcafbb36761ace5fcf5707a503a3.tar.gz Simple-3e950abc9eb2bcafbb36761ace5fcf5707a503a3.zip | |
Partial integer updateabandoned
Diffstat (limited to 'chapter19/src/main')
10 files changed, 10 insertions, 10 deletions
diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/AddNode.java index 5a42e2e8..cdc09027 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/AddNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/AddNode.java @@ -49,7 +49,7 @@ public class AddNode extends Node { // Add of 0. We do not check for (0+x) because this will already // canonicalize to (x+0) - if( t2 == TypeInteger.ZERO ) + if( t2 == TypeInteger.ZERO && lhs._type instanceof TypeInteger ) return lhs; // Add of same to a multiply by 2 diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/AndNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/AndNode.java index 36e3a949..461a8f9b 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/AndNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/AndNode.java @@ -39,7 +39,7 @@ public class AndNode extends LogicalNode { // And of -1. We do not check for (-1&x) because this will already // canonicalize to (x&-1) - if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==-1 ) + if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==-1 && lhs._type instanceof TypeInteger ) return lhs; // Move constants to RHS: con*arg becomes arg*con diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/DivNode.java index 0d5ed297..82cafdea 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/DivNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/DivNode.java @@ -36,7 +36,7 @@ public class DivNode extends Node { @Override public Node idealize() { // Div of 1. - if( in(2)._type == TypeInteger.TRUE ) + if( in(2)._type == TypeInteger.TRUE && in(1)._type instanceof TypeInteger ) return in(1); return null; } diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/MinusNode.java index dd2cbd26..dafdb6b4 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/MinusNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/MinusNode.java @@ -31,7 +31,7 @@ public class MinusNode extends Node { @Override public Node idealize() { // -(-x) is x - if( in(1) instanceof MinusNode minus ) + if( in(1) instanceof MinusNode minus && minus.in(1)._type instanceof TypeInteger ) return minus.in(1); return null; diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/MulNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/MulNode.java index 53472994..7593d3a0 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/MulNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/MulNode.java @@ -50,7 +50,7 @@ public class MulNode extends Node { // Mul of 1. We do not check for (1*x) because this will already // canonicalize to (x*1) long c = i.value(); - if( c==1 ) return lhs; + if( c==1 ) return lhs._type instanceof TypeInteger ? lhs : null; if( c==0 ) return Parser.ZERO; // Mul by a power of 2, +/-1. Bit patterns more complex than this // are unlikely to win on an X86 vs the normal "imul", and so diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/OrNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/OrNode.java index 9b03dc5d..dfa32378 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/OrNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/OrNode.java @@ -36,7 +36,7 @@ public class OrNode extends LogicalNode { // Or of 0. We do not check for (0|x) because this will already // canonicalize to (x|0) - if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 ) + if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 && lhs._type instanceof TypeInteger ) return lhs; // Move constants to RHS: con*arg becomes arg*con diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/SarNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/SarNode.java index 4a71ec06..cb48f1c8 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/SarNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/SarNode.java @@ -39,7 +39,7 @@ public class SarNode extends LogicalNode { Type t2 = rhs._type; // Sar of 0. - if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 ) + if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && lhs._type instanceof TypeInteger ) return lhs; // TODO: x >> 3 >> (y ? 1 : 2) ==> x >> (y ? 4 : 5) diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/ShlNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/ShlNode.java index 21dbd503..ee2e8e54 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/ShlNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/ShlNode.java @@ -35,7 +35,7 @@ public class ShlNode extends LogicalNode { if( rhs._type instanceof TypeInteger shl && shl.isConstant() ) { // Shl of 0. - if( (shl.value()&63)==0 ) + if( (shl.value()&63)==0 && lhs._type instanceof TypeInteger ) return lhs; // (x + c) << i => (x << i) + (c << i) if( lhs instanceof AddNode add && add.addDep(this).in(2)._type instanceof TypeInteger c && c.isConstant() ) { diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/ShrNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/ShrNode.java index 789fb8a8..97673d9a 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/ShrNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/ShrNode.java @@ -35,7 +35,7 @@ public class ShrNode extends LogicalNode { Type t2 = rhs._type; // Shr of 0. - if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 ) + if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && lhs._type instanceof TypeInteger ) return lhs; // TODO: x >>> 3 >>> (y ? 1 : 2) ==> x >>> (y ? 4 : 5) diff --git a/chapter19/src/main/java/com/seaofnodes/simple/node/XorNode.java b/chapter19/src/main/java/com/seaofnodes/simple/node/XorNode.java index 37d7147d..03d7bf3d 100644 --- a/chapter19/src/main/java/com/seaofnodes/simple/node/XorNode.java +++ b/chapter19/src/main/java/com/seaofnodes/simple/node/XorNode.java @@ -35,7 +35,7 @@ public class XorNode extends LogicalNode { // Xor of 0. We do not check for (0^x) because this will already // canonicalize to (x^0) - if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 ) + if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 && lhs._type instanceof TypeInteger ) return lhs; // Move constants to RHS: con*arg becomes arg*con |
