1 /* PR c/68513 */
2 /* { dg-do compile } */
3 /* { dg-options "-funsafe-math-optimizations -fno-math-errno -O -Wno-div-by-zero" } */
4 
5 int i;
6 unsigned u;
7 volatile int *e;
8 
9 #define E (i ? *e : 0)
10 
11 /* Can't trigger some of them because operand_equal_p will return false
12    for side-effects.  */
13 
14 /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
15 int
fn1(void)16 fn1 (void)
17 {
18   int r = 0;
19   r += (short) (E & ~u | i & u);
20   r += -(short) (E & ~u | i & u);
21   r += (short) -(E & ~u | i & u);
22   return r;
23 }
24 
25 /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large.  */
26 double
fn2(void)27 fn2 (void)
28 {
29   double r;
30   r = __builtin_sqrt (E) < __builtin_inf ();
31   return r;
32 }
33 
34 /* sqrt(x) < c is the same as x >= 0 && x < c*c.  */
35 double
fn3(void)36 fn3 (void)
37 {
38   double r;
39   r = __builtin_sqrt (E) < 1.3;
40   return r;
41 }
42 
43 /* copysign(x,y)*copysign(x,y) -> x*x.  */
44 double
fn4(double y,double x)45 fn4 (double y, double x)
46 {
47   return __builtin_copysign (E, y) * __builtin_copysign (E, y);
48 }
49 
50 /* x <= +Inf is the same as x == x, i.e. !isnan(x).  */
51 int
fn5(void)52 fn5 (void)
53 {
54   return E <= __builtin_inf ();
55 }
56 
57 /* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
58 int
fn6(void)59 fn6 (void)
60 {
61   return (i & ~E) - (i & E);
62 }
63 
64 /* Fold (A & B) - (A & ~B) into B - (A ^ B).  */
65 int
fn7(void)66 fn7 (void)
67 {
68   return (i & E) - (i & ~E);
69 }
70 
71 /* x + (x & 1) -> (x + 1) & ~1 */
72 int
fn8(void)73 fn8 (void)
74 {
75   return E + (E & 1);
76 }
77 
78 /* Simplify comparison of something with itself.  */
79 int
fn9(void)80 fn9 (void)
81 {
82   return E <= E | E >= E;
83 }
84 
85 /* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
86 int
fn10(void)87 fn10 (void)
88 {
89   return (i & ~E) - (i & E);
90 }
91 
92 /* abs(x)*abs(x) -> x*x.  Should be valid for all types.  */
93 int
fn11(void)94 fn11 (void)
95 {
96   return __builtin_abs (E) * __builtin_abs (E);
97 }
98 
99 /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
100 int
fn12(void)101 fn12 (void)
102 {
103   return (E | 11) & 12;
104 }
105 
106 /* fold_range_test */
107 int
fn13(const char * s)108 fn13 (const char *s)
109 {
110   return s[E] != '\0' && s[E] != '/';
111 }
112 
113 /* fold_comparison */
114 int
fn14(void)115 fn14 (void)
116 {
117   return (!!i ? : (u *= E / 0)) >= (u = E);
118 }
119 
120 /* fold_mult_zconjz */
121 _Complex int
fn15(_Complex volatile int * z)122 fn15 (_Complex volatile int *z)
123 {
124   return *z * ~*z;
125 }
126