[Bug target/66822] Turn -mtune=iamcu for size

2015-07-10 Thread ubizjak at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66822

--- Comment #7 from Uroš Bizjak ubizjak at gmail dot com ---
(In reply to Uroš Bizjak from comment #3)
 Please hold a bit with this change, I have a patch that improves generation
 of zero_extend substantially.

Eh, it won't have such drastic effect on code size, so if size is priority,
X86_TUNE_ZERO_EXTEND_WITH_AND should be disabled.

[Bug target/66822] Turn -mtune=iamcu for size

2015-07-09 Thread hjl.tools at gmail dot com
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:
 
  foo:
0: 83 f8 17cmp$0x17,%eax
3: 76 0b   jbe10 foo+0x10
5: e9 fc ff ff ff  jmp6 foo+0x6  6: R_386_PC32   bar
a: 8d b6 00 00 00 00   lea0x0(%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 01and$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:
 
  foo:
0: 83 f8 17cmp$0x17,%eax
3: 76 0b   jbe10 foo+0x10
5: e9 fc ff ff ff  jmp6 foo+0x6  6: R_386_PC32   bar
a: 8d b6 00 00 00 00   lea0x0(%esi),%esi
   10: ba 0c 0c 86 00  mov$0x860c0c,%edx
   15: 0f a3 c2bt %eax,%edx
   18: 73 eb   jae5 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

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

[Bug target/66822] Turn -mtune=iamcu for size

2015-07-09 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66822

--- Comment #5 from H.J. Lu hjl.tools at gmail dot com ---
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:

 foo:
   0:   83 f8 17cmp$0x17,%eax
   3:   76 0b   jbe10 foo+0x10
   5:   e9 fc ff ff ff  jmp6 foo+0x6  6: R_386_PC32   bar
   a:   8d b6 00 00 00 00   lea0x0(%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 01and$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:

 foo:
   0:   83 f8 17cmp$0x17,%eax
   3:   76 0b   jbe10 foo+0x10
   5:   e9 fc ff ff ff  jmp6 foo+0x6  6: R_386_PC32   bar
   a:   8d b6 00 00 00 00   lea0x0(%esi),%esi
  10:   ba 0c 0c 86 00  mov$0x860c0c,%edx
  15:   0f a3 c2bt %eax,%edx
  18:   73 eb   jae5 foo+0x5
  1a:   c3  ret
[hjl@gnu-tools-1 pr66822]$


[Bug target/66822] Turn -mtune=iamcu for size

2015-07-09 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66822

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

Summary|Turn off|Turn -mtune=iamcu for size
   |X86_TUNE_ZERO_EXTEND_WITH_A |
   |ND for -miamcu  |

--- Comment #4 from H.J. Lu hjl.tools at gmail dot com ---
-mtune=iamcu should be tuned for size. X86_TUNE_ZERO_EXTEND_WITH_AND
lead to bigger size:

[hjl@gnu-tools-1 pr66822]$ cat x.i
unsigned int
foo (unsigned short x)
{
  return x;
}
[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 -o x.o x.i -mtune-ctrl=^zero_extend_with_and
[hjl@gnu-tools-1 pr66822]$ objdump -dwr x.o

x.o: file format elf32-i386


Disassembly of section .text:

 foo:
   0:   0f b7 c0movzwl %ax,%eax
   3:   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 -o x.o x.i -mtune-ctrl=zero_extend_with_and
[hjl@gnu-tools-1 pr66822]$ objdump -dwr x.o

x.o: file format elf32-i386


Disassembly of section .text:

 foo:
   0:   25 ff ff 00 00  and$0x,%eax
   5:   c3  ret
[hjl@gnu-tools-1 pr66822]$