Integration by parts, the cases when it does not matter what $u$ and $dv$ we choose.

There can't really be any general rule for choosing $u$ and $v$ for integration by parts but there are hierarchies that make sense most of the time. The rule I like to use for choosing $u$ (this is not my rule; it is well documented if you google it) is LIATE (logarithm - inverse trig - algebraic - trig - exponential). That is, if there are logarithms present, you should first try to eliminate them with $u$; next you should look for inverse trig functions, then algebraic functions (polynomials, rational functions) and so forth. My general philosophy is choose $u$ which becomes "better" when you differentiate it. Here by better, I mean something like "more elementary." For example, logarithms and inverse trig functions become algebraic functions when differentiated; polynomials become lower order polynomials when differentiated. This makes these good candidates for $u$. For $dv$, I try to choose something which "doesn't get much worse" when anti-differentiated. This makes trig functions and exponentials good candidates for $dv$ since, upon anti-differentiation they remain trig functions and exponentials (respectively). This sort of thinking explains why we should choose $u = x$ and $dv = \cos(x) dx$ when integrating $$\int x \cos(x) dx.$$ It also explains why the choice is arbitrary for integral like $$\int \cos(ax) e^{bx} dx.$$ Neither of these get better upon differentiation and neither get worse upon anti-differentiation so you just choose one to be $u$ and one to be $dv$, perform IBP twice and arrive at the result; no matter which way you've chosen, you don't do any more or less work.