Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 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,9 @@
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 +104,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
20 changes: 20 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,20 @@
// target-fuelvm
script;

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

// ::check-ir::

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

// ::check-asm::
//
// not: mcp