What is the connection between this Pasuk and the previous one?
Seforno (cont.): ... and it was by the grace of Hashem that Avraham defeated his enemies. That was the current Berachah that Avraham received from Hashem, to which Shem referred. 1
Because when the Resha'im fall into the hands of the Tzadikim there is great joy.
Who gave Ma'aser to whom?
Rashi: Avraham gave to Shem.
Riva: Alternatively, Shem gave to Avraham, for Hashem deposed Shem from being a Kohen. 1
Rashi holds that Kehunah was taken from Shem's children, but not from Shem.
How could Avraham give "Ma'aser of all" to Shem? He did not keep any of the spoils!
Riva (1), Moshav Zekenim (verse 23): Really, everything belonged to Avraham, like one who saves from bandits. A Chaver (one who meticulously fulfills Ma'aser) may not let matters leave his Reshus without tithing them.
Riva (2): Rashi explained that he gave Ma'aser "from all his [property]", i.e. but not from the spoils. He intended only to return the spoils to the owners; he never acquired them. Even a Chaver need not tithe in such a case.
רש"י: ויתן לו- אברם: אולי מלכי צדק הוא זה שנתן?
גור אריה: כיוון שמלכי צדק היה הכהן, בודאי אברהם הוא זה שנתן לו.
רש"י: מכל אשר לו: אולי נתן רק ממה ששבה?
גור אריה: כיון שאברהם לא רצה לקחת מהשבי, אין לו לתרום מדבר שאינו שלו.