summaryrefslogtreecommitdiff
path: root/chapter25/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter25/src/main/java')
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/AddNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/DivNode.java4
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/MinusNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/MulNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/SarNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/ShlNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/ShrNode.java2
-rw-r--r--chapter25/src/main/java/com/seaofnodes/simple/node/XorNode.java2
9 files changed, 10 insertions, 10 deletions
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
index ca2cc955..64892f3f 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
@@ -49,7 +49,7 @@ public class CodeGen {
// -Dsimple.assert.expensive=0 disables these checks
// -Dsimple.assert.expensive=1 checks every step
// -Dsimple.assert.expensive=N checks once every 1<<N steps
- private static final int EXPENSIVE_ASSERT_LOG = Integer.getInteger("simple.assert.expensive",8);
+ private static final int EXPENSIVE_ASSERT_LOG = Integer.getInteger("simple.assert.expensive",1);
public static boolean expensiveAssert() { return EXPENSIVE_ASSERT_LOG > 0; }
public static boolean expensiveAssert( int trip ) {
if( EXPENSIVE_ASSERT_LOG <= 0 ) return false;
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/AddNode.java
index 46607c23..a29ba73b 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/AddNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/AddNode.java
@@ -37,7 +37,7 @@ public class AddNode extends ArithNode {
// 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.isa(compute()) )
return lhs;
// Add of same to a multiply by 2
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/DivNode.java
index dcc9a27a..f173f0ef 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/DivNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/DivNode.java
@@ -22,12 +22,12 @@ public class DivNode extends ArithNode {
@Override
public Node idealize() {
// Div of 1.
- if( in(2)._type == TypeInteger.TRUE )
+ if( in(2)._type == TypeInteger.TRUE && in(1)._type.isa(compute()) )
return in(1);
// Div of constant
if( _mode==2 ) {
- if( in(2)._type == TypeFloat.constant(1.) )
+ if( in(2)._type == TypeFloat.constant(1.) && in(1)._type.isa(compute()) )
return in(1);
if( in(2)._type instanceof TypeFloat f && f.isConstant() )
return new MulNode(in(1),ConstantNode.make(TypeFloat.constant(1.0/f.value())).peephole(),_mode);
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/MinusNode.java
index 2261adab..34e5667e 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/MinusNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/MinusNode.java
@@ -65,7 +65,7 @@ public class MinusNode extends Node implements ModeNode {
@Override
public Node idealize() {
// -(-x) is x
- if( in(1) instanceof MinusNode minus )
+ if( in(1) instanceof MinusNode minus && minus.in(1)._type.isa(compute()) )
return minus.in(1);
// Can we decide int vs flt?
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/MulNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/MulNode.java
index e773ed57..bb99cad5 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/MulNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/MulNode.java
@@ -35,7 +35,7 @@ public class MulNode extends ArithNode {
// 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.isa(compute()) ? lhs : super.idealize();
if( c==0 ) return CodeGen.CODE.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/chapter25/src/main/java/com/seaofnodes/simple/node/SarNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/SarNode.java
index e3f99ed4..de21fead 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/SarNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/SarNode.java
@@ -28,7 +28,7 @@ public class SarNode extends ArithNode {
Type t2 = rhs._type;
// Sar of 0.
- if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && forceInt(lhs) )
+ if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && forceInt(lhs) && lhs._type instanceof TypeInteger )
return lhs;
// TODO: x >> 3 >> (y ? 1 : 2) ==> x >> (y ? 4 : 5)
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/ShlNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/ShlNode.java
index 24d9bdb4..8f7b7b7e 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/ShlNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/ShlNode.java
@@ -33,7 +33,7 @@ public class ShlNode extends ArithNode {
if( rhs._type instanceof TypeInteger shl && shl.isConstant() ) {
// Shl of 0.
- if( (shl.value()&63)==0 && forceInt(lhs) )
+ if( (shl.value()&63)==0 && forceInt(lhs) && lhs._type instanceof TypeInteger )
return lhs;
// (x + c) << i => (x << i) + (c << i)
if( lhs instanceof AddNode add && addDep(add).in(2)._type instanceof TypeInteger c && c.isConstant() ) {
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/ShrNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/ShrNode.java
index 1bf7d118..2b268b42 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/ShrNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/ShrNode.java
@@ -23,7 +23,7 @@ public class ShrNode extends ArithNode {
Type t2 = rhs._type;
// Shr of 0.
- if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && forceInt(lhs) )
+ if( t2.isConstant() && t2 instanceof TypeInteger i && (i.value()&63)==0 && forceInt(lhs) && lhs._type instanceof TypeInteger )
return lhs;
// TODO: x >>> 3 >>> (y ? 1 : 2) ==> x >>> (y ? 4 : 5)
diff --git a/chapter25/src/main/java/com/seaofnodes/simple/node/XorNode.java b/chapter25/src/main/java/com/seaofnodes/simple/node/XorNode.java
index 27ebc3dc..a979bad8 100644
--- a/chapter25/src/main/java/com/seaofnodes/simple/node/XorNode.java
+++ b/chapter25/src/main/java/com/seaofnodes/simple/node/XorNode.java
@@ -26,7 +26,7 @@ public class XorNode extends ArithNode {
// 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 && forceInt(lhs) )
+ if( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==0 && forceInt(lhs) && lhs._type instanceof TypeInteger )
return lhs;
// Move constants to RHS: con*arg becomes arg*con