Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-29 Thread Jeff Law
On 11/29/2016 03:16 AM, Richard Biener wrote: On Mon, Nov 28, 2016 at 7:41 PM, Jeff Law wrote: On 11/28/2016 06:10 AM, Paolo Bonzini wrote: On 27/11/2016 00:28, Marc Glisse wrote: On Sat, 26 Nov 2016, Paolo Bonzini wrote: --- match.pd(revision 242742) +++ match.pd

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-29 Thread Richard Biener
On Tue, Nov 29, 2016 at 12:50 PM, Paolo Bonzini wrote: > > > On 29/11/2016 11:16, Richard Biener wrote: >> (bit_and >> (if (shift > 0) >>(lshift (convert @0) { build_int_cst (integer_type_node, shift); }) >>(convert (rshift @0 { build_int_cst

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-29 Thread Paolo Bonzini
On 29/11/2016 11:16, Richard Biener wrote: >>> >> (bit_and >>> >> (if (shift > 0) >>> >>(lshift (convert @0) { build_int_cst (integer_type_node, shift); }) >>> >>(convert (rshift @0 { build_int_cst (integer_type_node, -shift); }))) >>> >> @3) >>> >> >>> >> What do you think? >> > >>

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-29 Thread Richard Biener
On Mon, Nov 28, 2016 at 7:41 PM, Jeff Law wrote: > On 11/28/2016 06:10 AM, Paolo Bonzini wrote: >> >> >> >> On 27/11/2016 00:28, Marc Glisse wrote: >>> >>> On Sat, 26 Nov 2016, Paolo Bonzini wrote: >>> --- match.pd(revision 242742) +++ match.pd(working copy)

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-28 Thread Jeff Law
On 11/28/2016 06:10 AM, Paolo Bonzini wrote: On 27/11/2016 00:28, Marc Glisse wrote: On Sat, 26 Nov 2016, Paolo Bonzini wrote: --- match.pd(revision 242742) +++ match.pd(working copy) @@ -2554,6 +2554,19 @@ (cmp (bit_and@2 @0 integer_pow2p@1) @1) (icmp @2 { build_zero_cst

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-28 Thread Paolo Bonzini
On 27/11/2016 00:28, Marc Glisse wrote: > On Sat, 26 Nov 2016, Paolo Bonzini wrote: > >> --- match.pd(revision 242742) >> +++ match.pd(working copy) >> @@ -2554,6 +2554,19 @@ >> (cmp (bit_and@2 @0 integer_pow2p@1) @1) >> (icmp @2 { build_zero_cst (TREE_TYPE (@0)); }))) >> >> +/* If

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-26 Thread Segher Boessenkool
On Sat, Nov 26, 2016 at 11:22:44PM +0100, Paolo Bonzini wrote: > The combine.c hunk instead is needed to simplify cases that do not use the > ternary operator (the "h" and "i" functions in the testcases) like this: > > return ((x >> 9) & 1) << 7; > > Normally this is simplified just fine

Re: [PATCH] improve folding of expressions that move a single bit around

2016-11-26 Thread Marc Glisse
On Sat, 26 Nov 2016, Paolo Bonzini wrote: --- match.pd(revision 242742) +++ match.pd(working copy) @@ -2554,6 +2554,19 @@ (cmp (bit_and@2 @0 integer_pow2p@1) @1) (icmp @2 { build_zero_cst (TREE_TYPE (@0)); }))) +/* If we have (A & C) != 0 ? D : 0 where C and D are powers of 2, +

[PATCH] improve folding of expressions that move a single bit around

2016-11-26 Thread Paolo Bonzini
In code like the following from KVM: /* it is a read fault? */ error_code = (exit_qualification << 2) & PFERR_FETCH_MASK; it would be nicer to write /* it is a read fault? */ error_code = (exit_qualification & VMX_EPT_READ_FAULT_MASK) ? PFERR_FETCH_MASK : 0;