Message ID | 87fvl5dsyt.fsf@talisman.default |
---|---|
State | New |
Headers | show |
On Tue, Apr 22, 2014 at 10:12 PM, Richard Sandiford <rdsandiford@googlemail.com> wrote: > This patch undoes a few assorted differences from trunk. > > For fold-const.c the old code was: > > /* If INNER is a right shift of a constant and it plus BITNUM does > not overflow, adjust BITNUM and INNER. */ > if (TREE_CODE (inner) == RSHIFT_EXPR > && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST > && tree_fits_uhwi_p (TREE_OPERAND (inner, 1)) > && bitnum < TYPE_PRECISION (type) > && (tree_to_uhwi (TREE_OPERAND (inner, 1)) > < (unsigned) (TYPE_PRECISION (type) - bitnum))) > { > bitnum += tree_to_uhwi (TREE_OPERAND (inner, 1)); > inner = TREE_OPERAND (inner, 0); > } > > and we lost the bitnum range test. > > The gimple-fold.c change contained an unrelated stylistic change that > makes the code a bit less efficient. > > For ipa-prop.c we should convert to a HOST_WIDE_INT before multiplying, > like trunk does. It doesn't change the result and is more efficient. > > objc-act.c contains three copies of the same code. The check for 0 was > kept in the third but not the first two. > > Tested on x86_64-linux-gnu. OK to install? Ok. Thanks, Richard. > Thanks, > Richard > > > Index: gcc/fold-const.c > =================================================================== > --- gcc/fold-const.c 2014-04-22 21:00:26.921619127 +0100 > +++ gcc/fold-const.c 2014-04-22 21:00:27.317622218 +0100 > @@ -6581,8 +6581,9 @@ fold_single_bit_test (location_t loc, en > not overflow, adjust BITNUM and INNER. */ > if (TREE_CODE (inner) == RSHIFT_EXPR > && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST > - && wi::ltu_p (wi::to_widest (TREE_OPERAND (inner, 1)) + bitnum, > - TYPE_PRECISION (type))) > + && bitnum < TYPE_PRECISION (type) > + && wi::ltu_p (TREE_OPERAND (inner, 1), > + TYPE_PRECISION (type) - bitnum)) > { > bitnum += tree_to_uhwi (TREE_OPERAND (inner, 1)); > inner = TREE_OPERAND (inner, 0); > Index: gcc/gimple-fold.c > =================================================================== > --- gcc/gimple-fold.c 2014-04-22 20:58:26.869682704 +0100 > +++ gcc/gimple-fold.c 2014-04-22 21:00:27.318622226 +0100 > @@ -3163,12 +3163,13 @@ fold_const_aggregate_ref_1 (tree t, tree > && (idx = (*valueize) (TREE_OPERAND (t, 1))) > && TREE_CODE (idx) == INTEGER_CST) > { > - tree low_bound = array_ref_low_bound (t); > - tree unit_size = array_ref_element_size (t); > + tree low_bound, unit_size; > > /* If the resulting bit-offset is constant, track it. */ > - if (TREE_CODE (low_bound) == INTEGER_CST > - && tree_fits_uhwi_p (unit_size)) > + if ((low_bound = array_ref_low_bound (t), > + TREE_CODE (low_bound) == INTEGER_CST) > + && (unit_size = array_ref_element_size (t), > + tree_fits_uhwi_p (unit_size))) > { > offset_int woffset > = wi::sext (wi::to_offset (idx) - wi::to_offset (low_bound), > Index: gcc/ipa-prop.c > =================================================================== > --- gcc/ipa-prop.c 2014-04-22 20:58:26.869682704 +0100 > +++ gcc/ipa-prop.c 2014-04-22 21:00:27.319622234 +0100 > @@ -3787,8 +3787,8 @@ ipa_modify_call_arguments (struct cgraph > if (TYPE_ALIGN (type) > align) > align = TYPE_ALIGN (type); > } > - misalign += (offset_int::from (off, SIGNED) > - * BITS_PER_UNIT).to_short_addr (); > + misalign += (offset_int::from (off, SIGNED).to_short_addr () > + * BITS_PER_UNIT); > misalign = misalign & (align - 1); > if (misalign != 0) > align = (misalign & -misalign); > Index: gcc/objc/objc-act.c > =================================================================== > --- gcc/objc/objc-act.c 2014-04-22 20:58:26.869682704 +0100 > +++ gcc/objc/objc-act.c 2014-04-22 21:00:27.320622242 +0100 > @@ -4882,7 +4882,9 @@ objc_decl_method_attributes (tree *node, > which specifies the index of the format string > argument. Add 2. */ > number = TREE_VALUE (second_argument); > - if (number && TREE_CODE (number) == INTEGER_CST) > + if (number > + && TREE_CODE (number) == INTEGER_CST > + && !wi::eq_p (number, 0)) > TREE_VALUE (second_argument) > = wide_int_to_tree (TREE_TYPE (number), > wi::add (number, 2)); > @@ -4893,7 +4895,9 @@ objc_decl_method_attributes (tree *node, > in which case we don't need to add 2. Add 2 if not > 0. */ > number = TREE_VALUE (third_argument); > - if (number && TREE_CODE (number) == INTEGER_CST) > + if (number > + && TREE_CODE (number) == INTEGER_CST > + && !wi::eq_p (number, 0)) > TREE_VALUE (third_argument) > = wide_int_to_tree (TREE_TYPE (number), > wi::add (number, 2));
Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2014-04-22 21:00:26.921619127 +0100 +++ gcc/fold-const.c 2014-04-22 21:00:27.317622218 +0100 @@ -6581,8 +6581,9 @@ fold_single_bit_test (location_t loc, en not overflow, adjust BITNUM and INNER. */ if (TREE_CODE (inner) == RSHIFT_EXPR && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST - && wi::ltu_p (wi::to_widest (TREE_OPERAND (inner, 1)) + bitnum, - TYPE_PRECISION (type))) + && bitnum < TYPE_PRECISION (type) + && wi::ltu_p (TREE_OPERAND (inner, 1), + TYPE_PRECISION (type) - bitnum)) { bitnum += tree_to_uhwi (TREE_OPERAND (inner, 1)); inner = TREE_OPERAND (inner, 0); Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c 2014-04-22 20:58:26.869682704 +0100 +++ gcc/gimple-fold.c 2014-04-22 21:00:27.318622226 +0100 @@ -3163,12 +3163,13 @@ fold_const_aggregate_ref_1 (tree t, tree && (idx = (*valueize) (TREE_OPERAND (t, 1))) && TREE_CODE (idx) == INTEGER_CST) { - tree low_bound = array_ref_low_bound (t); - tree unit_size = array_ref_element_size (t); + tree low_bound, unit_size; /* If the resulting bit-offset is constant, track it. */ - if (TREE_CODE (low_bound) == INTEGER_CST - && tree_fits_uhwi_p (unit_size)) + if ((low_bound = array_ref_low_bound (t), + TREE_CODE (low_bound) == INTEGER_CST) + && (unit_size = array_ref_element_size (t), + tree_fits_uhwi_p (unit_size))) { offset_int woffset = wi::sext (wi::to_offset (idx) - wi::to_offset (low_bound), Index: gcc/ipa-prop.c =================================================================== --- gcc/ipa-prop.c 2014-04-22 20:58:26.869682704 +0100 +++ gcc/ipa-prop.c 2014-04-22 21:00:27.319622234 +0100 @@ -3787,8 +3787,8 @@ ipa_modify_call_arguments (struct cgraph if (TYPE_ALIGN (type) > align) align = TYPE_ALIGN (type); } - misalign += (offset_int::from (off, SIGNED) - * BITS_PER_UNIT).to_short_addr (); + misalign += (offset_int::from (off, SIGNED).to_short_addr () + * BITS_PER_UNIT); misalign = misalign & (align - 1); if (misalign != 0) align = (misalign & -misalign); Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c 2014-04-22 20:58:26.869682704 +0100 +++ gcc/objc/objc-act.c 2014-04-22 21:00:27.320622242 +0100 @@ -4882,7 +4882,9 @@ objc_decl_method_attributes (tree *node, which specifies the index of the format string argument. Add 2. */ number = TREE_VALUE (second_argument); - if (number && TREE_CODE (number) == INTEGER_CST) + if (number + && TREE_CODE (number) == INTEGER_CST + && !wi::eq_p (number, 0)) TREE_VALUE (second_argument) = wide_int_to_tree (TREE_TYPE (number), wi::add (number, 2)); @@ -4893,7 +4895,9 @@ objc_decl_method_attributes (tree *node, in which case we don't need to add 2. Add 2 if not 0. */ number = TREE_VALUE (third_argument); - if (number && TREE_CODE (number) == INTEGER_CST) + if (number + && TREE_CODE (number) == INTEGER_CST + && !wi::eq_p (number, 0)) TREE_VALUE (third_argument) = wide_int_to_tree (TREE_TYPE (number), wi::add (number, 2));