U.S. companies emerged last week as among the most outspoken — and effective — adversaries of state legislation they contended would sanction discrimination against gays.

Pressure from Wal-Mart Stores Inc., Apple Inc., General Electric Co. and others persuaded Indiana lawmakers to amend a religious-freedom law and Arkansas Gov. Asa Hutchinson to demand changes to a bill legislators sent him. Opposition from companies also may be slowing the momentum in other states that are considering what critics decry as anti-gay measures disguised as protecting religious liberty.

For companies, defending gay rights is good for business. "Large multistate employees have to hire and attract and retain people from all walks of life," said Bob Witeck, a consultant whose clients include Wal-Mart and Citigroup Inc.

Employers don't want rules in some states that would make it hard to relocate talented people. And executives don't want their states to be on the wrong side of history — or subjected to boycotts and negative publicity — as public opinion is increasingly shifting in favor of gay rights.

"It's just bad for their business," said Gary Gates, research director at the UCLA School of Law's Williams Institute. A patchwork of state policies means "their policies must be potentially different depending on the location. That all costs money."

That's one reason, he said, that companies have been "so far ahead of the public and government" on gay-rights issues.

Before polls showed Americans supported the idea, companies such as the Walt Disney Co. gave employees' same-sex partners the health, pension and other benefits that their spouses had.

Goldman Sachs Group Inc. and Microsoft Corp. were among the hundreds of companies that signed a brief urging the U.S. Supreme Court to strike down the Defense of Marriage Act; the court overturned the federal law in 2013.

In Arkansas, Wal-Mart Chief Executive Officer Doug McMillon asked the governor to veto the religious freedom act that passed last Wednesday, saying it threatened "to undermine the spirit of inclusion present through the state."

"Every day, in our stores, we see firsthand the benefits diversity and inclusion have on our associates, customers and communities we serve," McMillon said on the company's Twitter account. Wal-Mart, based in Bentonville, Ark., has 2.2 million employees.

Hutchinson, a Republican, said he wouldn't sign the original bill. "We want to be known as a state that does not discriminate but understands tolerance," he said. He did sign a revised version.

GE CEO Jeffrey Immelt urged Indiana lawmakers to amend that state's religious freedom law, which like the one in Arkansas prevented government from infringing on religious beliefs.

"We have zero tolerance for discrimination of any kind," Immelt said in an open letter to Indiana Gov. Mike Pence, a Republican. GE employs 1,500 people in Indiana.