Hello, Earlier this year, I had a chat with Richard Earnshaw about code size optimizations in GCC. I'm of the opinion that GCC should be able to do better, if a small number of obvious shortcomings would be fixed. There are many passes that matter for code size, which are currently rather impaired (see e.g. the cross jumping bug, PR30905).
One typical code-size optimization that is not implemented very well (IMHO) is code hoisting. I don't know if Richard E. remembers, but I promised to list the issues I knew about. Well then, here we go... I think the most important issue is that code hoisting could be done very efficiently at the tree level, as a pass before the insert phase of GVN-PRE. Dan Berlin had a rough outline of how this would work [1] but nobody has implemented this so far (my bank account number is ... ;-). (Actually, I believe generally the people interested in code size optimizations are not making the most of the opportunities that tree-ssa has opened up, but that's a different issue...) GCC does implement code hoisting for RTL. I compiled a list of issues I know of in the code hoisting implementation in gcse.c. I have filed the issues in a new bug report, see http://gcc.gnu.org/PR33828. An issue I didn't list, is that the implementation apparently lacks good testing coverage. For instance, Richard Sandiford fixed an obvious error in the implementation two years ago (see PR22167), that must have resulted in wrong-code issues ever since the code hoisting pass was contributed in the late '90s. This apparent lack of test coverage is not really surprising, I suppose, because code hoisting is only enabled at -Os for some reason. I guess that some of the issues in my list may have kept bugs like Richard S.'s just hidden. I hope the list is useful for someone who wishes to improve GCC's optimizations for code size. Gr. Steven [1] http://gcc.gnu.org/ml/gcc-patches/2005-12/msg00077.html