scan-17.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. float r = 1.0f, a[1024], b[1024];
  8. __attribute__((noipa)) void
  9. foo (float *a, float *b)
  10. {
  11. #pragma omp for simd reduction (inscan, *:r)
  12. for (int i = 0; i < 1024; i++)
  13. {
  14. b[i] = r;
  15. #pragma omp scan exclusive(r)
  16. r *= a[i];
  17. }
  18. }
  19. __attribute__((noipa)) float
  20. bar (void)
  21. {
  22. float s = -__builtin_inff ();
  23. #pragma omp parallel for simd reduction (inscan, max:s)
  24. for (int i = 0; i < 1024; i++)
  25. {
  26. b[i] = s;
  27. #pragma omp scan exclusive(s)
  28. s = s > a[i] ? s : a[i];
  29. }
  30. return s;
  31. }
  32. int
  33. main ()
  34. {
  35. float s = 1.0f;
  36. for (int i = 0; i < 1024; ++i)
  37. {
  38. if (i < 80)
  39. a[i] = (i & 1) ? 0.25f : 0.5f;
  40. else if (i < 200)
  41. a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
  42. else if (i < 280)
  43. a[i] = (i & 1) ? 0.25f : 0.5f;
  44. else if (i < 380)
  45. a[i] = (i % 3) == 0 ? 2.0f : (i % 3) == 1 ? 4.0f : 1.0f;
  46. else
  47. switch (i % 6)
  48. {
  49. case 0: a[i] = 0.25f; break;
  50. case 1: a[i] = 2.0f; break;
  51. case 2: a[i] = -1.0f; break;
  52. case 3: a[i] = -4.0f; break;
  53. case 4: a[i] = 0.5f; break;
  54. case 5: a[i] = 1.0f; break;
  55. default: a[i] = 0.0f; break;
  56. }
  57. b[i] = -19.0f;
  58. asm ("" : "+g" (i));
  59. }
  60. #pragma omp parallel
  61. foo (a, b);
  62. if (r * 16384.0f != 0.125f)
  63. abort ();
  64. float m = -175.25f;
  65. for (int i = 0; i < 1024; ++i)
  66. {
  67. if (b[i] != s)
  68. abort ();
  69. else
  70. b[i] = -231.75f;
  71. s *= a[i];
  72. a[i] = m - ((i % 3) == 1 ? 2.0f : (i % 3) == 2 ? 4.0f : 0.0f);
  73. m += 0.75f;
  74. }
  75. if (bar () != 592.0f)
  76. abort ();
  77. s = -__builtin_inff ();
  78. for (int i = 0; i < 1024; ++i)
  79. {
  80. if (b[i] != s)
  81. abort ();
  82. if (s < a[i])
  83. s = a[i];
  84. }
  85. return 0;
  86. }