| 1 |
/* See backwards thru casts if the range fits the LHS type. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-O2 -fdump-tree-evrp" } */ |
| 4 |
|
| 5 |
extern void kill(int i); |
| 6 |
extern void keep(int i); |
| 7 |
|
| 8 |
void |
| 9 |
foo (int i) |
| 10 |
{ |
| 11 |
if (i >= 10) |
| 12 |
{ |
| 13 |
if (i <= 100) |
| 14 |
{ |
| 15 |
/* i has a range of [10, 100] */ |
| 16 |
char c = (char) i; |
| 17 |
if (c < 30) |
| 18 |
{ |
| 19 |
/* If we wind back thru the cast with the range of c being [10,29] |
| 20 |
* from the branch, and recognize that the range of i fits within |
| 21 |
* a cast to c, then there is no missing information in a cast |
| 22 |
* back to int. We can use the range calculated for 'c' with 'i' |
| 23 |
* as well and Ranger should be able to kill the call. */ |
| 24 |
if (i > 29) |
| 25 |
kill (i); |
| 26 |
} |
| 27 |
} |
| 28 |
/* i has a range of [10, MAX] */ |
| 29 |
char d = (char) i; |
| 30 |
if (d < 30) |
| 31 |
{ |
| 32 |
/* Here, a cast to a char and back is NOT equivalent, so we cannot use |
| 33 |
* the value of d to remove the call. */ |
| 34 |
if (i > 29) |
| 35 |
keep (i); |
| 36 |
} |
| 37 |
|
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
/* { dg-final { scan-tree-dump-times "kill \\(" 0 "evrp"} } */ |
| 42 |
/* { dg-final { scan-tree-dump-times "keep \\(" 1 "evrp"} } */ |
| 43 |
|