Recommit of r223513 and r223514.

Reviewed at http://reviews.llvm.org/D6488
Recommit of r223513 and r223514.

Reviewed at http://reviews.llvm.org/D6488