Skip to content

Commit 8fee45e

Browse files
committed
Simplify extractbits(concatenation(...))
1 parent 6076f56 commit 8fee45e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include "ieee_float.h"
2121
#include "invariant.h"
2222
#include "namespace.h"
23+
#include "pointer_offset_size.h"
2324
#include "rational.h"
2425
#include "rational_tools.h"
2526
#include "std_expr.h"
@@ -1146,6 +1147,32 @@ bool simplify_exprt::simplify_extractbits(extractbits_exprt &expr)
11461147

11471148
return false;
11481149
}
1150+
else if(expr.src().id() == ID_concatenation)
1151+
{
1152+
// the most-significant bit comes first in an concatenation_exprt, hence we
1153+
// count down
1154+
mp_integer offset = width;
1155+
1156+
forall_operands(it, expr.src())
1157+
{
1158+
mp_integer op_width = pointer_offset_bits(it->type(), ns);
1159+
1160+
if(op_width <= 0)
1161+
return true;
1162+
1163+
if(start + 1 == offset && end + op_width == offset)
1164+
{
1165+
exprt tmp = *it;
1166+
if(tmp.type() != expr.type())
1167+
return true;
1168+
1169+
expr.swap(tmp);
1170+
return false;
1171+
}
1172+
1173+
offset -= op_width;
1174+
}
1175+
}
11491176

11501177
return true;
11511178
}

0 commit comments

Comments
 (0)