Re: [PATCH] Further bootstrap unbreak (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-13 Thread Wilco Dijkstra
Hi Jakub, On Sat, Jan 11, 2020 at 05:30:52PM +0100, Jakub Jelinek wrote: > On Sat, Jan 11, 2020 at 05:24:19PM +0100, Andreas Schwab wrote: > > ../../gcc/tree-ssa-forwprop.c: In function 'bool > > simplify_count_trailing_zeroes(gimple_stmt_iterator*)': > > ../../gcc/tree-ssa-forwprop.c:1925:23: er

Re: [PATCH] Further bootstrap unbreak (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-13 Thread Richard Biener
On Mon, 13 Jan 2020, Jakub Jelinek wrote: > On Sat, Jan 11, 2020 at 05:30:52PM +0100, Jakub Jelinek wrote: > > On Sat, Jan 11, 2020 at 05:24:19PM +0100, Andreas Schwab wrote: > > > ../../gcc/tree-ssa-forwprop.c: In function 'bool > > > simplify_count_trailing_zeroes(gimple_stmt_iterator*)': > > >

[PATCH] Further bootstrap unbreak (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-13 Thread Jakub Jelinek
On Sat, Jan 11, 2020 at 05:30:52PM +0100, Jakub Jelinek wrote: > On Sat, Jan 11, 2020 at 05:24:19PM +0100, Andreas Schwab wrote: > > ../../gcc/tree-ssa-forwprop.c: In function 'bool > > simplify_count_trailing_zeroes(gimple_stmt_iterator*)': > > ../../gcc/tree-ssa-forwprop.c:1925:23: error: variab

Re: [PATCH] PR90838: Support ctz idioms

2020-01-11 Thread Segher Boessenkool
Hi! On Fri, Jan 10, 2020 at 10:35:04PM +0100, Jakub Jelinek wrote: > On Thu, Jan 09, 2020 at 02:26:10PM +0100, Richard Biener wrote: > > > >> + tree lhs = gimple_assign_lhs (stmt); > > > >> + bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), > > > >> val); > > > > > > > > sinc

Re: [committed] Unbreak bootstrap on most targets (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-11 Thread Jakub Jelinek
On Sat, Jan 11, 2020 at 05:24:19PM +0100, Andreas Schwab wrote: > ../../gcc/tree-ssa-forwprop.c: In function 'bool > simplify_count_trailing_zeroes(gimple_stmt_iterator*)': > ../../gcc/tree-ssa-forwprop.c:1925:23: error: variable 'mode' set but not > used [-Werror=unused-but-set-variable] > 1925

Re: [committed] Unbreak bootstrap on most targets (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-11 Thread Andreas Schwab
../../gcc/tree-ssa-forwprop.c: In function 'bool simplify_count_trailing_zeroes(gimple_stmt_iterator*)': ../../gcc/tree-ssa-forwprop.c:1925:23: error: variable 'mode' set but not used [-Werror=unused-but-set-variable] 1925 | scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type); |

Re: [PATCH] PR90838: Support ctz idioms

2020-01-10 Thread Jakub Jelinek
On Thu, Jan 09, 2020 at 02:26:10PM +0100, Richard Biener wrote: > > >> + tree lhs = gimple_assign_lhs (stmt); > > >> + bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), val); > > > > > > since we're using the optab entry shouldn't you check for == 2 here? > > > > Yes, that looks

[committed] Unbreak bootstrap on most targets (was Re: [PATCH] PR90838: Support ctz idioms)

2020-01-10 Thread Jakub Jelinek
On Thu, Jan 09, 2020 at 02:26:10PM +0100, Richard Biener wrote: > > 2019-12-11 Wilco Dijkstra > > > > PR tree-optimization/90838 > > * tree-ssa-forwprop.c (check_ctz_array): Add new function. > > (check_ctz_string): Likewise. > > (optimize_count_trailing_zeroes):

Re: [PATCH] PR90838: Support ctz idioms

2020-01-09 Thread Richard Biener
On Wed, Dec 11, 2019 at 5:55 PM Wilco Dijkstra wrote: > > Hi Richard, > > >> +(match (ctz_table_index @1 @2 @3) > >> + (rshift (mult (bit_and (negate @1) @1) INTEGER_CST@2) INTEGER_CST@3)) > > > > You need a :c on the bit_and > > Fixed. > > > + unsigned HOST_WIDE_INT val = tree_to_uhwi (mulc); >

Re: [PATCH] PR90838: Support ctz idioms

2019-12-11 Thread Wilco Dijkstra
Hi Richard, >> +(match (ctz_table_index @1 @2 @3) >> +  (rshift (mult (bit_and (negate @1) @1) INTEGER_CST@2) INTEGER_CST@3)) > > You need a :c on the bit_and Fixed. > +  unsigned HOST_WIDE_INT val = tree_to_uhwi (mulc); > +  unsigned shiftval = tree_to_uhwi (tshift); > +  unsigned input_bits =

Re: [PATCH] PR90838: Support ctz idioms

2019-11-29 Thread Richard Biener
On Fri, Nov 15, 2019 at 4:24 PM Wilco Dijkstra wrote: > > Hi Richard, > > > Uh. Well. I think that the gimple-match-head.c hunk isn't something we > > want. Instead, > > since this optimizes a memory access, the handling should move > > to tree-ssa-forwprop.c where you _may_ use a (match ...)

Re: [PATCH] PR90838: Support ctz idioms

2019-11-28 Thread Wilco Dijkstra
ping Hi Richard, > Uh. Well. I think that the gimple-match-head.c hunk isn't something we > want. Instead, > since this optimizes a memory access, the handling should move > to tree-ssa-forwprop.c where you _may_ use a (match ...) > match.pd pattern to do the (rshift (mult (bit_and (negate @1

Re: [PATCH] PR90838: Support ctz idioms

2019-11-15 Thread Wilco Dijkstra
Hi Richard, > Uh.  Well.  I think that the gimple-match-head.c hunk isn't something we > want.  Instead, > since this optimizes a memory access, the handling should move > to tree-ssa-forwprop.c where you _may_ use a (match ...) > match.pd pattern to do the (rshift (mult (bit_and (negate @1) @1)

Re: [PATCH] PR90838: Support ctz idioms

2019-11-13 Thread Richard Biener
On Tue, Nov 12, 2019 at 3:36 PM Wilco Dijkstra wrote: > > Hi, > > Support common idioms for count trailing zeroes using an array lookup. > The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic > constant which when multiplied by a power of 2 contains a unique value > in the top 5

Re: [PATCH] PR90838: Support ctz idioms

2019-11-13 Thread Wilco Dijkstra
Hi Segher, > Out of interest, what uses this? I have never seen it before. It's used in sjeng in SPEC and gives a 2% speedup on Cortex-A57. Tricks like this used to be very common 20 years ago since a loop or binary search is way too slow and few CPUs supported fast clz/ctz instructions. It's o

Re: [PATCH] PR90838: Support ctz idioms

2019-11-13 Thread Segher Boessenkool
Hi! On Tue, Nov 12, 2019 at 02:35:54PM +, Wilco Dijkstra wrote: > Support common idioms for count trailing zeroes using an array lookup. > The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic > constant which when multiplied by a power of 2 contains a unique value > in the t