Originally authored by Rui Ueyama. Differential Revision: https://reviews.llvm.org/D53031 llvm-svn: 350464