Re-commit of r144034, with an extra fix so that RemoveDeadNode doesn't blow up. llvm-svn: 144055
llvm-svn: 144044
llvm-svn: 144034