World number one Rafael Nadal battled back from a set down to overcome 12th seed Milos Raonic and reach the semi-finals of the Sony Open.