From 849062a54f59d79f4f1b0e652915f5eaf6f983b8 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Fri, 5 Apr 2024 11:34:45 -0500 Subject: [PATCH] Add equality check to value merge --- .../noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs index 0a351148fa3..b7a76cf2b93 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs @@ -72,6 +72,11 @@ impl<'a> ValueMerger<'a> { "Expected values merged to be of the same type but found {then_type} and {else_type}" ); + // Don't merge two values if they're already equal. That can make them non-constant + if then_value == else_value { + return then_value; + } + let then_call_stack = self.dfg.get_value_call_stack(then_value); let else_call_stack = self.dfg.get_value_call_stack(else_value);