https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66822

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to H.J. Lu from comment #5)
> X86_TUNE_USE_BT also reduces code size:
> 
> [hjl@gnu-tools-1 pr66822]$ cat y.i
> void bar (void);
> 
> void
> foo (int x)
> {
>   if (x != 2 && x != 3 && x != 10 && x != 11 && x != 17 && x != 18 && x !=
> 23)
>     bar ();
> }
> [hjl@gnu-tools-1 pr66822]$ make y.o
> /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
> -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -m32 -miamcu
> -mtune=iamcu -S -o y.s y.i
> /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
> -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -m32 -miamcu
> -mtune=iamcu -c -o y.o y.s
> rm y.s
> [hjl@gnu-tools-1 pr66822]$ objdump -dwr y.o
> 
> y.o:     file format elf32-i386
> 
> 
> Disassembly of section .text:
> 
> 00000000 <foo>:
>    0: 83 f8 17                cmp    $0x17,%eax
>    3: 76 0b                   jbe    10 <foo+0x10>
>    5: e9 fc ff ff ff          jmp    6 <foo+0x6>      6: R_386_PC32   bar
>    a: 8d b6 00 00 00 00       lea    0x0(%esi),%esi
>   10: ba 0c 0c 86 00          mov    $0x860c0c,%edx
>   15: 88 c1                   mov    %al,%cl
>   17: d3 ea                   shr    %cl,%edx
>   19: 83 e2 01                and    $0x1,%edx
>   1c: 74 e7                   je     5 <foo+0x5>
>   1e: c3                      ret    
> [hjl@gnu-tools-1 pr66822]$ /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
> -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -m32 -miamcu
> -mtune=iamcu -c y.i -mtune-ctrl=use_bt
> [hjl@gnu-tools-1 pr66822]$ objdump -dwr y.o
> 
> y.o:     file format elf32-i386
> 
> 
> Disassembly of section .text:
> 
> 00000000 <foo>:
>    0: 83 f8 17                cmp    $0x17,%eax
>    3: 76 0b                   jbe    10 <foo+0x10>
>    5: e9 fc ff ff ff          jmp    6 <foo+0x6>      6: R_386_PC32   bar
>    a: 8d b6 00 00 00 00       lea    0x0(%esi),%esi
>   10: ba 0c 0c 86 00          mov    $0x860c0c,%edx
>   15: 0f a3 c2                bt     %eax,%edx
>   18: 73 eb                   jae    5 <foo+0x5>
>   1a: c3                      ret    
> [hjl@gnu-tools-1 pr66822]$

We can reduce size further by

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index bca1fee..4f08d0a 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2556,7 +2556,7 @@ static const struct ptt
processor_target_table[PROCESSOR_max] =
   {"i386", &i386_cost, 4, 3, 4, 3, 4},
   {"i486", &i486_cost, 16, 15, 16, 15, 16},
   {"pentium", &pentium_cost, 16, 7, 16, 7, 16},
-  {"iamcu", &iamcu_cost, 16, 7, 16, 7, 16},
+  {"iamcu", &iamcu_cost, 0, 0, 0, 0, 0},
   {"pentiumpro", &pentiumpro_cost, 16, 15, 16, 10, 16},
   {"pentium4", &pentium4_cost, 0, 0, 0, 0, 0},
   {"nocona", &nocona_cost, 0, 0, 0, 0, 0},

and get

00000000 <foo>:
   0:   83 f8 17                cmp    $0x17,%eax
   3:   76 05                   jbe    a <foo+0xa>
   5:   e9 fc ff ff ff          jmp    6 <foo+0x6>      6: R_386_PC32   bar
   a:   ba 0c 0c 86 00          mov    $0x860c0c,%edx
   f:   0f a3 c2                bt     %eax,%edx
  12:   73 f1                   jae    5 <foo+0x5>
  14:   c3                      ret    
[hjl@gnu-tools-1 pr66822]$

Reply via email to