scan-9.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* { dg-require-effective-target size32plus } */
  2. extern void abort (void);
  3. int r, a[1024], b[1024], x, y, z;
  4. __attribute__((noipa)) void
  5. foo (int *a, int *b)
  6. {
  7. #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) firstprivate (x) private (y)
  8. for (int i = 0; i < 1024; i++)
  9. {
  10. { y = a[i]; r += y + x + 12; }
  11. #pragma omp scan inclusive(r)
  12. { b[i] = r; if ((i & 1) == 0 && i < 937) z = r; }
  13. }
  14. }
  15. __attribute__((noipa)) int
  16. bar (void)
  17. {
  18. int s = 0;
  19. #pragma omp parallel
  20. #pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) lastprivate (z)
  21. for (int i = 0; i < 1024; i++)
  22. {
  23. { y = 2 * a[i]; s += y; z = y; }
  24. #pragma omp scan inclusive(s)
  25. { y = s; b[i] = y + x + 12; }
  26. }
  27. return s;
  28. }
  29. __attribute__((noipa)) void
  30. baz (int *a, int *b)
  31. {
  32. #pragma omp parallel for reduction (inscan, +:r) firstprivate (x) lastprivate (x)
  33. for (int i = 0; i < 1024; i++)
  34. {
  35. { r += a[i] + x + 12; if (i == 1023) x = 29; }
  36. #pragma omp scan inclusive(r)
  37. b[i] = r;
  38. }
  39. }
  40. __attribute__((noipa)) int
  41. qux (void)
  42. {
  43. int s = 0;
  44. #pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: x, y)
  45. for (int i = 0; i < 1024; i++)
  46. {
  47. { s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i]; }
  48. #pragma omp scan inclusive(s)
  49. { b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i]; }
  50. }
  51. return s;
  52. }
  53. int
  54. main ()
  55. {
  56. int s = 0;
  57. x = -12;
  58. for (int i = 0; i < 1024; ++i)
  59. {
  60. a[i] = i;
  61. b[i] = -1;
  62. asm ("" : "+g" (i));
  63. }
  64. #pragma omp parallel
  65. foo (a, b);
  66. if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
  67. abort ();
  68. for (int i = 0; i < 1024; ++i)
  69. {
  70. s += i;
  71. if (b[i] != s)
  72. abort ();
  73. else
  74. b[i] = 25;
  75. }
  76. if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
  77. abort ();
  78. s = 0;
  79. for (int i = 0; i < 1024; ++i)
  80. {
  81. s += 2 * i;
  82. if (b[i] != s)
  83. abort ();
  84. else
  85. b[i] = -1;
  86. }
  87. r = 0;
  88. baz (a, b);
  89. if (r != 1024 * 1023 / 2 || x != 29)
  90. abort ();
  91. s = 0;
  92. for (int i = 0; i < 1024; ++i)
  93. {
  94. s += i;
  95. if (b[i] != s)
  96. abort ();
  97. else
  98. b[i] = -25;
  99. }
  100. if (qux () != 1024 * 1023 || x != 823 || y != 828)
  101. abort ();
  102. s = 0;
  103. for (int i = 0; i < 1024; ++i)
  104. {
  105. s += 2 * i;
  106. if (b[i] != s)
  107. abort ();
  108. }
  109. return 0;
  110. }