[Bug tree-optimization/90838] Detect table-based ctz implementation

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Wed Jun 12 08:42:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838

--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 12 Jun 2019, ktkachov at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838
> 
> --- Comment #5 from ktkachov at gcc dot gnu.org ---
> FWIW, there is another similar function in deepsjeng that computes a
> side-effect:
> int
> myctz2 (unsigned long long * const b) {
>      unsigned long long lsb = (*b) & -(*b);
>     *b ^= lsb;
>     return table[(lsb * magic) >> 58];
> }
> 
> so we'd need to make sure that our solution handles multiple uses of lsb

I'd say we want to start the pattern matching from the table lookup.

I agree match.pd is too expensive unless we have pre-analyzed
initializers in varpool nodes.

Writing the matching of the index as exported (match (...)) function
is still something we can do.  I've for some time wanted the excuse
for somebody to support writing in tree-ssa-math-opts.c for example

/* !start-match
   (match (foo @0 @1)
    (....))
   !end-match */

and a

MATCH_FILES=tree-ssa-math-opts.c

gimple-match-fns.c: MATCH_FILES
        extract-parts.sh MATCH_FILES > temp.pd
        build/genmatch --gimple --export temp.pd > $<

or something along this lines.  You can then do

if (gimple_foo (ssa_op, &op0, &op1, NULL))
  ...

to do the pattern matching.  Currently all (match ..) functions
are exported in gimple-match.c and that could then change
with --export only done to those used from outside match.pd.


More information about the Gcc-bugs mailing list