Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-9.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-9.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-9.c (revision 0) @@ -0,0 +1,47 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +__attribute__ ((noinline)) +int foo () +{ + unsigned int pos = 1; + unsigned int i; + float limit = 12; + + for (i = 0; i < N; i++) + if (arr[i] > limit) + { + pos = i + 1; + limit = arr[i]; + } + + return pos; +} + +int main (void) +{ + int i, pos; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr [2] = N + 15.8; + + pos = foo (); + if (pos != 3) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_cmp } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-1.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-1.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-1.c (revision 0) @@ -0,0 +1,47 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +__attribute__ ((noinline)) +int foo () +{ + unsigned int pos = 1; + unsigned int i; + float limit = N+N; + + for (i = 0; i < N; i++) + if (arr[i] < limit) + { + pos = i + 1; + limit = arr[i]; + } + + return pos; +} + +int main (void) +{ + int i, pos; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr [2] = -5.8; + + pos = foo (); + if (pos != 3) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_cmp } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-2.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-2.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-2.c (revision 0) @@ -0,0 +1,49 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +__attribute__ ((noinline)) +int foo (unsigned int n, float *min) +{ + unsigned int pos = 1; + unsigned int i; + float limit = N+N; + + for (i = 0; i < N; i++) + if (arr[i] < limit) + { + pos = i + 1; + limit = arr[i]; + } + + *min = limit; + return pos; +} + +int main (void) +{ + int i, pos; + float min; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr[2] = -5.8; + + pos = foo (N, &min); + if (pos != 3 || min != arr[2]) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_cmp } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-3.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-3.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-3.c (revision 0) @@ -0,0 +1,55 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; +short a[N]; + +/* Loop with multiple types - currently not supported. */ +__attribute__ ((noinline)) +int foo (unsigned int n, float *min, short x) +{ + unsigned int pos = 1; + unsigned int i; + float limit = N+N; + + for (i = 0; i < n; i++) + { + if (arr[i] < limit) + { + limit = arr[i]; + pos = i + 1; + } + + a[i] = x; + } + + *min = limit; + return pos; +} + +int main (void) +{ + int i, pos; + float min; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr[2] = -5.8; + + pos = foo (N, &min, 6); + if (pos != 3 || min != arr[2]) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-4.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-4.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-4.c (revision 0) @@ -0,0 +1,52 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +#define MAX_VALUE N+N +float arr[N]; + +/* Not minloc pattern - different conditions. */ +__attribute__ ((noinline)) +int foo () +{ + unsigned int pos = 1; + unsigned int i; + float limit = MAX_VALUE; + + for (i = 0; i < N; i++) + { + if (arr[i] < limit) + pos = i + 1; + + if (arr[i] > limit) + limit = arr[i]; + } + + return pos; +} + +int main (void) +{ + int i, pos; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr[2] = -5.8; + + pos = foo (); + + if (pos != N) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-5.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-5.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-5.c (revision 0) @@ -0,0 +1,50 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +/* Not minloc pattern: position is not induction. */ +__attribute__ ((noinline)) +int foo (unsigned int n, float *min) +{ + unsigned int pos = 1; + unsigned int i; + float limit = N+N; + + for (i = 0; i < n; i++) + if (arr[i] < limit) + { + pos = 5; + limit = arr[i]; + } + + *min = limit; + return pos; +} + +int main (void) +{ + int i, pos; + float min; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr[2] = -5.8; + + pos = foo (N, &min); + if (pos != 5 || min != arr[2]) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-6.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-6.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-6.c (revision 0) @@ -0,0 +1,50 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +/* Position and minimum are of types of different sizes - not supported. */ +__attribute__ ((noinline)) +int foo (unsigned short n, float *min) +{ + unsigned short pos = 1; + unsigned short i; + float limit = N+N; + + for (i = 0; i < n; i++) + if (arr[i] < limit) + { + pos = i + 1; + limit = arr[i]; + } + + *min = limit; + return pos; +} + +int main (void) +{ + int i, pos; + float min; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr[2] = -5.8; + + pos = foo (N, &min); + if (pos != 3 || min != arr[2]) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { xfail *-*-* } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/vect.exp =================================================================== --- gcc.dg/vect/vect.exp (revision 161484) +++ gcc.dg/vect/vect.exp (working copy) @@ -158,9 +158,27 @@ dg-runtest [lsort [glob -nocomplain $src # -ffast-math tests set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS lappend DEFAULT_VECTCFLAGS "-ffast-math" -dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-*.\[cS\]]] \ +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-pr*.\[cS\]]] \ "" $DEFAULT_VECTCFLAGS +# -ffast-math tests +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-ffast-math" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-slp*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + +# -ffast-math tests +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-ffast-math" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-vect*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + +# -ffast-math and -fno-tree-pre tests +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-ffast-math" "-fno-tree-pre" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-no-pre*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + # -fno-math-errno tests set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS lappend DEFAULT_VECTCFLAGS "-fno-math-errno" Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-7.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-7.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-7.c (revision 0) @@ -0,0 +1,49 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N][N]; + +/* Double reduction. */ +__attribute__ ((noinline)) +int foo () +{ + unsigned int pos = 1; + unsigned int i, j; + float limit = N+N; + + for (j = 0; j < N; j++) + for (i = 0; i < N; i++) + if (arr[i][j] < limit) + { + pos = i + 1; + limit = arr[i][j]; + } + + return pos; +} + +int main (void) +{ + int i, j, pos; + + check_vect(); + + for (j = 0; j < N; j++) + for (i = 0; i < N; i++) + arr[j][i] = (float)(i+j+1); + + arr[8][2] = 0; + pos = foo (); + if (pos != 9) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_cmp } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc.dg/vect/fast-math-no-pre-minmax-loc-8.c =================================================================== --- gcc.dg/vect/fast-math-no-pre-minmax-loc-8.c (revision 0) +++ gcc.dg/vect/fast-math-no-pre-minmax-loc-8.c (revision 0) @@ -0,0 +1,48 @@ +/* { dg-require-effective-target vect_float } */ + +#include +#include +#include "tree-vect.h" + +#define N 64 +float arr[N]; + +__attribute__ ((noinline)) +int foo () +{ + unsigned int pos = 1; + unsigned int i; + float limit = 7; + + for (i = 0; i < N; i++) + if (arr[i] >= limit) + { + pos = i + 1; + limit = arr[i]; + } + + return pos; +} + +int main (void) +{ + int i, pos; + + check_vect(); + + for (i = 0; i < N; i++) + arr[i] = (float)(i); + + arr [2] = N + 5.8; + arr [12] = N + 5.8; + + pos = foo (); + if (pos != 13) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_cmp } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: lib/target-supports.exp =================================================================== --- lib/target-supports.exp (revision 161484) +++ lib/target-supports.exp (working copy) @@ -2839,6 +2839,23 @@ proc check_effective_target_vect_strided return $et_vect_strided_wide_saved } +# Return 1 if the target supports vector comparison, 0 otherwise. +proc check_effective_target_vect_cmp { } { + global et_vect_cmp_saved + + if [info exists et_vect_cmp_saved] { + verbose "check_effective_target_vect_cmp: using cached result" 2 + } else { + set et_vect_cmp_saved 0 + if { [istarget powerpc*-*-*] } { + set et_vect_cmp_saved 1 + } + } + + verbose "check_effective_target_vect_cmp: returning $et_vect_cmp_saved" 2 + return $et_vect_cmp_saved +} + # Return 1 if the target supports section-anchors proc check_effective_target_section_anchors { } {