Smoking cannabis during pregnancy produces infants who score better on one measure of brain development, according to a study of New Zealand children.
Drinking alcohol, however, led to worse scores - and when both drugs were used, they cancelled each other out.
But the optometry and psychology researchers who did the study warn that women should not self-medicate on the strength of their findings because cannabis use in pregnancy is also known to lead to poor outcomes on other measures of brain development.
In the study, 165 children aged 4 and below watched multiple moving dots on a computer screen and were asked to state the main direction in which they were moving. It is a measure of visual discrimination in the brain called global motion perception.
Arijit Chakraborty of Auckland University likened the test to identifying a single moving car at busy intersection.
He and his co-researchers founds the scores were markedly better in those whose mothers used cannabis in pregnancy than in offspring of those who didn't use it in pregnancy. The more frequently the mothers smoked and the larger the quantities, the greater the benefit.
Children of mothers who drank in pregnancy performed worse than those whose mothers did not drink, although none of the children in the study had been diagnosed with fetal alcohol syndrome. The more the mothers drank, the greater the visual impairment. Nicotine and methamphetamine had no effect and none of the four drugs affected other visual measures including visual acuity.
The researchers' paper, published today in the journal Scientific Reports, says that if the cancelling-out they found with alcohol and cannabis can be repeated, this could provide a basis for future research on "new ways to prevent or ameliorate" the ill effects of prenatal drug exposure.
But Mr Chakraborty says women should await the results of scientific study on this rather than undertaking their own experiments at home.
"We are not recommending on the basis of our findings to start smoking marijuana. Previous studies suggest marijuana had some ill effects on other neurodevelopmental domains. One improvement in one particular neurodevelopmental domain does not suggest holistically the brain is performing better."
"We would recommend the mothers to stop drinking in the first place instead of trying marijuana unless subsequent research specifically answers this question."
The researchers say that although prenatal cannabis exposure has not been studied widely, "detrimental effects have been reported for motor and cognitive development. Therefore our results cannot be extrapolated beyond global motion perception or interpreted as marijuana having beneficial effects on fetal development."
"Previous studies have reported that prenatal exposure to heavy marijuana use impairs performance on a range of standardized neuropsychological tests of attention, memory, and executive function that involve a visual component."
Seeking to explain their findings, the researchers say there is some animal and laboratory evidence the chemicals in cannabis can improve movement and that they can help in the formation of nerve and brain cells in neuro-degenerative disorders.
Internationally, numerous other research groups are testing cannabis derivatives for a range disorders, including cancer, multiple sclerosis, HIV and Alzheimer's disease.
Christine Rogan, of the Fetal Alcohol Network, says, "The evidence that alcohol is harmful during pregnancy has been known for an awfully long time but our efforts to prevent drinking in pregnancy have been slow to mature.
"The amount of alcohol that is available in our society means it has been normalised to the extent that women who might not realise they are pregnant are consuming a high amount. We know that of all drugs alcohol appears to be the most harmful; none of them are good."
"This is another piece of the puzzle, that there is no safe amount."