scan-13.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. r *= a[i];
  15. #pragma omp scan inclusive(r)
  16. b[i] = r;
  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. s = s > a[i] ? s : a[i];
  27. #pragma omp scan inclusive(s)
  28. b[i] = s;
  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. s *= a[i];
  68. if (b[i] != s)
  69. abort ();
  70. else
  71. {
  72. a[i] = m - ((i % 3) == 1 ? 2.0f : (i % 3) == 2 ? 4.0f : 0.0f);
  73. b[i] = -231.75f;
  74. m += 0.75f;
  75. }
  76. }
  77. if (bar () != 592.0f)
  78. abort ();
  79. s = -__builtin_inff ();
  80. for (int i = 0; i < 1024; ++i)
  81. {
  82. if (s < a[i])
  83. s = a[i];
  84. if (b[i] != s)
  85. abort ();
  86. }
  87. return 0;
  88. }