Useless exit instruction in "main", replaceable with return inst


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.


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().)