Dávid Bolvanský via llvm-dev
2018-Apr-03 16:24 UTC
[llvm-dev] Useless exit instruction in "main", replaceable with return inst
Hi, 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? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180403/01d88af9/attachment.html>
David Zarzycki via llvm-dev
2018-Apr-03 17:30 UTC
[llvm-dev] Useless exit instruction in "main", replaceable with return inst
> 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
Friedman, Eli via llvm-dev
2018-Apr-03 17:31 UTC
[llvm-dev] Useless exit instruction in "main", replaceable with return inst
On 4/3/2018 9:24 AM, Dávid Bolvanský via llvm-dev wrote:> Hi, > > 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?The usual answer to this sort of question is "nobody has implemented it yet". And frankly, it's not really worth implementing; a minor size reduction on a cold path in main() has very little benefit. (And strictly speaking, C allows programs to recursively call main().) -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project