Skip to content

Commit

Permalink
Special case inc_rc instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Nov 28, 2023
1 parent fcc90db commit ead0806
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 1 addition & 6 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,10 @@ impl Instruction {
| ArrayGet { .. }
| ArraySet { .. } => false,

// IncrementRc is not counted as having side effects since we still
// want it to be removed by the DIE pass if its parameter is unused.
// At the time of writing has_side_effects is only used by DIE but
// we should keep this in mind (or rename this method?) if it is ever used elsewhere.
IncrementRc { .. } => false,

Constrain(..)
| Store { .. }
| EnableSideEffects { .. }
| IncrementRc { .. }
| RangeCheck { .. } => true,

// Some `Intrinsic`s have side effects so we must check what kind of `Call` this is.
Expand Down
9 changes: 7 additions & 2 deletions compiler/noirc_evaluator/src/ssa/opt/die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::ssa::{
basic_block::{BasicBlock, BasicBlockId},
dfg::DataFlowGraph,
function::Function,
instruction::InstructionId,
instruction::{InstructionId, Instruction},
post_order::PostOrder,
value::{Value, ValueId},
},
Expand Down Expand Up @@ -90,7 +90,12 @@ impl Context {
fn is_unused(&self, instruction_id: InstructionId, function: &Function) -> bool {
let instruction = &function.dfg[instruction_id];

if instruction.has_side_effects(&function.dfg) {
// IncrementRc is a special case, we want to remove it if possible
// but it has no results so it'd always be removed if left to the normal check.
// We must check whether its parameter is unused instead.
if let Instruction::IncrementRc { value } = instruction {
!self.used_values.contains(value)
} else if instruction.has_side_effects(&function.dfg) {
// If the instruction has side effects we should never remove it.
false
} else {
Expand Down

0 comments on commit ead0806

Please sign in to comment.