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

fix(ssa): Resolve value IDs in terminator before comparing to array #6448

Merged
merged 2 commits into from
Nov 5, 2024
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
5 changes: 3 additions & 2 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ pub(crate) struct DataFlowGraph {
blocks: DenseMap<BasicBlock>,

/// Debugging information about which `ValueId`s have had their underlying `Value` substituted
/// for that of another. This information is purely used for printing the SSA, and has no
/// material effect on the SSA itself.
/// for that of another. In theory this information is purely used for printing the SSA,
/// and has no material effect on the SSA itself, however in practice the IDs can get out of
/// sync and may need this resolution before they can be compared.
#[serde(skip)]
replaced_value_ids: HashMap<ValueId, ValueId>,

Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/array_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ impl<'f> Context<'f> {
// If the array comes from a load we may potentially being mutating an array at a reference
// that is loaded from by other values.
let terminator = self.dfg[block_id].unwrap_terminator();

// If we are in a return block we are not concerned about the array potentially being mutated again.
let is_return_block =
matches!(terminator, TerminatorInstruction::Return { .. });
// We also want to check that the array is not part of the terminator arguments, as this means it is used again.
let mut array_in_terminator = false;
terminator.for_each_value(|value| {
if value == array {
// The terminator can contain original IDs, while the SSA has replaced the array value IDs; we need to resolve to compare.
if !array_in_terminator && self.dfg.resolve(value) == array {
array_in_terminator = true;
}
});
Expand Down
Loading