Computers are not as intelligent as humans right now at coding. So it's no surprise that they can't improve code (let alone their own).
If we ever get them there, then it's likely that the usual resourcing considerations will come into play, and refactoring/optimization/redesign will be viable if you throw hours at them. But unlike with human optimization, every hour spent there will increase the effectiveness of future optimizations.