scan-20.c 2.6 KB

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