You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
long patatino() {
long x = 0;
for (int i = 0; i < 5; ++i) {
while (x < 10) {
if (x % 2 == 0) {
x += 2;
} else {
x += 1;
}
// Dead while loop
while ((x > 20) && (i % 3 == 0) && (x % 5 == 0)) {
x -= 5;
}
// Dead while loop
while ((x < -5) && (i % 2 == 0) && (x % 3 == 0)) {
x += 3;
}
}
}
return x;
}
If you remove the two 'dead while loops' then LLVM is able to optimize this down to a constant.
For comparison, GCC trunk seems to do better, but also doesn't optimize this fully
When examining the PN %x.3 = phi i64 [ %x.2, %while.body ], [ %sub, %while.body6 ] in getPredicateAt, the constant range returned by LVI for the first incoming value %x.2 is [INT_MIN, 12) which is always less than [20,21). However, for %sub the constant range is [16, UINT_MAX) which is not less than [20,21). Doesn't this second range look suboptimal?
Uh oh!
There was an error while loading. Please reload this page.
Godbolt link:
https://godbolt.org/z/Kaq3sbsr9
Inline code:
If you remove the two 'dead while loops' then LLVM is able to optimize this down to a constant.
For comparison, GCC trunk seems to do better, but also doesn't optimize this fully
cc: @fhahn @nikic
The text was updated successfully, but these errors were encountered: