This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fold-const.c: Don't transform X & C into (X >> C') & 1in fold_binary.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: rsandifo at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org, law at redhat dot com, roger at eyesopen dot com
- Date: Wed, 20 Apr 2005 18:04:56 -0400 (EDT)
- Subject: Re: [patch] fold-const.c: Don't transform X & C into (X >> C') & 1in fold_binary.
- References: <20050420.172552.50360813.kazu@cs.umass.edu><87r7h5jf6g.fsf@firetop.home>
Hi Richard,
> > Roger agreed that it was a good idea to disable this transformation in
> > fold, but I would like to know what others think as well. Jeff?
> > Richard?
>
> Certainly no objections here ;) As I suspect you know...
Great! :-)
> > IIRC, do_jump contains code to reverse the effect of
> > fold_single_bit_test. If this patch is approved, I am planning to
> > adjust that code as a follow-up patch.
>
> ...I only added that do_jump code because the conversion in fold
> was causing a MIPS performance regression. I would have been much
> happier removing the fold transformation if I thought I could have
> got away with it, but others seemed to believe that it was useful
> in some cases.
I am guessing that the reason why people like (a >> 2) & 1 is that it
can be directly used for a store flag type of operation, but as I have
mentioned in the original post, do_store_flag can take (a & 4) != 0
and emit (a >> 2) & 1.
> If your argument holds true, I'd be glad to see both the fold code
> and the do_jump code removed. (At least, assuming I've understood
> correctly, and that this:
>
> > AFAICT, it does not matter whether we do this transformation or not as
> > far as conditional branches are concerned. Combine canonicalizes a
> > single bit test into zero_extract regardless of whether we have
> >
> > a & 4
> >
> > or
> >
> > (a >> 2) & 1
>
> means that, even without the jump code, we will continue to avoid the
> shift on MIPS if the user writes "(X >> 2) & 1" themselves.)
Oh, I should have been a bit more careful here. I meant that if we
are setting cc0 or a MODE_CC register, combine canonicalizes a single
bit test into zero_extract (regardless of whether we have a & 4 or
(a >> 2) & 1. If the MIPS port has no such insn, I suspect with my
patch, (a >> 2) & 1 would stay as is. If you like, I'd be happy to
teach fold_binary to transform (a >> 2) & 1 != 0 back to a & 4 != 0
for you
Kazu Hirata