This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR middle-end/18293: Fast-path expand_mult for 2^N


Roger Sayle <roger@eyesopen.com> writes:

> !       /* Special case powers of two.  */
> !       if (EXACT_POWER_OF_2_OR_ZERO_P (coeff))
> !     {
> !       if (coeff == 0)
> !         return const0_rtx;
> !       if (coeff == 1)
> !         return op0;
> !       return expand_shift (LSHIFT_EXPR, mode, op0,
> !                            build_int_cst (NULL_TREE, floor_log2 (coeff)),
> !                            target, unsignedp);
> !     }
>
> !       mult_cost = rtx_cost (gen_rtx_MULT (mode, op0, op1), SET);
> !       if (choose_mult_variant (mode, coeff, &algorithm, &variant,
>                              mult_cost))
> !     return expand_mult_const (mode, op0, coeff, target,
>                                 &algorithm, variant);

Can I suggest instead a structure like this:

   if (coeff == 0)
     return const0_rtx;
   else if (coeff == 1)
     return op0;
   else if (EXACT_POWER_OF_2_OR_ZERO_P (coeff))
     return expand_shift (LSHIFT_EXPR, mode, op0,
                          build_int_cst (NULL_TREE, floor_log2 (coeff)),
                          target, unsignedp);
   else
     {
       mult_cost = rtx_cost (gen_rtx_MULT (mode, op0, op1), SET);
       if (choose_mult_variant (mode, coeff, &algorithm, &variant, mult_cost))
         return expand_mult_const (mode, op0, coeff, target,
                                   &algorithm, variant);
     }

I find this somewhat easier to read, and it is also arguably more
efficient for the *0, *1 cases while being no less efficient for
anything else.

[We do still strength-reduce *2 all the way to x+x, right?]

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]