From 14d149435cf5cbee27434d2e9ff6cf434e4a0975 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 12 Oct 2023 01:28:16 +0100 Subject: [PATCH] feat: remove unnecessary truncation of boolean multiplication --- compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs index f7e2d7df93..d1031c9855 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs @@ -774,7 +774,15 @@ fn operator_result_max_bit_size_to_truncate( match op { Add => Some(std::cmp::max(lhs_bit_size, rhs_bit_size) + 1), Subtract => Some(std::cmp::max(lhs_bit_size, rhs_bit_size) + 1), - Multiply => Some(lhs_bit_size + rhs_bit_size), + Multiply => { + if lhs_bit_size == 1 || rhs_bit_size == 1 { + // Truncation is unnecessary as multiplication by a boolean value cannot cause an overflow. + None + } else { + Some(lhs_bit_size + rhs_bit_size) + } + } + ShiftLeft => { if let Some(rhs_constant) = dfg.get_numeric_constant(rhs) { // Happy case is that we know precisely by how many bits the the integer will