Gains from trade are theoretical numbers, based on the shapes of the supply and demand curves. As long as those numbers are positive, trade still happens. When zero, the traders are indifferent to the trade. So when things like monopoly pricing, taxes, and price discrimination com into play, a certain quantity of trade will simply not happen.
That value is not something you can tax directly. It's more like happiness than cash. In the barter, the traders walk away with the same value of goods, but greater happiness. I'm not sure what dollar value the IRS places on happiness, but based on their behavior, I'm pretty sure it is $0 per smile.
Therefore, neither trader in a normal barter should realize a taxable gain.
In barter, both parties believe that the value they walked away with is greater than the value they put into the deal. In principle, that's exactly what the IRS wants to tax. A currency system should generally preclude any barter by assigning reliable values to both parties' goods, such that the one whose stuff is assigned a higher monetary value by the market will be unwilling to make the trade, since they could do better by just selling their stuff and buying the other party's. (A raw trade could still happen where the market value of each party's offering is somewhere within the bid/ask spread of the other's.) But that's independent of what "barter" is. Barter is just trade unmediated by a currency. You can realize taxable gains through barter in just the same way that my uncle once paid his rent for a month by selling an art object he bought at a garage sale for under $100. Despite being mediated by cash, that was a highly uneven trade, and barter is no different.
In a happy coincidence for the IRS, assigning monetary values to everything makes it trivial to assign a value to the trade for the gaining party to pay tax on. Again, not relevant to what barter is.
Given that the IRS can operate under any rules that the government pleases itself to create, regardless of any connection to reality, I don't think anyone there even attempts to discern whether a given rule is actually generating revenue or just fruitlessly destroying commerce.
As you say, anyone with enough cash available would always prefer settling with two trades using money instead of one barter trade. So really, the barter tax is only levied on people who don't have the money to pay it and on tax avoiders. The tax avoiders find another loophole; the poor people remain screwed.
That value is not something you can tax directly. It's more like happiness than cash. In the barter, the traders walk away with the same value of goods, but greater happiness. I'm not sure what dollar value the IRS places on happiness, but based on their behavior, I'm pretty sure it is $0 per smile.
Therefore, neither trader in a normal barter should realize a taxable gain.