This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Reassociate X == CST1 || X == CST2 if popcount (CST2 - CST1) == 1 into ((X - CST1) & ~(CST2 - CST1)) == 0
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Zhenqiang Chen <zhenqiang dot chen at arm dot com>
- Cc: "'Jeff Law'" <law at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 10 Oct 2013 12:10:04 +0200
- Subject: Re: [PATCH] Reassociate X == CST1 || X == CST2 if popcount (CST2 - CST1) == 1 into ((X - CST1) & ~(CST2 - CST1)) == 0
- Authentication-results: sourceware.org; auth=none
- References: <000001ce91b3$0a947cc0$1fbd7640$ at arm dot com> <52561947 dot 90600 at redhat dot com> <000001cec59a$99f2ba60$cdd82f20$ at arm dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Oct 10, 2013 at 05:25:01PM +0800, Zhenqiang Chen wrote:
> > Note I've been suggesting the bits I'm referring to in fold-const.c move
> out
> > into the tree-ssa optimizers. If they fit well into tree-ssa-reassoc.c
> I'd look
> > favorably upon a patch which moved them.
>
> The code is similar with the code (in tree-ssa-reassoc.c) for
> Optimize X == CST1 || X == CST2
> if popcount (CST1 ^ CST2) == 1 into
> (X & ~(CST1 ^ CST2)) == (CST1 & ~(CST1 ^ CST2))
Yeah. Though, that is one operation cheaper than this, the above
is replacing two comparisons with constants plus one || with
one arithmetic operation (with constant) plus one comparison of constant,
I think that should be always a win (ok, it is one arithmetic operation
more expensive if X == CST1 all the time, but otherwise it is likely
cheaper). While in your case it is two arithmetic operations plus
comparison with constant, so perhaps for very cheap BRANCH_COST it might
not be beneficial.
Jakub