simd-9.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* { dg-do run } */
  2. /* { dg-options "-O2" } */
  3. /* { dg-additional-options "-msse2" { target sse2_runtime } } */
  4. /* { dg-additional-options "-mavx" { target avx_runtime } } */
  5. extern void abort ();
  6. int a[32][32] __attribute__((aligned (32))) = { { 1 } };
  7. struct S { int s; };
  8. #pragma omp declare reduction (+:struct S:omp_out.s += omp_in.s)
  9. #pragma omp declare reduction (foo:struct S:omp_out.s += omp_in.s)
  10. #pragma omp declare reduction (foo:int:omp_out += omp_in)
  11. __attribute__((noinline, noclone)) int
  12. foo (void)
  13. {
  14. int i, j, u = 0;
  15. struct S s, t;
  16. s.s = 0; t.s = 0;
  17. #pragma omp simd aligned(a : 32) lastprivate (i, j) reduction(+:s) reduction(foo:t, u) collapse(2)
  18. for (i = 0; i < 32; i++)
  19. for (j = 0; j < 32; j++)
  20. {
  21. int *q = &i;
  22. int *r = &j;
  23. int x = a[i][j];
  24. s.s += x;
  25. t.s += x;
  26. u += x;
  27. }
  28. if (t.s != s.s || u != s.s || i != 32 || j != 32)
  29. abort ();
  30. return s.s;
  31. }
  32. __attribute__((noinline, noclone)) int
  33. bar (void)
  34. {
  35. int i, j, u = 0;
  36. struct S s, t;
  37. s.s = 0; t.s = 0;
  38. #pragma omp simd aligned(a:32)reduction(+:s)reduction(foo:t,u)collapse(2)
  39. for (i = 0; i < 32; i++)
  40. for (j = 0; j < 32; j++)
  41. {
  42. int *q = &i;
  43. int *r = &j;
  44. int x = a[i][j];
  45. s.s += x;
  46. t.s += x;
  47. u += x;
  48. }
  49. if (t.s != s.s || u != s.s || i != 32 || j != 32)
  50. abort ();
  51. return s.s;
  52. }
  53. int
  54. main ()
  55. {
  56. int i, j;
  57. for (i = 0; i < 32; i++)
  58. for (j = 0; j < 32; j++)
  59. a[i][j] = j + (i / 4);
  60. int s = foo ();
  61. if (s != 19456)
  62. abort ();
  63. if (bar () != 19456)
  64. abort ();
  65. return 0;
  66. }