Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sway-core/src/asm_generation/fuel/optimizations/misc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::super::abstract_instruction_set::AbstractInstructionSet;

use crate::asm_lang::{JumpType, Op, OrganizationalOp, VirtualOp, VirtualRegister};
use crate::asm_lang::{
virtual_register::ConstantRegister, JumpType, Op, OrganizationalOp, VirtualOp, VirtualRegister,
};

use std::collections::HashSet;

Expand Down Expand Up @@ -101,6 +103,10 @@ impl AbstractInstructionSet {
let remove = match &op.opcode {
Either::Left(VirtualOp::NOOP) => true,
Either::Left(VirtualOp::MOVE(a, b)) => a == b,
Either::Left(VirtualOp::MCP(_, _, len)) => {
matches!(len, VirtualRegister::Constant(ConstantRegister::Zero))
}
Either::Left(VirtualOp::MCPI(_, _, imm)) => imm.value() == 0,
_ => false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ output:
Building test/src/e2e_vm_tests/test_programs/should_pass/stdlib/vec_encoding_decoding
Compiling library std (test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-vec)
Compiling script vec_encoding_decoding (test/src/e2e_vm_tests/test_programs/should_pass/stdlib/vec_encoding_decoding)
Finished release [optimized + fuel] target(s) [10.24 KB] in ???
Finished release [optimized + fuel] target(s) [10.232 KB] in ???
Running 6 tests, filtered 0 tests

tested -- vec_encoding_decoding
Expand All @@ -24,10 +24,10 @@ tested -- vec_encoding_decoding
test nested_vec_non_trivial ... ok (???, 47654 gas)
decoded log values:
[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8]], log rb: 16171443785104013487
test vec_encode_zst ... ok (???, 3465 gas)
test vec_encode_zst ... ok (???, 3448 gas)
decoded log values:
[(), (), (), (), (), (), (), (), (), ()], log rb: 7172587179247292377
test nested_vec_zst ... ok (???, 23061 gas)
test nested_vec_zst ... ok (???, 22968 gas)
decoded log values:
[[], [()], [(), ()], [(), (), ()], [(), (), (), ()], [(), (), (), (), ()], [(), (), (), (), (), ()], [(), (), (), (), (), (), ()], [(), (), (), (), (), (), (), ()], [(), (), (), (), (), (), (), (), ()]], log rb: 15095959372321865352

Expand Down
26 changes: 26 additions & 0 deletions test/src/ir_generation/tests/mcp_zero_len.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// target-fuelvm
script;

fn main() -> u64 {
let src: u64 = 42;
let mut dst: u64 = 0;
asm(dst_ptr: __addr_of(dst), src_ptr: __addr_of(src), zero: 0u64) {
mcp dst_ptr src_ptr zero;
Comment thread
Dnreikronos marked this conversation as resolved.
}
asm(dst_ptr: __addr_of(dst), src_ptr: __addr_of(src)) {
mcpi dst_ptr src_ptr i0;
}
dst
}

// ::check-ir::

// check: asm(dst_ptr: $VAL, src_ptr: $VAL, zero: $VAL) -> ()
// check: mcp
// check: asm(dst_ptr: $VAL, src_ptr: $VAL) -> ()
// check: mcpi

// ::check-asm::
//
// not: mcp
// not: mcpi
Loading