[llvm-dev] Useless exit instruction in "main", replaceable with return inst

David Zarzycki via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 3 10:30:51 PDT 2018


> On Apr 3, 2018, at 12:24, Dávid Bolvanský via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> LLVM optimizer seems to leave "call exit" instruction in "main" function but it could be replaced by a return instruction.
> Any reason why leave it as is or this simple optimization could be implemented e.g. in SimplifyLibCalls?

Hi Dávid,

The C standard forces the dynamic linker to basically invoke main like so “exit(main(argc, argv))”, therefore returning from main isn’t any faster than calling exit() directly. Also, for real world operating systems, the cost of process startup and shutdown overhead is so high that the cycle or two difference is deeply in the noise.

Dave


More information about the llvm-dev mailing list