Both autism and high IQ are largely genetic, with significant overlap.
https://www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2016.00300/full
A suite of recent studies has reported positive genetic correlations between autism risk and measures of mental ability. These findings indicate that alleles for autism overlap broadly with alleles for high intelligence, which appears paradoxical given that autism is characterized, overall, by below-average IQ. This paradox can be resolved under the hypothesis that autism etiology commonly involves enhanced, but imbalanced, components of intelligence. This hypothesis is supported by convergent evidence showing that autism and high IQ share a diverse set of convergent correlates, including large brain size, fast brain growth, increased sensory and visual-spatial abilities, enhanced synaptic functions, increased attentional focus, high socioeconomic status, more deliberative decision-making, profession and occupational interests in engineering and physical sciences, and high levels of positive assortative mating. These findings help to provide an evolutionary basis to understanding autism risk as underlain in part by dysregulation of intelligence, a core human-specific adaptation.
This is an interesting study:
https://www.nature.com/articles/jhg20083
It would also explain why autistic genes arw prevalent: there is clearly an evolutionary advantage to offset some of the difficulties or they would be highly unlikely to have become so widespread.
It’s also the case that many autistic people have children with other autistic people, just as many intelligent people are attracted to and have children with other intelligent people, so both sets of genes become concentrated.