[PATCH] Improve folding of bitwise ops on booleans

Andrew Pinski pinskia@gmail.com
Wed Jun 5 01:46:00 GMT 2013


On Tue, Jun 4, 2013 at 6:42 PM, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>> However, in looking at it, if we rewrite the code to have come from
>> comparisons:
>
>
> <snip>
>
>
>> _Bool bfoo_cmp (long w, long x, long y, long z)
>> {
>>   _Bool a = (w < x);
>>   _Bool b = (y < z);
>>   _Bool r = ~a & b;
>>   return r;
>> }
>>
>> We get:
>
>
> <snip>
>
>
>> .L.bfoo_cmp:
>>         cmpd 6,3,4
>>         cmpd 7,5,6
>>         mfcr 3,2
>>         rlwinm 3,3,25,1
>>         mfcr 6,1
>>         rlwinm 6,6,29,1
>>         andc 3,6,3
>>         blr
>
>
> It is a bit better on 32-bit:
>
> bfoo_cmp:
>         cmpw 7,3,4
>         cmpw 6,5,6
>         mfcr 3
>         rlwinm 6,3,25,1
>         rlwinm 3,3,29,1
>
>         andc 3,6,3
>         blr
>
>> And it would have been nice to use the logcal comparison operations in the
>> CR
>> register unit (i.e. doing a crandc in the CR unit rather than moving the
>> value
>> from a CR to a GPR -- cmpd/mfcr/rlwinm instructions).
>
>
> We cannot avoid an mfcr then, either.  It would be one machine
> instruction shorter though (but can be more expensive to execute,
> on some CPUs).
>
> That you get two MFCRs on 64-bit is a target bug.

Not true there.  If you look at the 64bit output you will see you are
using the one cr mfcr version in 64bit while you are grabbing the full
cr in the 32bit.  It depends on the processor but the one cr might be
better.

Thanks,
Andrew

>
>
> Segher
>



More information about the Gcc-patches mailing list