1 /* { dg-do run } */ 2 /* { dg-options "-O2 -floop-interchange -fdump-tree-linterchange-details" } */ 3 /* { dg-skip-if "too big data segment" { avr-*-* visium-*-* } } */ 4 5 #define M 256 6 int a[M][M], b[M][M], c[M], d[M]; 7 void __attribute__((noinline)) simple_reduc_1(int n)8simple_reduc_1 (int n) 9 { 10 for (int j = 0; j < n; j++) 11 { 12 int sum = c[j]; 13 for (int i = 0; i < n; i++) 14 sum = sum + a[i][j]*b[i][j]; 15 16 c[j] = sum; 17 } 18 } 19 20 void __attribute__((noinline)) simple_reduc_2(int n)21simple_reduc_2 (int n) 22 { 23 for (int j = 0; j < n; j++) 24 { 25 int sum = d[j]; 26 for (int i = 0; i < n; i++) 27 sum = sum + a[i][j]*b[i][j]; 28 29 asm volatile ("" ::: "memory"); 30 d[j] = sum; 31 } 32 } 33 34 extern void abort (); 35 36 static void __attribute__((noinline)) init(int i)37init (int i) 38 { 39 c[i] = 0; 40 d[i] = 0; 41 for (int j = 0; j < M; j++) 42 { 43 a[i][j] = i; 44 b[i][j] = j; 45 } 46 } 47 main(void)48int main (void) 49 { 50 for (int i = 0; i < M; ++i) 51 init (i); 52 53 simple_reduc_1 (M); 54 simple_reduc_2 (M); 55 56 for (int i = 0; i < M; ++i) 57 if (c[i] != d[i]) 58 abort (); 59 60 return 0; 61 } 62 63 /* { dg-final { scan-tree-dump-times "Loop_pair<outer:., inner:.> is interchanged" 1 "linterchange" } } */ 64