[LLVMdev] code bloat example

Evan Cheng evan.cheng at apple.com
Fri Aug 22 15:07:36 PDT 2008


Can you file a bug? Thanks.

Evan

On Aug 20, 2008, at 10:13 PM, regehr wrote:

> Here's an example where llvm should probably be producing smaller  
> code, its output is 700% larger than gcc.
>
> regehr at john-home:~/volatile/tmp11$ llvm-gcc -Os -w small.c -o  
> small ; size small
>   text	   data	    bss	    dec	    hex	filename
>   6324	    252	      8	   6584	   19b8	small
> regehr at john-home:~/volatile/tmp11$ current-gcc -Os -w small.c -o  
> small ; size small
>   text	   data	    bss	    dec	    hex	filename
>    784	    252	     12	   1048	    418	small
>
> Looks easy to fix: probably at -Os the inliner should not be so  
> aggressive.
>
> John Regehr
> typedef unsigned char uint8_t;
> typedef unsigned short int uint16_t;
> typedef unsigned int uint32_t;
> uint16_t context;
> static uint16_t
> crcByte (uint16_t crc, uint8_t b)
> {
>  uint8_t i;
>  crc = crc ^ b << 1;
>  do
>    if (crc)
>      crc = crc << 0x1021;
>    else
>      crc = crc << 1;
>  while (--i);
>  return crc;
> }
> static void
> crcBytes (uint32_t val)
> {
>  uint8_t *tmp = (uint8_t *) (&val);
>  int len;
>  for (len = 4; len; len--)
>    context = crcByte (context, *tmp++);
> }
>
> int
> main (int argc, char *argv[])
> {
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  crcBytes (1);
>  return 0;
> }
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list