On Wed, Jul 13, 2011 at 9:32 AM, Kai Tietz <ktiet...@googlemail.com> wrote: > Hello, > > This patch adds support to fold_range_test and to fold_truthop for > one-bit precision > typed bitwise-binary and bitwise-not expressions.
This looks reasonable but I'd like to see testcases excercising the foldings (by scanning the .original dump). Richard. > ChangeLog > > 2011-07-13 Kai Tietz <kti...@redhat.com> > > * fold-const.c (fold_range_test): Add > support for one-bit bitwise operations. > (fold_truthop): Likewise. > > Bootstrapped and regression tested with prior patches of this series > for x86_64-pc-linux-gnu. > Ok for apply? > > Regards, > Kai > > Index: gcc/gcc/fold-const.c > =================================================================== > --- gcc.orig/gcc/fold-const.c 2011-07-13 08:07:59.000000000 +0200 > +++ gcc/gcc/fold-const.c 2011-07-13 08:59:26.117620200 +0200 > @@ -4819,7 +4819,8 @@ fold_range_test (location_t loc, enum tr > tree op0, tree op1) > { > int or_op = (code == TRUTH_ORIF_EXPR > - || code == TRUTH_OR_EXPR); > + || code == TRUTH_OR_EXPR > + || code == BIT_IOR_EXPR); > int in0_p, in1_p, in_p; > tree low0, low1, low, high0, high1, high; > bool strict_overflow_p = false; > @@ -4890,7 +4891,7 @@ fold_range_test (location_t loc, enum tr > } > } > > - return 0; > + return NULL_TREE; > } > > /* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P > @@ -5118,8 +5119,9 @@ fold_truthop (location_t loc, enum tree_ > } > } > > - code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR) > - ? TRUTH_AND_EXPR : TRUTH_OR_EXPR); > + if (code != BIT_AND_EXPR && code != BIT_IOR_EXPR) > + code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR) > + ? TRUTH_AND_EXPR : TRUTH_OR_EXPR); > > /* If the RHS can be evaluated unconditionally and its operands are > simple, it wins to evaluate the RHS unconditionally on machines > @@ -5134,7 +5136,7 @@ fold_truthop (location_t loc, enum tree_ > && simple_operand_p (rr_arg)) > { > /* Convert (a != 0) || (b != 0) into (a | b) != 0. */ > - if (code == TRUTH_OR_EXPR > + if ((code == TRUTH_OR_EXPR || code == BIT_IOR_EXPR) > && lcode == NE_EXPR && integer_zerop (lr_arg) > && rcode == NE_EXPR && integer_zerop (rr_arg) > && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) > @@ -5145,7 +5147,7 @@ fold_truthop (location_t loc, enum tree_ > build_int_cst (TREE_TYPE (ll_arg), 0)); > > /* Convert (a == 0) && (b == 0) into (a | b) == 0. */ > - if (code == TRUTH_AND_EXPR > + if ((code == TRUTH_AND_EXPR || code == BIT_AND_EXPR) > && lcode == EQ_EXPR && integer_zerop (lr_arg) > && rcode == EQ_EXPR && integer_zerop (rr_arg) > && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) > @@ -5209,7 +5211,8 @@ fold_truthop (location_t loc, enum tree_ > fail. However, we can convert a one-bit comparison against zero into > the opposite comparison against that bit being set in the field. */ > > - wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR); > + wanted_code = ((code == TRUTH_AND_EXPR > + || code == BIT_AND_EXPR) ? EQ_EXPR : NE_EXPR); > if (lcode != wanted_code) > { > if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask)) >