vik, I think the best way to think about the potential for fallacy in the 'grammars perform better' statement is at a pupil by pupil level.
Each pupil at a grammar school that has, say, a Progress8 of 0.5 for 'high attainers' gets, on average, half a GCSE grade better than the average pupil from the broad-brush 'high attaining cohort' nationwide.
However, each high attaining pupil at any OTHER school with a Progress 8 of 0.5 [the vast majority of which are comprehensive] ALSO gets half a grade at GCSE higher than the average pupil from that 'high attaining cohort'.
A grammar school will get better 'raw' results, because it collects together a higher percentage of these higher attaining pupils - but at a pupil by pupil level, each pupil will do exactly as they would at a comprehensive with exactly the same Progress8.
So using the examples that I gave above, in the girls' grammar with 95% high prior attainment, 95% get %+ in Maths & English GCSEs. In the base of Boston High, 5% more reach this benchmark than their % of previous high attainers. on the other hand, a comprehensive with 'only' 40% high attainers gets 77% to this benchmark - so not only gets the 40% high attainers to where they are expected to be, but 37% of other children to.
The first Girls' Grammar gets the higher raw results - but only because of the high prior attainment. The comprehensive would enable those children to get the same results, but also teaches the middle attainers so as to get the results too. Which is, at a pupil by pupil level, performing better? The comp has the best overall progress 8 of the 3, by quite a margin, even including the margins of error in each figure.