Apple has this in the form of a poorly-marketed feature called iTunes Match ($25/year). https://support.apple.com/en-us/108935
I no longer subscribe to Apple Music, but I have 169.5 days of purchased music that I can stream anywhere. Tracks that exactly match an entry in their catalog are presumably just represented as a pointer, and tracks which aren't available in Apple Music are uploaded.