1 /* { dg-do run } */
2 /* { dg-options "-O1" } */
3
4 #include <stdint.h>
5 #include <limits.h>
6 #include <stdio.h>
7
8 #ifndef N
9 #define N 65
10 #endif
11
12 #ifndef TYPE
13 #define TYPE int32_t
14 #endif
15
16 #ifndef DEBUG
17 #define DEBUG 1
18 #endif
19
20 #define BASE ((TYPE) -1 < 0 ? -126 : 4)
21
22 __attribute__ ((noinline, noipa))
23 void fun1(TYPE *x, int n)
24 {
25 for (int i = 0; i < n; i++)
26 x[i] = (-x[i]) >> 31;
27 }
28
29 __attribute__ ((noinline, noipa, optimize("O0")))
30 void fun2(TYPE *x, int n)
31 {
32 for (int i = 0; i < n; i++)
33 x[i] = (-x[i]) >> 31;
34 }
35
36 int main ()
37 {
38 TYPE a[N];
39 TYPE b[N];
40
41 a[0] = INT_MIN;
42 b[0] = INT_MIN;
43
44 for (int i = 1; i < N; ++i)
45 {
46 a[i] = BASE + i * 13;
47 b[i] = BASE + i * 13;
48 if (DEBUG)
49 printf ("%d: 0x%x\n", i, a[i]);
50 }
51
52 fun1 (a, N);
53 fun2 (b, N);
54
55 if (DEBUG)
56 printf ("%d = 0x%x == 0x%x\n", 0, a[0], b[0]);
57
58 if (a[0] != 0x0 || b[0] != -1)
59 __builtin_abort ();
60
61
62 for (int i = 1; i < N; ++i)
63 {
64 if (DEBUG)
65 printf ("%d = 0x%x == 0x%x\n", i, a[i], b[i]);
66
67 if (a[i] != b[i])
68 __builtin_abort ();
69 }
70 return 0;
71 }
72