This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Compile (X & C) == 0 to (X >> C) & 1 == 0 only at RTL level


On Thu, 28 Aug 2008, Paolo Bonzini wrote:

> 
> >> In my case, the problem is that I added a NOP_EXPR folding.  Then the
> >> last fold_convert in fold_single_bit_test rebuilds the BIT_AND_EXPR for
> >> (X >> C) & 1 and, fold_binary causes the canonicalization to happen.  At
> >> least this means that my NOP_EXPR folding is very effective in making
> >> canonical forms. :-)
> > 
> > Hm, I am somewhat confused by the above paragraphs (and my memory).
> > What is the canonical form of single bit tests now?  I thought it
> > was (X >> C) & 1.
> 
> I also thought so, but the number of foldings that introduce
> EQ_EXPR/NE_EXPR, including the following two:
> 
>    /* If we have (A & C) == C where C is a power of 2, convert this into
>       (A & C) != 0.  Similarly for NE_EXPR.  */
> 
> 
>    /* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y.  */
> 
> which explicitly undo what fold_single_bit_test does; and the fact that
> fold_single_bit_test is only ever called from expr.c, means that it is not.

Ok, I was probably confused because I ran into the following code a while
ago

      /* If this is an EQ or NE comparison with zero and ARG0 is
         (1 << foo) & bar, convert it to (bar >> foo) & 1.  Both require
         two operations, but the latter can be done in one less insn
         on machines that have only two-operand insns or on which a
         constant cannot be the first operand.  */
      if (TREE_CODE (arg0) == BIT_AND_EXPR
          && integer_zerop (arg1))
        {
...

> > It seems you allow truncating conversions, like  (short)(i + 5), to
> > be converted to (short)i + 5.
> 
> Yes, I noticed that while proceeding with the work on PR37242.  For now,
> I'll ask for approval without the fold_unary hunk (after
> bootstrapping/regtesting alone, of course).

The other parts are fine.

Thanks,
Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]