diff --git a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs index c81a557178b..62204ed93bd 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs @@ -745,15 +745,17 @@ impl ResultCache { has_side_effects: bool, ) -> Option { self.result.as_ref().and_then(|(origin_block, results)| { + if has_side_effects { + return None + } + if dom.dominates(*origin_block, block) { Some(CacheResult::Cached(results)) - } else if !has_side_effects { + } else { // Insert a copy of this instruction in the common dominator let dominator = dom.common_dominator(*origin_block, block); Some(CacheResult::NeedToHoistToCommonBlock(dominator)) - } else { - None - } + } }) } }