Ailing Rafa wins tough tussle against Shapovalov to reach semis