Skip to content

Commit ebd69f5

Browse files
committed
byte_extract lowering of arrays: optimise for constant index
No need to construct index_exprt when we can just pick the operand out of a vector.
1 parent 5884421 commit ebd69f5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/solvers/lowering/byte_operators.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,21 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
499499
little_endian?(width_bytes-i-1):i;
500500

501501
plus_exprt offset_i(from_integer(offset_int, offset.type()), offset);
502-
index_exprt index_expr(root, offset_i);
503-
op.push_back(index_expr);
502+
simplify(offset_i, ns);
503+
504+
mp_integer index = 0;
505+
if(
506+
!offset_i.is_constant() ||
507+
(root.id() != ID_array && root.id() != ID_vector) ||
508+
to_integer(to_constant_expr(offset_i), index) ||
509+
index >= root.operands().size() || index < 0)
510+
{
511+
op.push_back(index_exprt(root, offset_i));
512+
}
513+
else
514+
{
515+
op.push_back(root.operands()[numeric_cast_v<std::size_t>(index)]);
516+
}
504517
}
505518

506519
if(width_bytes==1)

0 commit comments

Comments
 (0)