C++: SimpleRangeAnalysis: widen recursive *, +, -

The number of candidate bounds during the main `SimpleRangeAnalysis`
recursion was in principle always exponential in the size of the
program, but in practice it did not get out of hand when only `+` and
`-` operations were supported. Now that `*` is also supported, the range
analysis started timing out on the SinaMostafanejad/OpenRDM project. The
problematic expressions in that project are of the form

    a*x*x*x + b*x*x + c*x + d

where most of the variables involved are recursive definitions and are
therefore likely to have a large number of candidate bounds.

The fix here is to identify those few binary operations that are most
likely to cause an explosion in the number of bounds and apply widening
to them. Previously, widening was only applied at definitions.
This commit is contained in:
Jonas Jensen
2020-10-06 13:28:07 +02:00
parent bbeea452e1
commit 9b12ceae8d
3 changed files with 55 additions and 4 deletions

View File

@@ -644,6 +644,6 @@ void widen_recursive_expr() {
int s;
for (s = 0; s < 10; s++) {
int result = s + s; // 0 .. 9 [BUG: upper bound is 15 due to widening]
out(result); // 0 .. 18 [BUG: upper bound is 30 due to widening]
out(result); // 0 .. 18 [BUG: upper bound is 127 due to double widening]
}
}

View File

@@ -587,7 +587,7 @@
| test.c:645:23:645:23 | s | 15 |
| test.c:646:18:646:18 | s | 15 |
| test.c:646:22:646:22 | s | 15 |
| test.c:647:9:647:14 | result | 30 |
| test.c:647:9:647:14 | result | 127 |
| test.cpp:10:7:10:7 | b | 2147483647 |
| test.cpp:11:5:11:5 | x | 2147483647 |
| test.cpp:13:10:13:10 | x | 2147483647 |