The mass loses kinetic energy and gains GPE as it moves from A to B. Let the velocity at the bottom be v1 and the velocity at the top be v2
The change of gpe is U = 2mgr.
The change of KE is U = -1/2 m (v12 - v22)
Equate the two expressions and eliminate the common factor "m" you get:
2gr = -1/2 (v12 - v22)
With a little bit of factorisation you can show that:
v1 - v2 = -4gr / (v1 + v2)