From 2d698d3bb7f1b7761b35b31326a0326ce375ef8e Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 12 Aug 2010 10:38:05 +0000 Subject: re PR tree-optimization/45232 (tree reassociation introduces undefined overflow) 2010-08-12 Richard Guenther PR tree-optimization/45232 * tree-ssa-reassoc.c (can_reassociate_p): Disable re-association for types with undefined overflow. (reassociate_bb): Allow re-associating of bit and min/max operations for types with undefined overflow. * tree-ssa-forwprop.c (associate_plusminus): New function. (tree_ssa_forward_propagate_single_use_vars): Call it. * gcc.dg/tree-ssa/pr44133.c: Adjust warning location. * gcc.dg/tree-ssa/loop-7.c: Adjust. * gcc.dg/tree-ssa/reassoc-1.c: XFAIL. * gcc.dg/tree-ssa/reassoc-20.c: Add reassoc-1.c variant with unsigned arithmetic. * gcc.dg/tree-ssa/reassoc-14.c: Use unsigned arithmetic. * gcc.dg/tree-ssa/reassoc-15.c: Likewise. * gcc.dg/tree-ssa/reassoc-18.c: Likewise. * gcc.dg/tree-ssa/reassoc-2.c: XFAIL. * gcc.dg/tree-ssa/reassoc-21.c: Add reassoc-2.c variant with unsigned arithmetic. * gcc.dg/tree-ssa/reassoc-6.c: XFAIL. * gcc.dg/tree-ssa/reassoc-22.c: Add reassoc-6.c variant with unsigned arithmetic. * gcc.dg/tree-ssa/reassoc-7.c: Use unsigned arithmetic. * gcc.dg/tree-ssa/reassoc-9.c: XFAIL. * gcc.dg/tree-ssa/reassoc-23.c: Add reassoc-9.c variant with unsigned arithmetic. * gcc.dg/tree-ssa/ssa-pre-2.c: Adjust. * gcc.dg/tree-ssa/negate.c: Adjust. * gcc.dg/vect/vect-1.c: Adjust. * gfortran.dg/reassoc_6.f: XFAIL. From-SVN: r163190 --- gcc/tree-ssa-reassoc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gcc/tree-ssa-reassoc.c') diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 6cd3ceb..adc5a8d 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -1949,7 +1949,7 @@ static bool can_reassociate_p (tree op) { tree type = TREE_TYPE (op); - if (INTEGRAL_TYPE_P (type) + if ((INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) || NON_SAT_FIXED_POINT_TYPE_P (type) || (flag_associative_math && FLOAT_TYPE_P (type))) return true; @@ -2065,9 +2065,16 @@ reassociate_bb (basic_block bb) rhs1 = gimple_assign_rhs1 (stmt); rhs2 = gimple_assign_rhs2 (stmt); - if (!can_reassociate_p (lhs) - || !can_reassociate_p (rhs1) - || !can_reassociate_p (rhs2)) + /* For non-bit or min/max operations we can't associate + all types. Verify that here. */ + if (rhs_code != BIT_IOR_EXPR + && rhs_code != BIT_AND_EXPR + && rhs_code != BIT_XOR_EXPR + && rhs_code != MIN_EXPR + && rhs_code != MAX_EXPR + && (!can_reassociate_p (lhs) + || !can_reassociate_p (rhs1) + || !can_reassociate_p (rhs2))) continue; if (associative_tree_code (rhs_code)) -- cgit v1.1