simd-9.c 1.5 KB

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