diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs index 83b8f2a57ff..1bbd407cf0f 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs @@ -116,11 +116,14 @@ pub(crate) struct GlobalsGraph { /// All of the instructions in the global value space. /// These are expected to all be Instruction::MakeArray instructions: DenseMap, + + #[serde(skip)] + constants: HashMap<(FieldElement, NumericType), ValueId>, } impl GlobalsGraph { pub(crate) fn from_dfg(dfg: DataFlowGraph) -> Self { - Self { values: dfg.values, instructions: dfg.instructions } + Self { values: dfg.values, instructions: dfg.instructions, constants: dfg.constants } } /// Iterate over every Value in this DFG in no particular order, including unused Values @@ -386,6 +389,9 @@ impl DataFlowGraph { if let Some(id) = self.constants.get(&(constant, typ)) { return *id; } + if let Some(id) = self.globals.constants.get(&(constant, typ)) { + return *id; + } let id = self.values.insert(Value::NumericConstant { constant, typ }); self.constants.insert((constant, typ), id); id