In my experience AI is pretty good at performance optimizations as long as you know what to ask for.
Can't speak to firmware code or complex cryptography but my hunch is if it's in it's training dataset and you know enough to guide it, it's generally pretty useful.