Skip to content

Commit be4dd5c

Browse files
committed
Simplify complex_{imag,real}_exprt
When the operand is a complex_exprt we can just extract the respective member.
1 parent 4b183ec commit be4dd5c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/util/simplify_expr.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,32 @@ bool simplify_exprt::simplify_byte_update(byte_update_exprt &expr)
23032303
return true;
23042304
}
23052305

2306+
bool simplify_exprt::simplify_complex(exprt &expr)
2307+
{
2308+
if(expr.id() == ID_complex_real)
2309+
{
2310+
complex_real_exprt &complex_real_expr = to_complex_real_expr(expr);
2311+
2312+
if(complex_real_expr.op().id() == ID_complex)
2313+
{
2314+
expr = to_complex_expr(complex_real_expr.op()).real();
2315+
return false;
2316+
}
2317+
}
2318+
else if(expr.id() == ID_complex_imag)
2319+
{
2320+
complex_imag_exprt &complex_imag_expr = to_complex_imag_expr(expr);
2321+
2322+
if(complex_imag_expr.op().id() == ID_complex)
2323+
{
2324+
expr = to_complex_expr(complex_imag_expr.op()).imag();
2325+
return false;
2326+
}
2327+
}
2328+
2329+
return true;
2330+
}
2331+
23062332
bool simplify_exprt::simplify_node_preorder(exprt &expr)
23072333
{
23082334
bool result=true;
@@ -2445,6 +2471,8 @@ bool simplify_exprt::simplify_node(exprt &expr)
24452471
result = simplify_popcount(to_popcount_expr(expr)) && result;
24462472
else if(expr.id() == ID_function_application)
24472473
result = simplify_function_application(expr) && result;
2474+
else if(expr.id() == ID_complex_real || expr.id() == ID_complex_imag)
2475+
result = simplify_complex(expr) && result;
24482476

24492477
#ifdef DEBUGX
24502478
if(!result

src/util/simplify_expr_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class simplify_exprt
113113
bool simplify_abs(exprt &expr);
114114
bool simplify_sign(exprt &expr);
115115
bool simplify_popcount(popcount_exprt &expr);
116+
bool simplify_complex(exprt &expr);
116117

117118
/// Attempt to simplify mathematical function applications if we have
118119
/// enough information to do so. Currently focused on constant comparisons.

0 commit comments

Comments
 (0)