[PATCH] D23940: Delete dead code

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 13:45:37 PDT 2016


> Let me take an example of what I mean:
>
> $ cat foo.cint foo =42;
> int bar();int bar2();
> int main() {
>         return bar() + bar2();
> }
> $ cat bar.c
> extern int foo;
> int locally_defined = 0;
> int bar(){
>         return foo;
> }
> int bar2() {
>         return locally_defined;
> }
>
> clang foo.c -c
> clang bar.c -c -flto
> clang foo.o bar.o
>
> You can see the difference in the codegen for bar and bar2 when I disassemble the binary:
>
> _bar:
> 100000fa0:      55      pushq   %rbp
> 100000fa1:      48 89 e5        movq    %rsp, %rbp
> 100000fa4:      48 8d 05 55 00 00 00    leaq    85(%rip), %rax
> 100000fab:      8b 00   movl    (%rax), %eax
> 100000fad:      5d      popq    %rbp
> 100000fae:      c3      retq
> 100000faf:      90      nop
>
> _bar2:
> 100000fb0:      55      pushq   %rbp
> 100000fb1:      48 89 e5        movq    %rsp, %rbp
> 100000fb4:      31 c0   xorl    %eax, %eax
> 100000fb6:      5d      popq    %rbp
> 100000fb7:      c3      retq

That already works for ELF. shouldAssumeDSOLocal knows that a symbol
in a executable cannot be preempted.

Yes, that is the kind of thing that could be handled uniformly by
having the IR explicitly say what can be assumed to be dso local, but
we don't have that feature yet.

Cheers,
Rafael


More information about the llvm-commits mailing list