Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
808d353
Add a new memcpy propagation pass
vaivaswatha Oct 6, 2025
935c616
enable pass, mistakenly disabled in previous commit
vaivaswatha Oct 6, 2025
db42ae8
Merge branch 'master' into vaivaswatha/memcpy_prop_new
vaivaswatha Oct 6, 2025
96127a8
clippy and fmt updates
vaivaswatha Oct 6, 2025
449e2ac
bugfix: check equality of symbol types involved in memcpy
vaivaswatha Oct 7, 2025
537bd79
skip sources that have an initializer
vaivaswatha Oct 7, 2025
df971f6
do not optimize memcpys that write partially to a symbol
vaivaswatha Oct 8, 2025
9b25911
post-opt: eliminate memcpys with same source and destination
vaivaswatha Oct 8, 2025
c1ec6b9
fix clippy
vaivaswatha Oct 8, 2025
201945d
Merge branch 'master' into vaivaswatha/memcpy_prop_new
vaivaswatha Oct 8, 2025
1cbfc91
update tests
vaivaswatha Oct 8, 2025
ebebb22
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 14, 2025
df03d6f
Change the correctness criteria for the optimization
vaivaswatha Oct 14, 2025
b9c4df5
fix clippy warning
vaivaswatha Oct 14, 2025
2df3b07
update tests
vaivaswatha Oct 14, 2025
c09ab61
further update tests
vaivaswatha Oct 14, 2025
6e6444a
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 18, 2025
abc5e95
update new test
vaivaswatha Oct 19, 2025
d0ca28b
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 21, 2025
6979283
Merge branch 'master' into vaivaswatha/memcpy_prop_new
vaivaswatha Oct 21, 2025
c2e75cd
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 21, 2025
d1553e6
Merge branch 'vaivaswatha/memcpy_prop_new' of github.com:FuelLabs/swa…
vaivaswatha Oct 21, 2025
002320e
Merge branch 'master' into vaivaswatha/memcpy_prop_new
vaivaswatha Oct 23, 2025
e4333be
Merge branch 'master' into vaivaswatha/memcpy_prop_new
vaivaswatha Oct 25, 2025
f69ab63
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 27, 2025
dd7a2bf
Merge branch 'vaivaswatha/memcpy_prop_new' of github.com:FuelLabs/swa…
vaivaswatha Oct 27, 2025
39cc598
check for cycles in memcpy propagation as suggested by AI
vaivaswatha Oct 27, 2025
5b72fea
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/me…
vaivaswatha Oct 31, 2025
816fd00
cargo fmt
vaivaswatha Oct 31, 2025
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
5 changes: 3 additions & 2 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ use sway_ir::{
create_o1_pass_group, register_known_passes, Context, Kind, Module, PassGroup, PassManager,
PrintPassesOpts, VerifyPassesOpts, ARG_DEMOTION_NAME, ARG_POINTEE_MUTABILITY_TAGGER_NAME,
CONST_DEMOTION_NAME, DCE_NAME, FN_DEDUP_DEBUG_PROFILE_NAME, FN_INLINE_NAME, GLOBALS_DCE_NAME,
MEM2REG_NAME, MEMCPYOPT_NAME, MISC_DEMOTION_NAME, RET_DEMOTION_NAME, SIMPLIFY_CFG_NAME,
SROA_NAME,
MEM2REG_NAME, MEMCPYOPT_NAME, MEMCPYPROP_REVERSE_NAME, MISC_DEMOTION_NAME, RET_DEMOTION_NAME,
SIMPLIFY_CFG_NAME, SROA_NAME,
};
use sway_types::span::Source;
use sway_types::{SourceEngine, SourceLocation, Span};
Expand Down Expand Up @@ -1322,6 +1322,7 @@ pub(crate) fn compile_ast_to_ir_to_asm(

match build_config.optimization_level {
OptLevel::Opt1 => {
pass_group.append_pass(MEMCPYPROP_REVERSE_NAME);
pass_group.append_pass(SROA_NAME);
pass_group.append_pass(MEM2REG_NAME);
pass_group.append_pass(DCE_NAME);
Expand Down
30 changes: 29 additions & 1 deletion sway-ir/src/analysis/dominator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
block::Block, AnalysisResult, AnalysisResultT, AnalysisResults, BranchToWithArgs, Context,
Function, IrError, Pass, PassMutability, ScopedPass,
Function, IrError, Pass, PassMutability, ScopedPass, Value,
};
use indexmap::IndexSet;
/// Dominator tree and related algorithms.
Expand Down Expand Up @@ -222,6 +222,34 @@ impl DomTree {
pub fn child(&self, node: Block, i: usize) -> Option<Block> {
self.0[&node].children.get(i).cloned()
}

/// Does `dominator` `dominate` `dominatee`?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Does `dominator` `dominate` `dominatee`?
/// Does `dominator` dominate `dominatee`?

pub fn dominates_instr(&self, context: &Context, dominator: Value, dominatee: Value) -> bool {
let dominator_inst = dominator.get_instruction(context).unwrap();
let dominatee_inst = dominatee.get_instruction(context).unwrap();

if dominator == dominatee {
return true;
}
let dominator_block = dominator_inst.parent;
let dominatee_block = dominatee_inst.parent;
if dominator_block == dominatee_block {
// Same block, but different instructions.
// Check the order of instructions in the block.
let mut found_dominator = false;
for instr in dominator_block.instruction_iter(context) {
if instr == dominator {
found_dominator = true;
}
if instr == dominatee {
return found_dominator;
}
}
false
} else {
self.dominates(dominator_block, dominatee_block)
}
}
}

pub const DOM_FRONTS_NAME: &str = "dominance-frontiers";
Expand Down
5 changes: 5 additions & 0 deletions sway-ir/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ impl BlockArgument {
}
None
}

/// Get that Value that this argument represents.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get that Value that this argument represents.
/// Get the [Value] that this argument represents.

pub fn as_value(&self, context: &Context) -> Value {
self.block.get_arg(context, self.idx).unwrap()
}
}

/// Each block may be explicitly named. A [`Label`] is a simple `String` synonym.
Expand Down
7 changes: 7 additions & 0 deletions sway-ir/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ impl Function {
Ok(())
}

/// Remove instructions from function that satisfy a given predicate.
pub fn remove_instructions<T: Fn(Value) -> bool>(&self, context: &mut Context, pred: T) {
for block in context.functions[self.0].blocks.clone() {
block.remove_instructions(context, &pred);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Predicate Reference Mismatch in Instruction Removal

The Function::remove_instructions method passes &pred to Block::remove_instructions. This causes a type mismatch because Block::remove_instructions expects a predicate implementing Fn(Value) -> bool, but &T (a reference to the original predicate) does not satisfy this trait bound.

Fix in Cursor Fix in Web


/// Get a new unique block label.
///
/// If `hint` is `None` then the label will be in the form `"blockN"` where N is an
Expand Down
Loading
Loading