This is a re-application of r345525, which had been reverted by fear of a regression. Reviewed as https://reviews.llvm.org/D53994. Thanks to Denis Yaroshevskiy for the patch. llvm-svn: 349358