| 1 |
/* PR tree-optimization/61839. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* Disable jump threading, we want to avoid separating the division/modulo |
| 4 |
by zero paths - we'd isolate those only later. */ |
| 5 |
/* { dg-options "-O2 -fno-thread-jumps -fdump-tree-evrp" } */ |
| 6 |
/* { dg-require-effective-target int32plus } */ |
| 7 |
|
| 8 |
__attribute__ ((noinline)) |
| 9 |
int foo () |
| 10 |
{ |
| 11 |
int a = -1; |
| 12 |
volatile unsigned b = 1U; |
| 13 |
int c = 1; |
| 14 |
c = (a + 972195718) / (b ? 2 : 0); |
| 15 |
if (c == 486097858) |
| 16 |
; |
| 17 |
else |
| 18 |
__builtin_abort (); |
| 19 |
return 0; |
| 20 |
} |
| 21 |
|
| 22 |
__attribute__ ((noinline)) |
| 23 |
int bar () |
| 24 |
{ |
| 25 |
int a = -1; |
| 26 |
volatile unsigned b = 1U; |
| 27 |
int c = 1; |
| 28 |
c = (a + 972195718) % (b ? 2 : 0); |
| 29 |
if (c == 1) |
| 30 |
; |
| 31 |
else |
| 32 |
__builtin_abort (); |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
__attribute__ ((noinline)) |
| 37 |
int bar2 () |
| 38 |
{ |
| 39 |
int a = -1; |
| 40 |
volatile unsigned b = 1U; |
| 41 |
int c = 1; |
| 42 |
c = (a + 972195716) % (b ? 1 : 2); |
| 43 |
if (c == 0) |
| 44 |
; |
| 45 |
else |
| 46 |
__builtin_abort (); |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
/* Ensure we are folding modulus sub-ranges properly. */ |
| 51 |
__attribute__ ((noinline)) |
| 52 |
int mod (int a, int b) |
| 53 |
{ |
| 54 |
int v1, v2; |
| 55 |
v1 = (a < 10) ? 12 : 24; |
| 56 |
v2 = (b > 20) ? 3 : 6; |
| 57 |
|
| 58 |
if (a > 20) |
| 59 |
v1 = v1 * 2; |
| 60 |
if (b > 20) |
| 61 |
v2 = v2 * 2; |
| 62 |
|
| 63 |
if (a == b) |
| 64 |
v2 = 0; |
| 65 |
|
| 66 |
/* v1 == 12, 24, or 48. v2 == 0, 3, 6, or 12. */ |
| 67 |
int c = v1 % v2; |
| 68 |
if (c == 0) |
| 69 |
; |
| 70 |
else |
| 71 |
__builtin_abort (); |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
/* EVRP now makes transformations in all functions, leaving a single |
| 76 |
* builtin_abort call in bar2. */ |
| 77 |
/* { dg-final { scan-tree-dump-times "__builtin_abort" 1 "evrp" } } */ |
| 78 |
|
| 79 |
/* Make sure to optimize 972195717 / 0 in function foo. */ |
| 80 |
/* { dg-final { scan-tree-dump-times "972195717 / " 0 "evrp" } } */ |
| 81 |
/* Make sure to optimize 972195717 % 0 in function bar. */ |
| 82 |
/* { dg-final { scan-tree-dump-times "972195717 % " 0 "evrp" } } */ |
| 83 |
/* Make sure to optimize 972195717 % [1,2] function bar2. */ |
| 84 |
/* { dg-final { scan-tree-dump-times "972195715 % " 0 "evrp" } } */ |
| 85 |
/* [12,12][24,24][48,48] % [0,0][3,3][6,6][12,12] == [0,0] */ |
| 86 |
/* { dg-final { scan-tree-dump-times "%" 0 "evrp" } } */ |