On Thu, Jan 09, 2020 at 02:26:10PM +0100, Richard Biener wrote:
> > 2019-12-11  Wilco Dijkstra  <wdijk...@arm.com>
> >
> >         PR tree-optimization/90838
> >         * tree-ssa-forwprop.c (check_ctz_array): Add new function.
> >         (check_ctz_string): Likewise.
> >         (optimize_count_trailing_zeroes): Likewise.
> >         (simplify_count_trailing_zeroes): Likewise.
> >         (pass_forwprop::execute): Try ctz simplification.
> >         * match.pd: Add matching for ctz idioms.
> >         * testsuite/gcc.target/aarch64/pr90838.c: New test.

This broke build on most targets:
../../gcc/tree-ssa-forwprop.c: In function ‘bool 
simplify_count_trailing_zeroes(gimple_stmt_iterator*)’:
../../gcc/config/i386/i386.h:2886:35: error: cannot convert ‘poly_uint16’ {aka 
‘poly_int<1, short unsigned int>’} to ‘long int’ in assignment
  ((VALUE) = GET_MODE_BITSIZE (MODE), TARGET_BMI ? 1 : 0)
                                   ^
../../gcc/tree-ssa-forwprop.c:1925:22: note: in expansion of macro 
‘CTZ_DEFINED_VALUE_AT_ZERO’
       bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), ctzval) == 2;
                      ^~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:1117: tree-ssa-forwprop.o] Error 1
As elsewhere, C*Z_DEFINED_VALUE_AT_ZERO should be used on scalar_int_mode,
not on machine_mode because then GET_MODE_BITSIZE is poly_int.

Fixed thusly, tested by building x86_64-linux and aarch64-linux (cross in
the latter case) and verifying the testcase on aarch64-linux (and seeing it
is not recognized on x86_64-linux; wonder if we couldn't handle
CTZ_DEFINED_VALUE_AT_ZERO == 1 too by emitting a conditional in gimple or
something similar and waiting for RTL opts to fix it up, but guess it can be
handled incrementally.

Committed to trunk as obvious to unbreak build.

2020-01-10  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/90838
        * tree-ssa-forwprop.c (simplify_count_trailing_zeroes): Use
        SCALAR_INT_TYPE_MODE instead of TYPE_MODE as operand of
        CTZ_DEFINED_VALUE_AT_ZERO.

--- gcc/tree-ssa-forwprop.c.jj  2020-01-10 21:45:46.499607493 +0100
+++ gcc/tree-ssa-forwprop.c     2020-01-10 21:53:37.349640604 +0100
@@ -1922,7 +1922,8 @@ simplify_count_trailing_zeroes (gimple_s
       tree type = TREE_TYPE (res_ops[0]);
       HOST_WIDE_INT ctzval;
       HOST_WIDE_INT type_size = tree_to_shwi (TYPE_SIZE (type));
-      bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), ctzval) == 2;
+      scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
+      bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (mode, ctzval) == 2;
 
       /* Skip if there is no value defined at zero, or if we can't easily
         return the correct value for zero.  */


        Jakub

Reply via email to