File tree Expand file tree Collapse file tree
compiler/noirc_evaluator/src/ssa/ir/dfg Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ pub(crate) fn simplify(
141141 try_optimize_array_set_from_previous_get ( dfg, * array_id, * index_id, * value)
142142 }
143143 Instruction :: Truncate { value, bit_size, max_bit_size } => {
144- if bit_size = = max_bit_size {
144+ if bit_size > = max_bit_size {
145145 return SimplifiedTo ( * value) ;
146146 }
147147 if let Some ( ( numeric_constant, typ) ) = dfg. get_numeric_constant_with_type ( * value) {
@@ -490,4 +490,25 @@ mod tests {
490490 assert_normalized_ssa_equals ( ssa, & expected) ;
491491 }
492492 }
493+
494+ #[ test]
495+ fn truncate_to_bit_size_bigger_than_value_max_bit_size ( ) {
496+ let src = "
497+ acir(inline) fn main f0 {
498+ b0(v0: u8):
499+ v1 = truncate v0 to 16 bits, max_bit_size: 8
500+ v2 = cast v1 as u16
501+ return v2
502+ }
503+ " ;
504+ let ssa = Ssa :: from_str_simplifying ( src) . unwrap ( ) ;
505+
506+ assert_ssa_snapshot ! ( ssa, @r"
507+ acir(inline) fn main f0 {
508+ b0(v0: u8):
509+ v1 = cast v0 as u16
510+ return v1
511+ }
512+ " ) ;
513+ }
493514}
You can’t perform that action at this time.
0 commit comments