aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2021-11-30 09:52:25 +0000
committerRichard Sandiford <richard.sandiford@arm.com>2021-11-30 09:52:25 +0000
commite32b9eb32d7cd2d39bf9c70497890ac61b9ee14c (patch)
tree3f4188ad4a2fc980f1b134c4f0137c3aba7947d9 /gcc/tree-vect-loop.c
parent30213ae9a2eb53f6bc0913919457ceae2572b019 (diff)
downloadgcc-e32b9eb32d7cd2d39bf9c70497890ac61b9ee14c.zip
gcc-e32b9eb32d7cd2d39bf9c70497890ac61b9ee14c.tar.gz
gcc-e32b9eb32d7cd2d39bf9c70497890ac61b9ee14c.tar.bz2
vect: Add support for fmax and fmin reductions
This patch adds support for reductions involving calls to fmax*() and fmin*(), without the -ffast-math flags that allow them to be converted to MAX_EXPR and MIN_EXPR. gcc/ * doc/md.texi (reduc_fmin_scal_@var{m}): Document. (reduc_fmax_scal_@var{m}): Likewise. * optabs.def (reduc_fmax_scal_optab): New optab. (reduc_fmin_scal_optab): Likewise * internal-fn.def (REDUC_FMAX, REDUC_FMIN): New functions. * tree-vect-loop.c (reduction_fn_for_scalar_code): Handle CASE_CFN_FMAX and CASE_CFN_FMIN. (neutral_op_for_reduction): Likewise. (needs_fold_left_reduction_p): Likewise. * config/aarch64/iterators.md (FMAXMINV): New iterator. (fmaxmin): Handle UNSPEC_FMAXNMV and UNSPEC_FMINNMV. * config/aarch64/aarch64-simd.md (reduc_<optab>_scal_<mode>): Fix unspec mode. (reduc_<fmaxmin>_scal_<mode>): New pattern. * config/aarch64/aarch64-sve.md (reduc_<fmaxmin>_scal_<mode>): Likewise. gcc/testsuite/ * gcc.dg/vect/vect-fmax-1.c: New test. * gcc.dg/vect/vect-fmax-2.c: Likewise. * gcc.dg/vect/vect-fmax-3.c: Likewise. * gcc.dg/vect/vect-fmin-1.c: New test. * gcc.dg/vect/vect-fmin-2.c: Likewise. * gcc.dg/vect/vect-fmin-3.c: Likewise. * gcc.target/aarch64/fmaxnm_1.c: Likewise. * gcc.target/aarch64/fmaxnm_2.c: Likewise. * gcc.target/aarch64/fminnm_1.c: Likewise. * gcc.target/aarch64/fminnm_2.c: Likewise. * gcc.target/aarch64/sve/fmaxnm_2.c: Likewise. * gcc.target/aarch64/sve/fmaxnm_3.c: Likewise. * gcc.target/aarch64/sve/fminnm_2.c: Likewise. * gcc.target/aarch64/sve/fminnm_3.c: Likewise.
Diffstat (limited to 'gcc/tree-vect-loop.c')
-rw-r--r--gcc/tree-vect-loop.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index b1198e1..841da78 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -3185,9 +3185,22 @@ reduction_fn_for_scalar_code (code_helper code, internal_fn *reduc_fn)
return true;
default:
- break;
- }
- return false;
+ return false;
+ }
+ else
+ switch (combined_fn (code))
+ {
+ CASE_CFN_FMAX:
+ *reduc_fn = IFN_REDUC_FMAX;
+ return true;
+
+ CASE_CFN_FMIN:
+ *reduc_fn = IFN_REDUC_FMIN;
+ return true;
+
+ default:
+ return false;
+ }
}
/* If there is a neutral value X such that a reduction would not be affected
@@ -3223,9 +3236,18 @@ neutral_op_for_reduction (tree scalar_type, code_helper code,
return initial_value;
default:
- break;
+ return NULL_TREE;
+ }
+ else
+ switch (combined_fn (code))
+ {
+ CASE_CFN_FMIN:
+ CASE_CFN_FMAX:
+ return initial_value;
+
+ default:
+ return NULL_TREE;
}
- return NULL_TREE;
}
/* Error reporting helper for vect_is_simple_reduction below. GIMPLE statement
@@ -3255,9 +3277,18 @@ needs_fold_left_reduction_p (tree type, code_helper code)
return false;
default:
- break;
+ return !flag_associative_math;
+ }
+ else
+ switch (combined_fn (code))
+ {
+ CASE_CFN_FMIN:
+ CASE_CFN_FMAX:
+ return false;
+
+ default:
+ return !flag_associative_math;
}
- return !flag_associative_math;
}
if (INTEGRAL_TYPE_P (type))