I’m not really convinced that this is a good idea in all cases.
Consider this (somewhat artificial) example:
Two roads connected, same tags, not being part of any relation.
Should they really be merged? I don’t think so.