1 /* PR rtl-optimization/97459 */
2 /* { dg-do run } */
3 /* { dg-options "-O2" } */
4 /* { dg-additional-options "-DEXPENSIVE" { target run_expensive_tests } } */
5 
6 #ifdef __SIZEOF_INT128__
7 typedef __int128_t T;
8 typedef __uint128_t U;
9 #else
10 typedef long long T;
11 typedef unsigned long long U;
12 #endif
13 
foo(T x,T n)14 T __attribute__((noipa)) foo (T x, T n) { return x % n; }
15 #define C(n) T __attribute__((noipa)) foo##n (T x) { return x % (n - 10000); }
16 
17 #define C1(n) C(n##1) C(n##3) C(n##5) C(n##7) C(n##9)
18 #define C2(n) C1(n##0) C1(n##1) C1(n##2) C1(n##3) C1(n##4) \
19 	      C1(n##5) C1(n##6) C1(n##7) C1(n##8) C1(n##9)
20 #ifdef EXPENSIVE
21 #define C3(n) C2(n##0) C2(n##1) C2(n##2) C2(n##3) C2(n##4) \
22 	      C2(n##5) C2(n##6) C2(n##7) C2(n##8) C2(n##9)
23 #define C4(n) C3(n##0) C3(n##1) C3(n##2) C3(n##3) C3(n##4) \
24 	      C3(n##5) C3(n##6) C3(n##7) C3(n##8) C3(n##9)
25 #else
26 #define C3(n) C2(n##0) C2(n##4) C2(n##9)
27 #define C4(n) C3(n##0) C3(n##3) C3(n##7)
28 #endif
29 #define TESTS C4(1) C1(10010) C1(10012) C1(16144)
30 
31 TESTS
32 
33 struct S { T x; T (*foo) (T); };
34 
35 #undef C
36 #define C(n) { n - 10000, foo##n },
37 
38 struct S tests[] = {
39 TESTS
40   { 0, 0 }
41 };
42 
43 int
main()44 main ()
45 {
46   int i, j, k;
47   for (k = 0; tests[k].x; k++)
48     for (i = 0; i < sizeof (T) * __CHAR_BIT__; i++)
49       for (j = -5; j <= 5; j++)
50 	{
51 	  U x = ((U) 1 << i) + j;
52 	  if (foo ((T) x, tests[k].x) != tests[k].foo ((T) x)
53 	      || foo ((T) -x, tests[k].x) != tests[k].foo ((T) -x))
54 	    __builtin_abort ();
55 	}
56   return 0;
57 }
58