parloops-exit-first-loop-alt.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* { dg-do run } */
  2. /* { dg-additional-options "-ftree-parallelize-loops=2" } */
  3. /* Variable bound, vector addition, signed loop counter, unsigned bound. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define N 1000
  7. unsigned int a[N];
  8. unsigned int b[N];
  9. unsigned int c[N];
  10. void __attribute__((noclone,noinline))
  11. f (unsigned int n, unsigned int *__restrict__ a, unsigned int *__restrict__ b,
  12. unsigned int *__restrict__ c)
  13. {
  14. int i;
  15. for (i = 0; i < n; ++i)
  16. c[i] = a[i] + b[i];
  17. }
  18. static void __attribute__((noclone,noinline))
  19. init (void)
  20. {
  21. int i, j;
  22. /* Complexify loop to inhibit parloops. */
  23. for (j = 0; j < 100; ++j)
  24. for (i = 0; i < 10; i++)
  25. {
  26. int k = i + (10 * j);
  27. a[k] = k;
  28. b[k] = (k * 3) % 7;
  29. c[k] = k * 2;
  30. }
  31. }
  32. int
  33. main (void)
  34. {
  35. int i;
  36. init ();
  37. f (N, a, b, c);
  38. for (i = 0; i < N; i++)
  39. {
  40. unsigned int actual = c[i];
  41. unsigned int expected = i + ((i * 3) % 7);
  42. if (actual != expected)
  43. abort ();
  44. }
  45. /* Test low iteration count case. */
  46. init ();
  47. f (10, a, b, c);
  48. for (i = 0; i < N; i++)
  49. {
  50. unsigned int actual = c[i];
  51. unsigned int expected = (i < 10
  52. ? i + ((i * 3) % 7)
  53. : i * 2);
  54. if (actual != expected)
  55. abort ();
  56. }
  57. return 0;
  58. }