Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-05 Thread Kai Tietz
2013/6/4 Jeff Law : > On 06/03/2013 08:23 AM, Kai Tietz wrote: >> >> >> Btw there is one optimization in this context which might be something >> worth here too. >> -X -> X for 1-bit typed X (signed doesn't matter here). > > I've had a hell of a time trying to trigger a case where this isn't alread

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-05 Thread Eric Botcazou
> Eventually we should force all BOOLEAN_TYPEs to have precision 1 but > as Kai remembers Ada uses alternate values for verification (true, false, > NaT or so). Eric may be able to explain. Correct, see: http://gcc.gnu.org/ml/gcc-patches/2011-05/msg01214.html A boolean type isn't a modular type o

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-05 Thread Richard Biener
On Tue, Jun 4, 2013 at 9:20 PM, Jeff Law wrote: > On 06/03/2013 08:23 AM, Kai Tietz wrote: >> >> >> Btw there is one optimization in this context which might be something >> worth here too. >> -X -> X for 1-bit typed X (signed doesn't matter here). > > I've had a hell of a time trying to trigger a

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Segher Boessenkool
1) GCC uses the all-fields instruction instead of the one-field form unless you use -mmfcrf (or -mcpu=power4, etc.), although the one-field mfcr works fine on all CPUs and is never slower (I'm not talking about mfocrf; just the plain mfcr instruction); Ugh, need more coffee, forget about this on

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Segher Boessenkool
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 i

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Andrew Pinski
On Tue, Jun 4, 2013 at 6:42 PM, Segher Boessenkool wrote: >> However, in looking at it, if we rewrite the code to have come from >> comparisons: > > > > > >> _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;

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Segher Boessenkool
However, in looking at it, if we rewrite the code to have come from comparisons: _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: .L.bfoo_cmp: cmpd 6,3,4 cmpd 7,5,6 mfcr 3,2

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Jeff Law
On 06/03/2013 08:23 AM, Kai Tietz wrote: Btw there is one optimization in this context which might be something worth here too. -X -> X for 1-bit typed X (signed doesn't matter here). I've had a hell of a time trying to trigger a case where this isn't already handled. Samples welcome.

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Kai Tietz
2013/6/4 Jeff Law : > On 06/04/2013 04:45 AM, Richard Biener wrote: >>> >>> >>> Yes. Booleans are integral types with a single bit of precision, right? >>> So >>> this check should allow boolean types. What am I missing? >> >> >> We have BOOLEAN_TYPEs that do not have a TYPE_PRECISION of one >> (

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Jeff Law
On 06/04/2013 04:45 AM, Richard Biener wrote: Yes. Booleans are integral types with a single bit of precision, right? So this check should allow boolean types. What am I missing? We have BOOLEAN_TYPEs that do not have a TYPE_PRECISION of one (but still are two-valued, and we assume those va

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Richard Biener
On Mon, Jun 3, 2013 at 8:34 PM, Jeff Law wrote: > On 06/03/2013 12:32 PM, Kai Tietz wrote: >> >> 2013/6/3 Jeff Law : >>> >>> On 06/03/2013 11:00 AM, Richard Henderson wrote: On 06/03/2013 09:37 AM, Kai Tietz wrote: > > > foo: > .seh_endprologue >

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-04 Thread Richard Biener
On Mon, Jun 3, 2013 at 6:05 PM, Jeff Law wrote: > On 06/03/2013 02:24 AM, Richard Biener wrote: >> >> On Fri, May 31, 2013 at 10:18 PM, Jeff Law wrote: >>> >>> >>> This is an implementation to fix a missed optimization pointed out to me >>> by >>> Kai. >>> >>> In all these examples, assume a & b

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Michael Meissner
On Mon, Jun 03, 2013 at 10:00:19AM -0700, Richard Henderson wrote: > On 06/03/2013 09:37 AM, Kai Tietz wrote: > > foo: > > .seh_endprologue > > cmpb%cl, %dl > > seta%al > > ret > > .seh_endproc > > .p2align 4,,15 > > .globl boo > >

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Jeff Law
On 06/03/2013 12:32 PM, Kai Tietz wrote: 2013/6/3 Jeff Law : On 06/03/2013 11:00 AM, Richard Henderson wrote: On 06/03/2013 09:37 AM, Kai Tietz wrote: foo: .seh_endprologue cmpb%cl, %dl seta%al ret .seh_endproc .p2align 4,,1

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Kai Tietz
2013/6/3 Jeff Law : > On 06/03/2013 11:00 AM, Richard Henderson wrote: >> >> On 06/03/2013 09:37 AM, Kai Tietz wrote: >>> >>> foo: >>> .seh_endprologue >>> cmpb%cl, %dl >>> seta%al >>> ret >>> .seh_endproc >>> .p2align 4,,15 >>>

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Richard Henderson
On 06/03/2013 09:37 AM, Kai Tietz wrote: > foo: > .seh_endprologue > cmpb%cl, %dl > seta%al > ret > .seh_endproc > .p2align 4,,15 > .globl boo > .defboo;.scl2; .type 32; .endef > .seh_proc

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Jeff Law
On 06/03/2013 11:00 AM, Richard Henderson wrote: On 06/03/2013 09:37 AM, Kai Tietz wrote: foo: .seh_endprologue cmpb%cl, %dl seta%al ret .seh_endproc .p2align 4,,15 .globl boo .defboo;.scl2; .type

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Kai Tietz
2013/6/3 Jeff Law : > 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

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Jeff Law
On 06/03/2013 02:24 AM, Richard Biener wrote: On Fri, May 31, 2013 at 10:18 PM, Jeff Law wrote: This is an implementation to fix a missed optimization pointed out to me by Kai. In all these examples, assume a & b are single bit types. ~a && b --> a < b For a signed 1-bit type you'll have v

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Kai Tietz
Hmm, it isn't necessary to restrict this optimization AFAICS. We have just two cases. (~X & Y) -> X < Y (X & ~Y) -> Y < X (~X | Y) -> X <= Y (X | ~Y) -> Y <= X is true for unsigned 1-bit types. For signed 1-bit types we need to invert logic here as following: (~X & Y) -> X > Y (X & ~Y) -> Y >

Re: [PATCH] Improve folding of bitwise ops on booleans

2013-06-03 Thread Richard Biener
On Fri, May 31, 2013 at 10:18 PM, Jeff Law wrote: > > This is an implementation to fix a missed optimization pointed out to me by > Kai. > > In all these examples, assume a & b are single bit types. > > ~a && b --> a < b For a signed 1-bit type you'll have values -1, 0 and clearly 0 < -1 is f

[PATCH] Improve folding of bitwise ops on booleans

2013-05-31 Thread Jeff Law
This is an implementation to fix a missed optimization pointed out to me by Kai. In all these examples, assume a & b are single bit types. ~a && b --> a < b a && ~b --> b < a ~a || b --> a <= b a && ~b --> b <= a This happens with some regularity in GCC itself, though it's not as pervasive