aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr68513.c
blob: 86f878d5d73533e5da0f5713236e0465f4cda078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* PR c/68513 */
/* { dg-do compile } */
/* { dg-options "-funsafe-math-optimizations -fno-math-errno -O -Wno-div-by-zero" } */

int i;
unsigned u;
volatile int *e;

#define E (i ? *e : 0)

/* Can't trigger some of them because operand_equal_p will return false
   for side-effects.  */

/* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
int
fn1 (void)
{
  int r = 0;
  r += (short) (E & ~u | i & u);
  r += -(short) (E & ~u | i & u);
  r += (short) -(E & ~u | i & u);
  return r;
}

/* sqrt(x) < y is x >= 0 && x != +Inf, when y is large.  */
double
fn2 (void)
{
  double r;
  r = __builtin_sqrt (E) < __builtin_inf ();
  return r;
}

/* sqrt(x) < c is the same as x >= 0 && x < c*c.  */
double
fn3 (void)
{
  double r;
  r = __builtin_sqrt (E) < 1.3;
  return r;
}

/* copysign(x,y)*copysign(x,y) -> x*x.  */
double
fn4 (double y, double x)
{
  return __builtin_copysign (E, y) * __builtin_copysign (E, y);
}

/* x <= +Inf is the same as x == x, i.e. !isnan(x).  */
int
fn5 (void)
{
  return E <= __builtin_inf ();
}

/* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
int
fn6 (void)
{
  return (i & ~E) - (i & E);
}

/* Fold (A & B) - (A & ~B) into B - (A ^ B).  */
int
fn7 (void)
{
  return (i & E) - (i & ~E);
}

/* x + (x & 1) -> (x + 1) & ~1 */
int
fn8 (void)
{
  return E + (E & 1);
}

/* Simplify comparison of something with itself.  */
int
fn9 (void)
{
  return E <= E | E >= E;
}

/* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
int
fn10 (void)
{
  return (i & ~E) - (i & E);
}

/* abs(x)*abs(x) -> x*x.  Should be valid for all types.  */
int
fn11 (void)
{
  return __builtin_abs (E) * __builtin_abs (E);
}

/* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
int
fn12 (void)
{
  return (E | 11) & 12;
}

/* fold_range_test */
int
fn13 (const char *s)
{
  return s[E] != '\0' && s[E] != '/';
}

/* fold_comparison */
int
fn14 (void)
{
  return (!!i ? : (u *= E / 0)) >= (u = E);
}

/* fold_mult_zconjz */
_Complex int
fn15 (_Complex volatile int *z)
{
  return *z * ~*z;
}