Daniel Jacobowitz <[email protected]> writes:
> On Wed, Feb 03, 2010 at 06:23:19AM -0800, Ian Lance Taylor wrote:
>> fanqifei <[email protected]> writes:
>>
>> > According to the internal manual, insn length attribute can be used to
>> > to calculate the length of emitted code chunks when verifying branch
>> > distances.
>> > Can it be used in code size optimization?
>>
>> I suppose it could, but it isn't. Instead of asking the backend for
>> the length of instructions, the compiler asks the backend for the cost
>> of instructions. The backend is free to determine that cost however
>> it likes. When using -Os, using the size of the instruction is a good
>> measure of cost.
>
> It seems to me that there's a hard ordering problem here: we can't
> determine insn lengths, using the current framework, until very late.
> We need at least (A) whole instructions, not just RTL expressions; (B)
> register allocation to select alternatives; (C) branch shortening to
> determine branch alternatives.
>
> I'm curious if anyone thinks there's a generic solution to this (that
> doesn't involve a complete instruction selection rewrite :-).
Yeah, it's something I've often wanted too, since at the moment you end
up duplicating a lot of the instruction selection in C code. E.g. the
MIPS port has stuff like:
if (float_mode_p
&& (ISA_HAS_NMADD4_NMSUB4 (mode) || ISA_HAS_NMADD3_NMSUB3 (mode))
&& TARGET_FUSED_MADD
&& !HONOR_NANS (mode)
&& !HONOR_SIGNED_ZEROS (mode))
{
/* See if we can use NMADD or NMSUB. See mips.md for the
associated patterns. */
rtx op0 = XEXP (x, 0);
rtx op1 = XEXP (x, 1);
if (GET_CODE (op0) == MULT && GET_CODE (XEXP (op0, 0)) == NEG)
{
*total = (mips_fp_mult_cost (mode)
+ rtx_cost (XEXP (XEXP (op0, 0), 0), SET, speed)
+ rtx_cost (XEXP (op0, 1), SET, speed)
+ rtx_cost (op1, SET, speed));
return true;
}
if (GET_CODE (op1) == MULT)
{
*total = (mips_fp_mult_cost (mode)
+ rtx_cost (op0, SET, speed)
+ rtx_cost (XEXP (op1, 0), SET, speed)
+ rtx_cost (XEXP (op1, 1), SET, speed));
return true;
}
}
Ugh!
But I could never see a cure that was better than the disease without
(as you say) a rewrite. I think (A) is the main problem: we already
have code to estimate constraints selection before reload, so we could
at least guess at (B) and (C). (Which is what the costs have to do
anyway really.)
Richard