[backport from gcc-4.9/trunk r197060, fixes regression from r196855 ] List-Archive: Date: Mon, 25 Mar 2013 13:08:18 -0600 From: Jeff Law Subject: Re: Record missing equivalence On 03/21/2013 03:44 AM, Richard Biener wrote: >> + /* If LHS is an SSA_NAME and RHS is a constant and LHS was set >> + via a widening type conversion, then we may be able to record >> + additional equivalences. */ >> + if (lhs >> + && TREE_CODE (lhs) == SSA_NAME >> + && is_gimple_constant (rhs)) >> + { >> + gimple defstmt = SSA_NAME_DEF_STMT (lhs); >> + >> + if (defstmt >> + && is_gimple_assign (defstmt) >> + && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (defstmt))) >> + { >> + tree old_rhs = gimple_assign_rhs1 (defstmt); >> + tree newval = fold_convert (TREE_TYPE (old_rhs), rhs); > > You want to delay that folding and creating of a new tree node until after ... > >> + >> + /* If this was a widening conversion and if RHS is >> converted >> + to the type of OLD_RHS and has the same value, then we >> + can record an equivalence between OLD_RHS and the >> + converted representation of RHS. */ >> + if ((TYPE_PRECISION (TREE_TYPE (lhs)) >> + > TYPE_PRECISION (TREE_TYPE (old_rhs))) > > ... this check. > >> + && operand_equal_p (rhs, newval, 0)) > > If you'd restricted yourself to handling INTEGER_CSTs then using > int_fits_type_p (rhs, TREE_TYPE (lhs)) would have been enough to check. > > And operand_equal_p will never return for non-equal typed non-INTEGER_CSTs > anyway ... Agreed. Addressed via the attached patch which was committed after a bootstrap and regression test on x86_64-unknown-linux-gnu. gcc/ 2013-03-25 Jeff Law * tree-ssa-dom.c (record_equivalences_from_incoming_edge): Rework slightly to avoid creating and folding useless trees. Simplify slightly by restricting to INTEGER_CSTs and using int_fits_type_p. --- gcc-4.8.0/gcc/tree-ssa-dom.c.~1~ 2013-03-29 12:46:25.565102162 +0100 +++ gcc-4.8.0/gcc/tree-ssa-dom.c 2013-03-29 12:46:48.665032210 +0100 @@ -1135,12 +1135,13 @@ record_equivalences_from_incoming_edge ( if (lhs) record_equality (lhs, rhs); - /* If LHS is an SSA_NAME and RHS is a constant and LHS was set - via a widening type conversion, then we may be able to record + /* If LHS is an SSA_NAME and RHS is a constant integer and LHS was + set via a widening type conversion, then we may be able to record additional equivalences. */ if (lhs && TREE_CODE (lhs) == SSA_NAME - && is_gimple_constant (rhs)) + && is_gimple_constant (rhs) + && TREE_CODE (rhs) == INTEGER_CST) { gimple defstmt = SSA_NAME_DEF_STMT (lhs); @@ -1149,16 +1150,14 @@ record_equivalences_from_incoming_edge ( && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (defstmt))) { tree old_rhs = gimple_assign_rhs1 (defstmt); - tree newval = fold_convert (TREE_TYPE (old_rhs), rhs); - /* If this was a widening conversion and if RHS is converted - to the type of OLD_RHS and has the same value, then we - can record an equivalence between OLD_RHS and the - converted representation of RHS. */ - if ((TYPE_PRECISION (TREE_TYPE (lhs)) - > TYPE_PRECISION (TREE_TYPE (old_rhs))) - && operand_equal_p (rhs, newval, 0)) - record_equality (old_rhs, newval); + /* If the constant is in the range of the type of OLD_RHS, + then convert the constant and record the equivalence. */ + if (int_fits_type_p (rhs, TREE_TYPE (old_rhs))) + { + tree newval = fold_convert (TREE_TYPE (old_rhs), rhs); + record_equality (old_rhs, newval); + } } }