diff options
Diffstat (limited to 'chapter27/src/main/java/com/seaofnodes')
| -rw-r--r-- | chapter27/src/main/java/com/seaofnodes/simple/node/LoadNode.java | 8 | ||||
| -rw-r--r-- | chapter27/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/chapter27/src/main/java/com/seaofnodes/simple/node/LoadNode.java b/chapter27/src/main/java/com/seaofnodes/simple/node/LoadNode.java index 736d91a2..aed0e703 100644 --- a/chapter27/src/main/java/com/seaofnodes/simple/node/LoadNode.java +++ b/chapter27/src/main/java/com/seaofnodes/simple/node/LoadNode.java @@ -253,7 +253,7 @@ public class LoadNode extends MemOpNode { } private Node folded(Node win) { - return win instanceof StoreNode st ? extend(castRO(st.val())) : zero((NewNode)win); + return win instanceof StoreNode st ? extend(castRO(st.val()),st._declaredType) : zero((NewNode)win); } // Materialize only after the profitability search succeeds. The value Phi @@ -311,8 +311,10 @@ public class LoadNode extends MemOpNode { // When a load bypasses a store, the store might truncate bits - and the // load will need to zero/sign-extend. - private Node extend(Node val) { - if( !(_declaredType instanceof TypeInteger ti) ) return val; + // Use the matching Store's width: while a class is open, this Load may + // already know its alias but not yet have recorded its storage type. + private Node extend(Node val, Type storage) { + if( !(storage instanceof TypeInteger ti) ) return val; if( ti._min==0 ) // Unsigned return new AndNode(null,val,con(ti._max)); // Signed extension diff --git a/chapter27/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java b/chapter27/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java index c854dd9d..a92b43d5 100644 --- a/chapter27/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java +++ b/chapter27/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/x86_64_v2.java @@ -552,7 +552,7 @@ public class x86_64_v2 extends Machine { private int imm( Node xval ) { assert val == null && imm == 0; - if( xval instanceof ConstantNode con && con._con instanceof TypeInteger ti) { + if( xval instanceof ConstantNode con && con._con instanceof TypeInteger ti && ti.isConstant() && imm32(ti.value()) ) { val = null; imm = (int) ti.value(); assert imm == ti.value(); // In 32-bit range |
