[PATCH] D23940: Delete dead code
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 26 15:41:28 PDT 2016
> On Aug 26, 2016, at 1:45 PM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
>
>> 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.
Right, my idea was to do something like adding “visibility hidden” on *declarations* when we have this passed-in by the linker, and update shouldAssumeDSOLocal to look for this.
—
Mehdi
More information about the llvm-commits
mailing list