I am starting to learn about QFT and something that I noticed is that integrals who would diverge otherwise are assigned a value if we do it by contour integration using the residues theorem and the Feynman prescription, e.g.
$$ \begin{alignat}{7} i\int\dfrac{\mathrm{d}^4p}{\left(2\pi\right)^4}\dfrac{1}{p^2-M^2} & ~~=~~ & i & \int \dfrac{\mathrm{d}^3\textbf{p}}{(2\pi)^4} && ~~ \int_{-\infty}^{\infty} \mathrm{d}p^0\dfrac{1}{\left(p^0\right)^2-E^2_{\textbf{p}}} \\ & ~~=~~ & \dfrac{1}{2} &\int \dfrac{\mathrm{d}^3\textbf{p}}{\left(2\pi\right)^3} && ~~ \dfrac{1}{E_{\textbf{p}}}. \end{alignat} $$
The integral at the most right in the first line diverges ($p^0$ is real as is $E_{\textbf{p}}$), but if we use the feynman prescription, i.e., changing the integrand$$ \dfrac{1}{\left(p^0\right)^2-E^2_{\textbf{p}}} ~~ \rightarrow ~~ \dfrac{1}{\left(p^0\right)^2-E^2_{\textbf{p}} + i\epsilon} \,,$$we can evaluate this to a finite value (which was used to go from the first to the second line) using the residues theorem. Incidentally, the integral on the second line still diverges and we need to regularize it.
But my question concerns the first step, why is it valid to assign a value to this integral just by shifting its poles? The integral isn't convergent, when we shift its poles we are evaluating another integral, not the same we started with.