Make sure the CastInst is valid before trying to create it