Congress, in another of its ineffable flights of logic, decided in 1978 that the buildings used to raise hogs all across America were no longer buildings but instead were "unitary hog-raising facilities."

The aim was not to burnish the image of the hog business.

The transformation was for tax purposes. "Facilities" are eligible for the investment tax credit; mere buildings are not. Eligibility means, in effect, that the federal government pays 10 percent of the cost of building new pig pens.

Pork producers were delighted with the new tax provision but did not foresee the results. It and other recent forms of tax forgiveness -- Congress in 1981 shortened the depreciation period for such facilities to five from 15 years -- have accelerated a trend that is leading to the demise of the small hog-farming operation.

In the last few years, even as national hog production has gone up, 30 percent of the nation's hog producers have gone out of business. A rush of taxpayer-subsidized expansion into the hog business by nonfarm corporations and investor syndicates raises the prospect of overproduction, price depression and instability for thousands of family farmers who can't compete with factory operations.

Now, as Congress, the administration and farm groups grapple with the spring credit crisis and position themselves to do battle over a new farm bill, there is a grudging, painful recognition in many quarters that agriculture's woes cannot be solved until lawmakers deal with tax policy.

The story of the hog buildings is but one element in a confounding world of federal tax shelters and credits that may have been designed in part to help the farmer as a business person, but which have turned out in many cases to be his own worst enemy.

It also is a contradictory world. Tax programs stimulate production, while farm programs prop up prices, subsidize farmers and pay them not to grow more food. Uncle Sam, for example, will help someone buy a dairy cow that can be rented to a farmer, then will guarantee to buy all the milk that cow turns out.

Evidence mounts that tax policy throws farm production out of sync by bringing in investors who care less about farming than they do about sheltering outside income from taxes. It inflates prices of land. It encourages land and equipment investments that the farmer can't afford or doesn't need.

The effects show up throughout agriculture. Grapes, pork, milk, wheat, corn, avocados and some tree fruits, to name a few, are in overproduction due to tax-beneficial investments by nonfarmers. Lower prices benefit consumers, but devastate legitimate farmers.

"The Internal Revenue Code has more effect on the status of American agriculture than the federal farm programs. No question about it," said Ed Andersen, a dairyman who heads the National Grange, the oldest U.S. farmer organization. "The major reason for overinvestment in agriculture is because of tax shelters." Breaks for the Affluent

Not all of agriculture, however, concurs with the Andersen view -- in part because tax breaks tend to help the affluent most. Farmers with no income to shelter get no benefits; their richer brethren increase their competitive edge by using the shelters and write-offs, which let them get higher prices, or let them get by with lower ones, for their commodities.

Hearings last year, and a study released this year by the Joint Economic Committee of Congress, highlighted facets of the tax code that have an adverse impact on small and medium-sized farms.

According to Sen. James Abdnor (R-S.D.), who was overrun last year when he tried to limit the amount of outside income that could be sheltered in agriculture, "farming of the tax code" by investors seeking tax avoidance will cost the Treasury more than $2.6 billion in revenue between now and 1987.

Putting it another way, the Council of Economic Advisers said last year that tax laws encourage the substitution of capital for labor -- machinery instead of people -- and lead to larger mechanized farms that get bigger tax breaks than the smaller farms. "This creates an incentive for higher-income people to invest in farming," the report said. "In practice, losses from farm operations reduce taxes on other income by more than the total federal tax revenue from farm profits, implying that total farm income for tax purposes is negative."

Hogs are where wise investors shelter their outside money these days, according to Chuck Hassebrook, a tax analyst with the Center for Rural Affairs, a family-farm advocacy group in Walthill, Neb. "The real reason for concern in the hog industry is that between 1980 and 1982, we lost 30 percent of our U.S. pork producers. Many of these were the small or medium-sized farmers who run family operations," he said. "Yet in the past year, we have seen six major corporations announcing expansions that will add 1 million more hogs per year to U.S. production," he said.

At a time when many hog farmers are operating on the margin, the meaning of that is ominous. Standard industry math says that a 1 percent increase in supply creates a 2 percent decrease in price and vice versa. The increase announced by the six big corporate producers translates to a drop of $1.20 per hundredweight -- a drop they can absorb but one that could send many small farmers over the edge.

"The average producer who sells 1,000 hogs per year would lose about $2,400," Hassebrook said. "That would be enough to knock many of these guys out of business . . . . Family farms can compete, given fair rules. But the rules are not fair."

But the hog industry is not at one with Hassebrook. The National Pork Producers Council is divided over the issue of accelerated cost recovery -- a feature of the 1981 tax law that gave farmers or investors a faster write-off of the cost of building hog-breeding facilities, which translates to more tax benefits per hog. Smaller producers end up at a competitive disadvantage.

When the law was passed, the council claimed it as a major legislative victory for hog farmers. Now the council is having second thoughts. Sheltered by Cattle

A similar curiosity occurs in the beef industry, where tax policy makes a major impact on the rancher's ability to compete and stay solvent. Profits have been low for a decade, small farmers who raise cattle are quitting and more than half of the country's cattle now are finished for market in about 400 big feedlots. But the National Cattleman's Association takes no position on the tax breaks that draw outside investors into these feeding operations. NCA says it wants tax reform across the board, not just changes in farm-related taxation.

Cattle feeding, however, is regarded by many experts as the most lucrative tax deferral shelter available -- by putting off and reducing taxation through various accounting and leveraging devices. These advantages make cattle feeding especially appealing to high tax-bracket investors and corporations such as Cargill Inc., the world's largest grain trading firm, which has become one of the country's largest cattle feeders.

Gerald F. Vaughn, an agricultural economist at the University of Delaware, theorizes that many farmers and ranchers see tax shelters as beneficial breaks and don't realize how little they gain from them in comparison to more affluent competitors. "A high-bracket farmer's competitive edge is bid into prices for farmland, equipment, livestock and other assets," he said.

"The result of present tax policies," Vaughn continued, "has been a restructuring of farming toward larger units owned by high-bracket taxpayers. This stimulates investment in added productive capacity so as to benefit from tax shelters. It leads to overproduction and lower farm prices."

None of this is simple, however. And perhaps none of it is so curious or so illustrative of the conflict between tax program and farm program as the case of the milk cow and Uncle Sam's lactic largess.

The federal dairy program guarantees that the government will buy all the milk a farmer can't sell -- more than $6 billion worth in the last three years. Yet federal tax law helps stimulate overproduction by allowing investors to buy cows, write off much of the investment and avoid taxation on other income.

Or take land. Hundreds of thousands of acres of fragile rangeland in the West have been plowed under since 1978 and converted to production of wheat, the country's major surplus crop. The double-dip of tax write-offs along with federal crop subsidies has cut Treasury income, increased farm program costs, intensified soil erosion problems and depressed farmers' prices.

It is even more bizarre in areas such as the delicate Sandhills of Nebraska, where outside investors swarmed in during the 1970s to harvest the tax code. Investment credits, accelerated depreciation rates and reduced capital gains taxes have contibuted to the installation of thousands of center-pivot irrigation systems on highly erosive grazing land to grow corn, another surplus crop. But the investor syndicates, from as far away as Wall Street, get a couple more bites from the apple through tax policy. They and Nebraska farmers can get "conservation" tax credits for leveling the hilly dunes to plant crops, even though erosion actually is increased. And they can take "depletion" allowances for pumping publicly owned irrigation water from the Ogallala Aquifer.

Next: The abandoned land