how can it? compiler doesn't know what the code is supposed to do. if compilers will know such things someday, we can stop writing programs altogether, as compilers will be able to write any program for us. ;-)
Correction:
I thought it would be nice if the compiler explained to me that key in aa ? aa[key] is a sub-optimal performance-wise.