| 1 |
/* { dg-options "-O2 -fwrapv -fdump-tree-optimized-raw" } */ |
| 2 |
|
| 3 |
#define TEST_CMP(FN, DIV, ADD, MUL) \ |
| 4 |
int \ |
| 5 |
FN (int x) \ |
| 6 |
{ \ |
| 7 |
if (x & 7) \ |
| 8 |
__builtin_unreachable (); \ |
| 9 |
x /= DIV; \ |
| 10 |
x += (int) (ADD); \ |
| 11 |
return x * MUL; \ |
| 12 |
} |
| 13 |
|
| 14 |
TEST_CMP (f1, 2, ~0U >> 1, 6) |
| 15 |
TEST_CMP (f2, 2, ~(~0U >> 2), 10) |
| 16 |
|
| 17 |
void |
| 18 |
cmp1 (int x) |
| 19 |
{ |
| 20 |
if (x & 3) |
| 21 |
__builtin_unreachable (); |
| 22 |
|
| 23 |
int y = x / 4; |
| 24 |
y += (int) (~0U / 3U); |
| 25 |
y *= 8; |
| 26 |
|
| 27 |
unsigned z = x; |
| 28 |
z *= 2U; |
| 29 |
z += ~0U / 3U * 8U; |
| 30 |
|
| 31 |
if (y != (int) z) |
| 32 |
__builtin_abort (); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
void |
| 37 |
cmp2 (int x) |
| 38 |
{ |
| 39 |
if (x & 63) |
| 40 |
__builtin_unreachable (); |
| 41 |
|
| 42 |
unsigned y = x / 64; |
| 43 |
y += 100U; |
| 44 |
int y2 = (int) y * 256; |
| 45 |
|
| 46 |
unsigned z = x; |
| 47 |
z *= 4U; |
| 48 |
z += 25600U; |
| 49 |
|
| 50 |
if (y2 != (int) z) |
| 51 |
__builtin_abort (); |
| 52 |
} |
| 53 |
|
| 54 |
/* { dg-final { scan-tree-dump-not {<[a-z]*_div_expr,} "optimized" } } */ |
| 55 |
/* { dg-final { scan-tree-dump-not {<rshift_expr,} "optimized" } } */ |
| 56 |
/* { dg-final { scan-tree-dump-not {gimple_call <} "optimized" } } */ |
| 57 |
/* { dg-final { scan-tree-dump-times {<nop_expr,} 4 "optimized" } } */ |
| 58 |
/* { dg-final { scan-tree-dump-times {<mult_expr,} 2 "optimized" } } */ |
| 59 |
/* { dg-final { scan-tree-dump-times {<plus_expr,} 2 "optimized" } } */ |