[llvm-commits] Possible bug in cost model?

Nadav Rotem nrotem at apple.com
Mon Jan 28 09:33:42 PST 2013


The name type-legalization-cost is misleading. The name should be something like "get number of parts".

The code checks if the number of parts is the same AND the type of part is the same. In that case, bitcasts and truncs are free. 

In the test case you attached the cost of the pointer bitcast operation is changed from zero to one, which is incorrect. Bitcasting pointers from one type to another is really free.

Thanks,
Nadav

On Jan 28, 2013, at 9:14 AM, Renato Golin <renato.golin at linaro.org> wrote:

> Hi Nadav,
> 
> This part of the code seems odd:
> 
>   // Check for NOOP conversions.
>   if (SrcLT.first == DstLT.first &&
>       SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
> 
>       // Bitcast between types that are legalized to the same type are free.
>       if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
>         return 0;
>   }
> 
> It looks as though it's stating that if the legalization of both types is the same, the cost is zero. I'd assume the cost would be the legalization cost.
> 
> It may not matter much on most cases because it's an invariant when all paths have the legalization phase, but if one of the paths can avoid the legalization (by completely removing it), than the benefit won't be accounted for.
> 
> Does it make sense?
> 
> The attached patch "fixes" this (assuming it's wrong) ;)
> 
> cheers,
> --renato
> <cast-cost-bug.patch>




More information about the llvm-commits mailing list