From 4c2aaf08ea7e6a085fb3b3cc889dbf293f8d3152 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:53:25 +0100 Subject: [PATCH] feat: Remove unnecessary truncation of boolean multiplication (#3122) Co-authored-by: Tom French --- 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 f7e2d7df935..d1031c98558 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