For what type of process can we use $dQ=TdS$? For what type of process can we use $dQ =TdS$? A reversible or irreversible one?
If only for reversible processes, how do we replace $dQ$ in $dQ=dU + PdV$ by $TdS$?
 A: Assume our system only interacts with the environment via heat transfer and mechanical work changing its volume.
For any process, we then have
$$
\Delta U = Q + W
$$
ie the change in energy of the system is given by the sum of heat energy flowing into the system and compression work performed on the system. That's just conservation of energy.
If we analyze the process infinitesimally, this reads
$$
dU = \delta Q + \delta W
$$
State functions such as $U$ normally are only defined in equilibrium, implying a quasi-static process, but given that $U$ is nothing but total energy, this relation could be argued to hold universally.
But if the process actually is quasi-static, we also have
$$
dU = TdS - PdV
$$
which relates infinitesimally neighbouring equilibrium states, no matter if the transition happens reversibly or irreversibly.
Now, one might assume that
$$
\delta Q = TdS \qquad\qquad \delta W = -PdV
$$
but this only holds for reversible processes. It is entirely possible that $dS\not= \delta Q/T$ if there's entropy production within our system (eg via friction). In that case,
$$
\delta Q \lt TdS
$$
which then implies
$$
\delta W \gt -PdV
$$
This last relation might seem paradoxical at first until you realize that static pressure cannot account for velocity-dependent effects, for one.
A: The equation $$dU=TdS-PdV$$ applies to the differential change in U between two closely neighboring thermodynamic equilibrium states, one at (S,V) and the other at (S+dS,V+dV).  The details of the process, no matter how convoluted and/or irreversible, are irrelevant, provided only that it starts at (S,V) and ends at (S+dS,V+dV).  For example, it could involve a large excursion away from the initial state as long as, in the end, it returns to the closely neighboring final state. The relationship is true for all paths because we can easily identify at least one reversible path that satisfies the equation.  For all the reversible paths, no matter how convoluted, we also have that $\Delta S=\int{dq/T}$.
