Neurons have a wide range of dendritic morphologies the functions of which are largely unknown. We used an optimization procedure to find neuronal morphological structures for two computational tasks: first, neuronal morphologies were selected for linearly summing excitatory synaptic potentials (EPSPs); second, structures were selected that distinguished the temporal order of EPSPs. The solutions resembled the morphology of real neurons. In particular the neurons optimized for linear summation electrotonically separated their synapses, as found in avian nucleus laminaris neurons, and neurons optimized for spike-order detection had primary dendrites of significantly different diameter, as found in the basal and apical dendrites of cortical pyramidal neurons. This similarity makes an experimentally testable prediction of our theoretical approach, which is that pyramidal neurons can act as spike-order detectors for basal and apical inputs. The automated mapping between neuronal function and structure introduced here could allow a large catalog of computational functions to be built indexed by morphological structure.