From 1ccf3a3239064c794d5ceb97f93de7f538e0b2e2 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 25 Sep 2026 12:31:31 -0300 Subject: [PATCH 1/3] chore(test_copy_propagation): assert copy source replaces return operands --- crates/newyork/src/simplify.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/newyork/src/simplify.rs b/crates/newyork/src/simplify.rs index 10e4ab35e..cf59df18c 100644 --- a/crates/newyork/src/simplify.rs +++ b/crates/newyork/src/simplify.rs @@ -4128,12 +4128,14 @@ mod tests { let block = &mut Block { statements }; simplifier.simplify_block(block); - if let Statement::Return { offset, .. } = &block.statements[block.statements.len() - 1] { - assert!( - offset.id.0 == 1 - || matches!(block.statements.last(), Some(Statement::Return { .. })) - ); - } + let Some(Statement::Return { offset, length }) = block.statements.last() else { + panic!("the block must still end in a return"); + }; + assert_eq!( + (offset.id, length.id), + (ValueId(1), ValueId(1)), + "uses of the copy `v2 := v1` must be rewritten to its source" + ); } #[test] From fd0819f72214829ab32add2d1d7e76640ecf729f Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 25 Sep 2026 12:31:32 -0300 Subject: [PATCH 2/3] chore(test_constant_propagation_through_add): assert load forwarding through folded add --- crates/newyork/src/mem_opt.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/newyork/src/mem_opt.rs b/crates/newyork/src/mem_opt.rs index bb744ef21..91bd9a224 100644 --- a/crates/newyork/src/mem_opt.rs +++ b/crates/newyork/src/mem_opt.rs @@ -1718,6 +1718,7 @@ mod tests { let offset_id = ValueId(2); let value_id = ValueId(3); let result_id = ValueId(4); + let addend_id = ValueId(5); let statements = vec![ Statement::Let { @@ -1727,6 +1728,13 @@ mod tests { value_type: Type::Int(BitWidth::I256), }, }, + Statement::Let { + bindings: vec![addend_id], + value: Expression::Literal { + value: BigUint::from(32u32), + value_type: Type::Int(BitWidth::I256), + }, + }, Statement::Let { bindings: vec![offset_id], value: Expression::Binary { @@ -1736,7 +1744,7 @@ mod tests { value_type: Type::Int(BitWidth::I256), }, rhs: Value { - id: ValueId(100), + id: addend_id, value_type: Type::Int(BitWidth::I256), }, }, @@ -1779,7 +1787,17 @@ mod tests { data: BTreeMap::new(), }; - let _statistics = optimizer.optimize_object(&mut object); + let statistics = optimizer.optimize_object(&mut object); + + assert_eq!(statistics.loads_eliminated, 1); + assert!( + matches!( + object.code.statements.last(), + Some(Statement::Let { bindings, value: Expression::Var(forwarded) }) + if bindings == &vec![result_id] && *forwarded == value_id + ), + "the load at the folded offset must be replaced by the stored value" + ); } #[test] From c7bb56abf98bba91f851b852a54187e54644068f Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 25 Sep 2026 12:31:32 -0300 Subject: [PATCH 3/3] chore(condition_observes_overlap_store_flags_unbounded): cover offset and region observation paths --- crates/newyork/src/heap_opt.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/newyork/src/heap_opt.rs b/crates/newyork/src/heap_opt.rs index af3912d58..b6fb9470c 100644 --- a/crates/newyork/src/heap_opt.rs +++ b/crates/newyork/src/heap_opt.rs @@ -1912,9 +1912,22 @@ mod tests { #[test] fn condition_observes_overlap_store_flags_unbounded() { use crate::ir::ValueId; + let mut statements = establish_fmp_statements(); statements.extend(overlap_store_statements(2)); statements.push(literal_binding(4, 0x40)); + statements.push(loop_with_condition(Expression::MLoad { + offset: Value::int(ValueId(4)), + region: MemoryRegion::Unknown, + })); + let results = object_with_code(statements, vec![]).analyze_heap(TEST_HEAP_SIZE); + assert!( + results.fmp_could_be_unbounded(), + "a loop condition loading from static offset 0x40 after an overlap store observes the corruption" + ); + + let mut statements = establish_fmp_statements(); + statements.extend(overlap_store_statements(2)); statements.push(loop_with_condition(Expression::MLoad { offset: Value::int(ValueId(4)), region: MemoryRegion::FreePointerSlot, @@ -1922,7 +1935,7 @@ mod tests { let results = object_with_code(statements, vec![]).analyze_heap(TEST_HEAP_SIZE); assert!( results.fmp_could_be_unbounded(), - "a loop condition reading mload(0x40) after an overlap store observes the corruption" + "a loop condition loading from the free pointer slot after an overlap store observes the corruption" ); }