From 58b3c0c2d56d09aaf5fba2f22ec44330f4612210 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 8 Jan 2024 18:45:28 +0000 Subject: [PATCH] feat: simplify chains of casts to be all in terms of the original `ValueId` --- compiler/noirc_evaluator/src/ssa/ir/instruction.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 9691017f04b..7d6507b7131 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -581,6 +581,14 @@ impl Instruction { /// that value is returned. Otherwise None is returned. fn simplify_cast(value: ValueId, dst_typ: &Type, dfg: &mut DataFlowGraph) -> SimplifyResult { use SimplifyResult::*; + let value = dfg.resolve(value); + + if let Value::Instruction { instruction, .. } = &dfg[value] { + if let Instruction::Cast(original_value, _) = &dfg[*instruction] { + return SimplifiedToInstruction(Instruction::Cast(*original_value, dst_typ.clone())); + } + } + if let Some(constant) = dfg.get_numeric_constant(value) { let src_typ = dfg.type_of_value(value); match (src_typ, dst_typ) {