Considering the relatively limited context window even on the latest models, the output would likely be incoherent mess. Sure, you could make the LLM go through the code in easily digestible chunks (file by file) but to get any groundbreaking optimization, it would need to have the context of the entire project to properly understand the architecture. (IMO that is, I'm not an expert)