diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16.c | 70 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8.c | 111 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16.c | 77 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u8.c | 101 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-1.c | 60 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-2.c | 67 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect.exp | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-dot-s8.c | 108 | ||||
-rwxr-xr-x | gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-pattern-2.c | 59 |
9 files changed, 661 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16.c new file mode 100644 index 00000000000..ddffc109d35 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16.c @@ -0,0 +1,70 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 64 + +#define DOT1 43680 +#define DOT2 43680 + +signed short X[N] __attribute__ ((__aligned__(16))); +signed short Y[N] __attribute__ ((__aligned__(16))); + +/* short->short->int dot product. + Not detected as a dot-product pattern. + Currently fails to be vectorized due to presence of type conversions. */ +int +foo1(int len) { + int i; + int result = 0; + short prod; + + for (i=0; i<len; i++) { + prod = X[i] * Y[i]; + result += prod; + } + return result; +} + +/* short->int->int dot product. + Detected as a dot-product pattern. + Vectorized on targets that support dot-product for signed shorts. */ +int +foo2(int len) { + int i; + int result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + + +int main (void) +{ + int i, dot1, dot2; + + check_vect (); + + for (i=0; i<N; i++) { + X[i] = i; + Y[i] = 64-i; + } + + dot1 = foo1 (N); + if (dot1 != DOT1) + abort (); + + dot2 = foo2 (N); + if (dot2 != DOT2) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 1 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_sdot_hi } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8.c new file mode 100644 index 00000000000..8e5d48035b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8.c @@ -0,0 +1,111 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 64 + +#define DOT1 43680 +#define DOT2 -21856 +#define DOT3 43680 + +signed char X[N] __attribute__ ((__aligned__(16))); +signed char Y[N] __attribute__ ((__aligned__(16))); + +/* char->short->int dot product. + The dot-product pattern should be detected. + Vectorizable on vect_sdot_qi targets (targets that support dot-product of + signed chars). + + In the future could also be vectorized as widening-mult + widening-summation, + or with type-conversion support. + */ +int +foo1(int len) { + int i; + int result = 0; + short prod; + + for (i=0; i<len; i++) { + prod = X[i] * Y[i]; + result += prod; + } + return result; +} + +/* char->short->short dot product. + The dot-product pattern should be detected. + The reduction is currently not vectorized becaus of the signed->unsigned->signed + casts, since this patch: + + 2005-12-26 Kazu Hirata <kazu@codesourcery.com> + + PR tree-optimization/25125 + + When the dot-product is detected, the loop should be vectorized on vect_sdot_qi + targets (targets that support dot-product of signed char). + This test would currently fail to vectorize on targets that support + dot-product of chars when the accumulator is int. + + In the future could also be vectorized as widening-mult + summation, + or with type-conversion support. + */ +short +foo2(int len) { + int i; + short result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + +/* char->int->int dot product. + Not detected as a dot-product pattern. + Currently fails to be vectorized due to presence of type conversions. */ +int +foo3(int len) { + int i; + int result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + +int main (void) +{ + int i, dot1, dot3; + short dot2; + + check_vect (); + + for (i=0; i<N; i++) { + X[i] = i; + Y[i] = 64-i; + } + + dot1 = foo1 (N); + if (dot1 != DOT1) + abort (); + + dot2 = foo2 (N); + if (dot2 != DOT2) + abort (); + + dot3 = foo3 (N); + if (dot3 != DOT3) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 1 "vect" } } */ + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_sdot_qi } } } */ + +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16.c new file mode 100644 index 00000000000..03db7e0b6a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16.c @@ -0,0 +1,77 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 64 + +#define DOT1 43680 +#define DOT2 43680 + +unsigned short X[N] __attribute__ ((__aligned__(16))); +unsigned short Y[N] __attribute__ ((__aligned__(16))); + +/* short->short->int dot product. + Not detected as a dot-product pattern. + Not vectorized due to presence of type-conversions. */ +unsigned int +foo1(int len) { + int i; + unsigned int result = 0; + unsigned short prod; + + for (i=0; i<len; i++) { + prod = X[i] * Y[i]; + result += prod; + } + return result; +} + +/* short->int->int dot product. + Currently not detected as a dot-product pattern: the multiplication + promotes the ushorts to int, and then the product is promoted to unsigned + int for the addition. Which results in an int->unsigned int cast, which + since no bits are modified in the cast should be trivially vectorizable. */ +unsigned int +foo2(int len) { + int i; + unsigned int result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + + +int main (void) +{ + unsigned int dot1, dot2; + int i; + + check_vect (); + + for (i=0; i<N; i++) { + X[i] = i; + Y[i] = 64-i; + } + + dot1 = foo1 (N); + if (dot1 != DOT1) + abort (); + + dot2 = foo2 (N); + if (dot2 != DOT2) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 1 "vect" { xfail *-*-* } } } */ + +/* Once the dot-product pattern is detected in the second loop, we expect + that loop to be vectorized on vect_udot_hi targets (targets that support + dot-product of unsigned shorts). */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail *-*-* } } } */ + +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u8.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u8.c new file mode 100644 index 00000000000..ad68bc752c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u8.c @@ -0,0 +1,101 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 64 + +#define DOT1 43680 +#define DOT2 43680 +#define DOT3 43680 + +unsigned char X[N] __attribute__ ((__aligned__(16))); +unsigned char Y[N] __attribute__ ((__aligned__(16))); + +/* char->short->int dot product. + Detected as a dot-product pattern. + Should be vectorized on targets that support dot-product for unsigned chars. + */ +unsigned int +foo1(int len) { + int i; + unsigned int result = 0; + unsigned short prod; + + for (i=0; i<len; i++) { + prod = X[i] * Y[i]; + result += prod; + } + return result; +} + +/* char->short->short dot product. + Detected as a dot-product pattern. + Should be vectorized on targets that support dot-product for unsigned chars. + This test currently fails to vectorize on targets that support dot-product + of chars only when the accumulator is int. + */ +unsigned short +foo2(int len) { + int i; + unsigned short result = 0; + + for (i=0; i<len; i++) { + result += (unsigned short)(X[i] * Y[i]); + } + return result; +} + +/* char->int->int dot product. + Not detected as a dot-product. + Doesn't get vectorized due to presence of type converisons. */ +unsigned int +foo3(int len) { + int i; + unsigned int result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + +int main (void) +{ + unsigned int dot1, dot3; + unsigned short dot2; + int i; + + check_vect (); + + for (i=0; i<N; i++) { + X[i] = i; + Y[i] = 64-i; + } + + dot1 = foo1 (N); + if (dot1 != DOT1) + abort (); + + dot2 = foo2 (N); + if (dot2 != DOT2) + abort (); + + dot3 = foo3 (N); + if (dot3 != DOT3) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 2 "vect" } } */ + +/* When the vectorizer is enhanced to vectorize foo2 (accumulation into short) for + targets that support accumulation into int (powerpc, ia64) we'd have: +dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_udot_qi } } +*/ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_udot_qi } } } */ + +/* { dg-final { cleanup-tree-dump "vect" } } */ + diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-1.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-1.c new file mode 100644 index 00000000000..61f1da19d6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-1.c @@ -0,0 +1,60 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 16 +#define SH_SUM 210 +#define CH_SUM 120 + +int main1 () +{ + int i; + unsigned short udata_sh[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28}; + unsigned char udata_ch[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + unsigned int intsum = 0; + unsigned short shortsum = 0; + + /* widenning sum: sum shorts into int. */ + for (i = 0; i < N; i++){ + intsum += udata_sh[i]; + } + + /* check results: */ + if (intsum != SH_SUM) + abort (); + + /* widenning sum: sum chars into int. */ + intsum = 0; + for (i = 0; i < N; i++){ + intsum += udata_ch[i]; + } + + /* check results: */ + if (intsum != CH_SUM) + abort (); + + /* widenning sum: sum chars into short. + pattern detected, but not vectorized yet. */ + for (i = 0; i < N; i++){ + shortsum += udata_ch[i]; + } + + /* check results: */ + if (shortsum != CH_SUM) + abort (); + + return 0; +} + +int main (void) +{ + check_vect (); + + return main1 (); +} + +/* { dg-final { scan-tree-dump-times "vect_recog_widen_sum_pattern: detected" 3 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vectorized 3 loops" 1 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" { target vect_widen_sum } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-2.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-2.c new file mode 100644 index 00000000000..5423c4376d9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-2.c @@ -0,0 +1,67 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 16 +#define SH_SUM 210 +#define CH_SUM 120 + +int main1 () +{ + int i; + signed short data_sh[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28}; + signed char data_ch[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + signed int intsum = 0; + signed short shortsum = 0; + + /* widenning sum: sum shorts into int. */ + for (i = 0; i < N; i++){ + intsum += data_sh[i]; + } + + /* check results: */ + if (intsum != SH_SUM) + abort (); + + /* widenning sum: sum chars into int. */ + intsum = 0; + for (i = 0; i < N; i++){ + intsum += data_ch[i]; + } + + /* check results: */ + if (intsum != CH_SUM) + abort (); + + /* widenning sum: sum chars into short. + The widening-summation pattern is currently not detected because of this + patch: + + 2005-12-26 Kazu Hirata <kazu@codesourcery.com> + + PR tree-optimization/25125 + */ + for (i = 0; i < N; i++){ + shortsum += data_ch[i]; + } + + /* check results: */ + if (shortsum != CH_SUM) + abort (); + + return 0; +} + +int main (void) +{ + check_vect (); + + return main1 (); +} + +/* { dg-final { scan-tree-dump-times "vect_recog_widen_sum_pattern: detected" 3 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vect_recog_widen_sum_pattern: detected" 2 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vectorized 3 loops" 1 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" { target vect_widen_sum } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect.exp b/gcc/testsuite/gcc.dg/vect/vect.exp index bfa6dced9b1..9cf78ff8519 100644 --- a/gcc/testsuite/gcc.dg/vect/vect.exp +++ b/gcc/testsuite/gcc.dg/vect/vect.exp @@ -1,4 +1,4 @@ -# Copyright (C) 1997, 2004 Free Software Foundation, Inc. +# Copyright (C) 1997, 2004, 2005, 2006 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -78,7 +78,7 @@ dg-init dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/nodump-*.\[cS\]]] \ "" $DEFAULT_VECTCFLAGS -lappend DEFAULT_VECTCFLAGS "-ftree-vectorizer-verbose=4" "-fdump-tree-vect-stats" +lappend DEFAULT_VECTCFLAGS "-fdump-tree-vect-details" # Main loop. dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/pr*.\[cS\]]] \ @@ -96,6 +96,12 @@ lappend DEFAULT_VECTCFLAGS "-ffast-math" dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-vect*.\[cS\]]] \ "" $DEFAULT_VECTCFLAGS +# -fwrapv tests +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-fwrapv" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/wrapv-vect*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + # -ftrapv tests set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS lappend DEFAULT_VECTCFLAGS "-ftrapv" diff --git a/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-dot-s8.c b/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-dot-s8.c new file mode 100644 index 00000000000..b11b9c70086 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-dot-s8.c @@ -0,0 +1,108 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 64 + +#define DOT1 43680 +#define DOT2 -21856 +#define DOT3 43680 + +signed char X[N] __attribute__ ((__aligned__(16))); +signed char Y[N] __attribute__ ((__aligned__(16))); + +/* char->short->int dot product. + The dot-product pattern should be detected. + Vectorizable on vect_sdot_qi targets (targets that support dot-product of + signed chars). + + In the future could also be vectorized as widening-mult + widening-summation, + or with type-conversion support. + */ +int +foo1(int len) { + int i; + int result = 0; + short prod; + + for (i=0; i<len; i++) { + prod = X[i] * Y[i]; + result += prod; + } + return result; +} + +/* char->short->short dot product. + The dot-product pattern should be detected. + Should be vectorized on vect_sdot_qi targets (targets that support + dot-product of signed char). + This test currently fails to vectorize on targets that support + dot-product of chars when the accumulator is int. + + In the future could also be vectorized as widening-mult + summation, + or with type-conversion support. + */ +short +foo2(int len) { + int i; + short result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + +/* char->int->int dot product. + Not detected as a dot-product pattern. + Currently fails to be vectorized due to presence of type conversions. */ +int +foo3(int len) { + int i; + int result = 0; + + for (i=0; i<len; i++) { + result += (X[i] * Y[i]); + } + return result; +} + +int main (void) +{ + int i, dot1, dot3; + short dot2; + + check_vect (); + + for (i=0; i<N; i++) { + X[i] = i; + Y[i] = 64-i; + } + + dot1 = foo1 (N); + if (dot1 != DOT1) + abort (); + + dot2 = foo2 (N); + if (dot2 != DOT2) + abort (); + + dot3 = foo3 (N); + if (dot3 != DOT3) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vect_recog_dot_prod_pattern: detected" 2 "vect" } } */ + +/* When vectorizer is enhanced to vectorize foo2 (accumulation into short) for targets + that support accumulation into int (ia64) we'd have: +dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_sdot_qi } } +*/ +/* In the meantime expect: */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_sdot_qi } } } */ + +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-pattern-2.c b/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-pattern-2.c new file mode 100755 index 00000000000..6c844eac38e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-pattern-2.c @@ -0,0 +1,59 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +#define N 16 +#define SH_SUM 210 +#define CH_SUM 120 + +int main1 () +{ + int i; + signed short data_sh[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28}; + signed char data_ch[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + signed int intsum = 0; + signed short shortsum = 0; + + /* widenning sum: sum shorts into int. */ + for (i = 0; i < N; i++){ + intsum += data_sh[i]; + } + + /* check results: */ + if (intsum != SH_SUM) + abort (); + + /* widenning sum: sum chars into int. */ + intsum = 0; + for (i = 0; i < N; i++){ + intsum += data_ch[i]; + } + + /* check results: */ + if (intsum != CH_SUM) + abort (); + + /* widenning sum: sum chars into short. */ + for (i = 0; i < N; i++){ + shortsum += data_ch[i]; + } + + /* check results: */ + if (shortsum != CH_SUM) + abort (); + + return 0; +} + +int main (void) +{ + check_vect (); + + return main1 (); +} + +/* { dg-final { scan-tree-dump-times "vect_recog_widen_sum_pattern: detected" 3 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vectorized 3 loops" 1 "vect" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" { target vect_widen_sum } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ |