This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Move ~X | X -> -1 folding
- From: Marek Polacek <polacek at redhat dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Tue, 30 Jun 2015 12:24:08 +0200
- Subject: Re: [PATCH] Move ~X | X -> -1 folding
- Authentication-results: sourceware.org; auth=none
- References: <20150630084620 dot GN10139 at redhat dot com> <alpine dot DEB dot 2 dot 20 dot 1506301056540 dot 1977 at laptop-mg dot saclay dot inria dot fr>
On Tue, Jun 30, 2015 at 11:08:35AM +0200, Marc Glisse wrote:
> On Tue, 30 Jun 2015, Marek Polacek wrote:
>
> >This moves a simple optimization. Here it's plain to see how :c
> >removes the need to duplicate code to handle commutativity.
>
> Note that the same transformation would work for plus and xor.
Sounds like a good follow-up. I think moving from fold-const.c to
match.pd ought to be 1:1 for clarity. I'll prepare a patch to also
handle +/^.
> >I put some more converts into the pattern, but then it's turned
> >out that I also need the tree_nop_conversion_p (otherwise we'd
> >regress binop-notor2.c that uses booleans).
>
> I don't really see why removing tree_nop_conversion_p would regress anything
> (though you would probably need to build the all_ones constant in TREE_TYPE
> (@0) and convert that to type). For my curiosity, could you explain a bit
> more?
This wasn't all that clear to me. The testcase in question is
int
foo (_Bool a, _Bool b)
{
return (a | (a == 0)) | ((b ^ 1) | b);
}
this ought to be simplified to "return 1". Through various folding we
arrive at
(int) ~b | (int) b
so we'd turn that into -1 (all_ones_cst of type int). But for boolean b
"~b | b" is always 1, right?
Marek