Skip to content

Commit

Permalink
Merge 580928b into 2303615
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Oct 2, 2024
2 parents 2303615 + 580928b commit 6b72841
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ControlFlowGraph {

/// Clears out a given block's successors. This also removes the given block from
/// being a predecessor of any of its previous successors.
fn invalidate_block_successors(&mut self, basic_block_id: BasicBlockId) {
pub(crate) fn invalidate_block_successors(&mut self, basic_block_id: BasicBlockId) {
let node = self
.data
.get_mut(&basic_block_id)
Expand Down
14 changes: 11 additions & 3 deletions compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl Function {
check_for_constant_jmpif(self, block, &mut cfg);

let mut predecessors = cfg.predecessors(block);

if predecessors.len() == 1 {
let predecessor =
predecessors.next().expect("Already checked length of predecessors");
Expand Down Expand Up @@ -99,14 +98,23 @@ fn check_for_constant_jmpif(
}) = function.dfg[block].terminator()
{
if let Some(constant) = function.dfg.get_numeric_constant(*condition) {
let destination =
if constant.is_zero() { *else_destination } else { *then_destination };
let (destination, unchosen_destination) = if constant.is_zero() {
(*else_destination, *then_destination)
} else {
(*then_destination, *else_destination)
};

let arguments = Vec::new();
let call_stack = call_stack.clone();
let jmp = TerminatorInstruction::Jmp { destination, arguments, call_stack };
function.dfg[block].set_terminator(jmp);
cfg.recompute_block(function, block);

// If `block` was the only predecessor to `unchosen_destination` then it's no long reachable through the CFG,
// we can then invalidate it successors as it's an invalid predecessor.
if cfg.predecessors(unchosen_destination).len() == 0 {
cfg.invalidate_block_successors(unchosen_destination);
}
}
}
}
Expand Down

0 comments on commit 6b72841

Please sign in to comment.