In manual mode "M", downshifting only occurs if the engine speed threatens to become too low. There is no automatic upshifting in "M" mode; the rider must always shift up themselves.
In automated shift mode "D", downshifts and upshifts are automatic, but the driver can override / manually select the desired gear by operating the gearshift lever.
When riding downhill in manual mode "M", the braking torque/engine speed (throttle grip/brake) is regulated or, in transmission mode "D", the system automatically shifts according to the throttle grip/engine speed depending on the riding mode.
For the best possible utilisation of the engine brake, e.g. when descending mountain passes, it is best to select manual mode "M".
Here you can find out more about the shifting actions and the transmission modes "M" and "D".