As a human, you are not encouraged to eat rocks. Babies are constantly trying, and a condition called pica can compel an adult to eat nonfood objects like rocks and dirt. However, some other animals actually need to swallow rocks in order to digest their food. These little stones even have a name — gastroliths — and their use as digestive tools have a long, illustrious evolutionary history.
Gastroliths — the word literally means "stomach stones" — are most often used by birds and reptiles, but they can also be found in earthworms, some fish, amphibians, seals and toothed whales. The fossil record tells us many herbivorous dinosaurs also ate rocks — paleontologists know when they find the telltale collection of small stones still trapped inside a fossilized ribcage. As far as scientists can tell, the groups of animals that currently use them fit into two categories: animals with gizzards and animals that swim.
A gizzard is a specialized, very muscular stomach attached to the "true stomach." Birds, for instance, don't have teeth like we do, so they swallow little stones, which make their way to the gizzard and help in the grinding of plant material — notoriously hard work, as the cellulose that makes up plant cells is tough and difficult to break down with stomach acids alone. After the gizzard has done its job, the food is passed back into the other stomach to be digested further. In the gizzard, gastroliths often eventually become rounded and smooth, and birds will sometimes regurgitate these, replacing them with sharper stones.
Swimming animals use gastroliths for a different reason — or at least scientists think they do. It's still a bit of a mystery; for a long time, scientists thought animals like seals and alligators swallowed stones in order to regulate their buoyancy in the water — for instance, a sea lion might eat rocks in order to make diving easier. However, this theory would only work if they were swallowing many big, heavy rocks, which they aren't, so the jury is still out on that one. In the past 30 years, other ideas have emerged: maybe animals eat them to alleviate hunger or even as an aid in digesting food, only without the gizzard.
But for the record, it's not a good idea for humans to eat rocks — you don't have the right internal equipment for it.