Some spear formations have no distinct advantage over swordsmen. Thureophoroi is the current name for spear armed hellenistic soldiers in a loose formation like the swordsmen or Rome or Gaul. I can't imagine they had any advantage over the swordsmen (although the longer the weapon the better). Such units are extremely flexible as their formation is easier to command and control, and cohesion is much easier to maintain even while running at speed.
Take the same spearmen and put them in a much tighter formation and you get a spear phalanx. All other things being equal, this formation has a distinct advantage in frontal combat against the last, looser formation, the one used by the Roman swordsmen. In this formation a spear is a lot more effective than a sword because it can be used overhanded. This formation is difficult to control as their is very limited room for movement. So it's more vulnerable to flanking than the pervious formation and cannot flank the enemy as well. The Romans successfully exploited its weaknesses to defeat it again and again, they did not throw their men into a frontal attack against it, that would be suicide. The soldiers fighting it frontally were there to hold it in place, not destroy it, something they were incapable of.
Give the above formation Pikes and they become kings of the battlefield. From the front they can mince both cavalry and infantry. Obviously if they found it hard to move around before, it becomes much harder with hundreds of pikes threading between men and keeping them in place, in addition to countless comrades pressing up all around them. But used in conjunction with effective flank protection, pike phalanxes are the ultimate meleé formation.
However you must remember that it can be effective with other supporting arms in the army. It was adopted again in the late middle ages because the heavy cavalry and men at arms to support its flanks and try to attack the enemy flanks existed. The demise of the hellenistic phalanx is linked to the demise of cavalry and light infantry in hellenistic armies.