This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR middle-end/18293: Fast-path expand_mult for 2^N
- From: Zack Weinberg <zack at codesourcery dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 07 Dec 2004 18:11:06 -0800
- Subject: Re: [PATCH] PR middle-end/18293: Fast-path expand_mult for 2^N
- References: <Pine.LNX.4.44.0412071652230.16350-100000@www.eyesopen.com>
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