jump optimizations
commit8227db3a23fd3cf11840eaa25eab5f3f5f813ac7
authorgrischka <grischka>
Sat, 22 Jun 2019 09:45:35 +0000 (22 11:45 +0200)
committergrischka <grischka>
Mon, 24 Jun 2019 09:40:01 +0000 (24 11:40 +0200)
tree22bd73cc5452233ac38bc1277a0d39fb307080a3
parent1b57560502d04cbc2e410a960d965765d7f3d635
jump optimizations

This unifies VT_CMP with VT_JMP(i) by using mostly VT_CMP
with both a positive and a negative jump target list.

Such we can delay putting the non-inverted or inverted jump
until we can see which one is nore suitable (in most cases).

example:
    if (a && b || c && d)
        e = 0;

before this patch:
   a: 8b 45 fc              mov    0xfffffffc(%ebp),%eax
   d: 83 f8 00              cmp    $0x0,%eax
  10: 0f 84 11 00 00 00     je     27 <main+0x27>
  16: 8b 45 f8              mov    0xfffffff8(%ebp),%eax
  19: 83 f8 00              cmp    $0x0,%eax
  1c: 0f 84 05 00 00 00     je     27 <main+0x27>
  22: e9 22 00 00 00        jmp    49 <main+0x49>
  27: 8b 45 f4              mov    0xfffffff4(%ebp),%eax
  2a: 83 f8 00              cmp    $0x0,%eax
  2d: 0f 84 11 00 00 00     je     44 <main+0x44>
  33: 8b 45 f0              mov    0xfffffff0(%ebp),%eax
  36: 83 f8 00              cmp    $0x0,%eax
  39: 0f 84 05 00 00 00     je     44 <main+0x44>
  3f: e9 05 00 00 00        jmp    49 <main+0x49>
  44: e9 08 00 00 00        jmp    51 <main+0x51>
  49: b8 00 00 00 00        mov    $0x0,%eax
  4e: 89 45 ec              mov    %eax,0xffffffec(%ebp)
  51:   ...

with this patch:
   a: 8b 45 fc              mov    0xfffffffc(%ebp),%eax
   d: 83 f8 00              cmp    $0x0,%eax
  10: 0f 84 0c 00 00 00     je     22 <main+0x22>
  16: 8b 45 f8              mov    0xfffffff8(%ebp),%eax
  19: 83 f8 00              cmp    $0x0,%eax
  1c: 0f 85 18 00 00 00     jne    3a <main+0x3a>
  22: 8b 45 f4              mov    0xfffffff4(%ebp),%eax
  25: 83 f8 00              cmp    $0x0,%eax
  28: 0f 84 14 00 00 00     je     42 <main+0x42>
  2e: 8b 45 f0              mov    0xfffffff0(%ebp),%eax
  31: 83 f8 00              cmp    $0x0,%eax
  34: 0f 84 08 00 00 00     je     42 <main+0x42>
  3a: b8 00 00 00 00        mov    $0x0,%eax
  3f: 89 45 ec              mov    %eax,0xffffffec(%ebp)
  42:   ...
Makefile
arm-gen.c
arm64-gen.c
c67-gen.c
i386-gen.c
tcc.h
tccgen.c
tests/tcctest.c
x86_64-gen.c