aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorTom de Vries <tom@codesourcery.com>2015-08-01 08:29:29 +0000
committerTom de Vries <vries@gcc.gnu.org>2015-08-01 08:29:29 +0000
commit805134b9170b4ac563189c24b35fa4dc09853569 (patch)
tree0353ecb04dbb4fcc695e28eb9c4d13e340815664 /gcc/tree.c
parentfaf4ac3218fdf7d316d7bd8da121029ba60f0099 (diff)
downloadgcc-805134b9170b4ac563189c24b35fa4dc09853569.zip
gcc-805134b9170b4ac563189c24b35fa4dc09853569.tar.gz
gcc-805134b9170b4ac563189c24b35fa4dc09853569.tar.bz2
Allow non-overflow ops in reductions
2015-08-01 Tom de Vries <tom@codesourcery.com> * tree.c (operation_can_overflow, operation_no_trapping_overflow): New function. * tree.h (operation_can_overflow, operation_no_trapping_overflow): Declare. * tree-vect-loop.c (vect_is_simple_reduction_1): Use operation_no_trapping_overflow. Allow non-overflow operations. * graphite-sese-to-poly.c (is_reduction_operation_p): Allow non-overflow operations. * gcc.dg/autopar/reduc-2char.c (init_arrays): Mark with attribute optimize ("-ftree-parallelize-loops=0"). Add successful scans for 2 detected reductions. Add xfail scans for 3 detected reductions. * gcc.dg/autopar/reduc-2short.c: Same. * gcc.dg/autopar/reduc-8.c (init_arrays): Mark with attribute optimize ("-ftree-parallelize-loops=0"). Add successful scans for 2 detected reductions. * gcc.dg/vect/trapv-vect-reduc-4.c: Update scan to match vectorized min and max reductions. From-SVN: r226463
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 94263af..3c2c20a 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -7597,6 +7597,75 @@ commutative_ternary_tree_code (enum tree_code code)
return false;
}
+/* Returns true if CODE can overflow. */
+
+bool
+operation_can_overflow (enum tree_code code)
+{
+ switch (code)
+ {
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ case MULT_EXPR:
+ case LSHIFT_EXPR:
+ /* Can overflow in various ways. */
+ return true;
+ case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ /* For INT_MIN / -1. */
+ return true;
+ case NEGATE_EXPR:
+ case ABS_EXPR:
+ /* For -INT_MIN. */
+ return true;
+ default:
+ /* These operators cannot overflow. */
+ return false;
+ }
+}
+
+/* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
+ ftrapv doesn't generate trapping insns for CODE. */
+
+bool
+operation_no_trapping_overflow (tree type, enum tree_code code)
+{
+ gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
+
+ /* We don't generate instructions that trap on overflow for complex or vector
+ types. */
+ if (!INTEGRAL_TYPE_P (type))
+ return true;
+
+ if (!TYPE_OVERFLOW_TRAPS (type))
+ return true;
+
+ switch (code)
+ {
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ case MULT_EXPR:
+ case NEGATE_EXPR:
+ case ABS_EXPR:
+ /* These operators can overflow, and -ftrapv generates trapping code for
+ these. */
+ return false;
+ case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ case LSHIFT_EXPR:
+ /* These operators can overflow, but -ftrapv does not generate trapping
+ code for these. */
+ return true;
+ default:
+ /* These operators cannot overflow. */
+ return true;
+ }
+}
+
namespace inchash
{