This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Improve folding of bitwise ops on booleans
- From: Kai Tietz <ktietz70 at googlemail dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 3 Jun 2013 18:37:36 +0200
- Subject: Re: [PATCH] Improve folding of bitwise ops on booleans
- References: <51A90588 dot 5080807 at redhat dot com> <CAFiYyc3yxAs0vV8qS830ubnprJSs5o4RCD+S9Pzkink_VPRzGw at mail dot gmail dot com> <51ACBEB8 dot 70005 at redhat dot com>
2013/6/3 Jeff Law <law@redhat.com>:
> The counter to that argument of leaving it to the backend to recover the
> and-not for is that the backend doesn't typically see these as single bit
> operations which makes turning the relational back into an and-not sequence
> considerably more difficult.
>
> Do we consider this enough of an issue to want to avoid going down this
> path? (in which case we'll file the example code as a missed-opt PR and
> attach the code and pointer to this thread for future reference)
>
Hmm, my tests are showing (for targets with conditional set
instructions) and improvement even for none-conditional-branch code.
Sample code:
_Bool foo (_Bool a, _Bool b)
{
_Bool r = a < b;
return r;
}
_Bool boo (_Bool a, _Bool b)
{
_Bool r = ~a & b;
return r;
}
produces:
.text
.p2align 4,,15
.globl foo
.def foo; .scl 2; .type 32; .endef
.seh_proc foo
foo:
.seh_endprologue
cmpb %cl, %dl
seta %al
ret
.seh_endproc
.p2align 4,,15
.globl boo
.def boo; .scl 2; .type 32; .endef
.seh_proc boo
boo:
.seh_endprologue
movl %ecx, %eax
notl %eax
andl %edx, %eax
andl $1, %eax
ret
So it seems to be obvious that code gets much less costy as without
this optimization.
Kai