Selena Gomez went to rehab ... but NOT for herself.
Selena showed up to provide moral support for her good friend, Demi Lovato ... who has successfully been fighting her addictions for two years.
Demi -- who actually lived in a sober living home for more than a year -- showed up to speak to a recovery group ... something she rarely does, and Selena came along for the ride to support her.
We're told ... Demi spoke to the group for an hour ... telling a pretty inspiring personal survival story.
The "X Factor" judge has publicly acknowledged struggling with anorexia, bulimia and cutting ... stories she recalled in vivid detail. Demi went on to say she wanted to surround herself with positive influences, which is why she chose to live in the facility for an extended period and why she values Selena as a friend.
Props to Selena ... and Demi.