Many U.S. multinational corporations, including Microsoft and Hewlett-Packard, have exploited weaknesses in the tax code to avoid paying billions of dollars in taxes on overseas profits, said a Senate subcommittee report released Thursday.

The Committee on Homeland Security and Governmental Affairs’ permanent subcommittee on investigations found that from 2009 to 2011, Microsoft was able to save up to $4.5 billion in taxes by transferring some of its intellectual property rights to a Puerto Rican subsidiary.

A memo by the subcommittee also described how ­Hewlett-Packard used billions of dollars of internal loans to duck taxes on foreign profits it was using to fund U.S. operations.

The actions of these companies aren’t illegal, said Sen. Carl Levin (D-Mich.), subcommittee chairman. But he said the strategies qualify as “gimmicks” that should not be allowed in the tax code.

At the subcommittee’s hearing Thursday, executives from Microsoft and Hewlett-Packard defended their firms as acting well within U.S. and foreign tax laws. Officials added that the U.S. code needed to be simplified in order for companies to compete abroad.

“Microsoft has a complex business and we must comply with the complicated tax code of the United States, resulting in an exceedingly complex tax structure,” the company said in a statement. “That is why we’ve advocated for reforms to simplify the U.S. tax code and make it more competitive with the rest of the world.”

As U.S. companies have become more globalized, they have accumulated cash abroad from their foreign operations. If that money were brought back to the United States, it would be taxed at the statutory corporate tax rate of 35 percent.

Some firms have argued that they should be allowed to bring back some of that money at a lower tax rate. Such a move, they say, could help revitalize the U.S. economy.

But the subcommittee’s memo suggests that some companies have for years been bringing that money back to the United States through convoluted methods that allow them to avoid paying taxes.

The subcommittee subpoenaed companies to obtain internal documents that offered a window into their tax strategies.

Hewlett-Packard, the subcommittee found, used loan funding from two offshore entities under the company’s control: one in Belgium and another in the Cayman Islands.

“This loan program, from at least 2008, appears to have been used as a way to de facto repatriate billions of dollars each year to the United States to fund most of H.P.’s U.S. operations,” the memo said.

The subcommittee also found that Hewlett-Packard relied on these internal loans to fund “essential” U.S. operations.

“HP has always had an extremely productive and professional relationship with the IRS, who has permanent offices at two of our facilities and has been continually auditing HP since the filing of our 1962 tax return,” said a spokesman for the company. “They have never raised any concerns about these programs. We are disappointed to see what appears to be a politically motivated attack on one of America’s largest employers.”

The subcommittee report also outlined how easily technology companies can shift intellectual property rights to foreign subsidiaries in countries with low tax rates.

While the U.S. statutory corporate tax rate is relatively high compared with those of other developed economies, the percentage of revenue coming from corporate tax receipts has steadily diminished since the 1950s. Corporate taxes currently account for 9 percent of federal tax revenue, compared with 41 percent from individual income taxes and 40 percent from payroll taxes.