Type-Aware Optimizations with Imperfect Types