Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly treat FuelVMInstructions in the memcpyopt #6650

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 21 additions & 3 deletions sway-ir/src/optimize/memcpyopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use sway_types::{FxIndexMap, FxIndexSet};

use crate::{
get_gep_symbol, get_referred_symbol, get_referred_symbols, get_stored_symbols, memory_utils,
AnalysisResults, Block, Context, EscapedSymbols, Function, InstOp, Instruction,
InstructionInserter, IrError, LocalVar, Pass, PassMutability, ReferredSymbols, ScopedPass,
Symbol, Type, Value, ValueDatum, ESCAPED_SYMBOLS_NAME,
AnalysisResults, Block, Context, EscapedSymbols, FuelVmInstruction, Function, InstOp,
Instruction, InstructionInserter, IrError, LocalVar, Pass, PassMutability, ReferredSymbols,
ScopedPass, Symbol, Type, Value, ValueDatum, ESCAPED_SYMBOLS_NAME,
};

pub const MEMCPYOPT_NAME: &str = "memcpyopt";
Expand Down Expand Up @@ -649,6 +649,24 @@ fn local_copy_prop(
&mut dest_to_copies,
);
}
Instruction {
op:
InstOp::FuelVm(
FuelVmInstruction::WideBinaryOp { result, .. }
| FuelVmInstruction::WideUnaryOp { result, .. }
| FuelVmInstruction::WideModularOp { result, .. },
ironcev marked this conversation as resolved.
Show resolved Hide resolved
),
..
} => {
kill_defined_symbol(
context,
*result,
memory_utils::pointee_size(context, *result),
&mut available_copies,
&mut src_to_copies,
&mut dest_to_copies,
);
}
_ => (),
}
}
Expand Down
20 changes: 20 additions & 0 deletions sway-ir/tests/memcpyopt/no_memcpyopt_wide_binary_operator.ir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
script {
entry fn main() -> u256 {
local u256 x
local u256 y
local u256 z

entry():
v0 = get_local ptr u256, x
v1 = get_local ptr u256, y
v2 = get_local ptr u256, z

mem_copy_val v2, v0
wide add v0, v1 to v2
v3 = load v2

ret u256 v3
}
}

// check: v3 = load v2
20 changes: 20 additions & 0 deletions sway-ir/tests/memcpyopt/no_memcpyopt_wide_unary_operator.ir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
script {
entry fn main() -> u256 {
local u256 x
local u256 y
local u256 z

entry():
v0 = get_local ptr u256, x
v1 = get_local ptr u256, y
v2 = get_local ptr u256, z

mem_copy_val v2, v0
wide not v1 to v2
v3 = load v2

ret u256 v3
}
}

// check: v3 = load v2
Loading