But the decision by Doug McMillon to speak out against the "religious freedom" bill reflects more than a decade of evolving policy by the retailer on the issue of gay and lesbian rights, and follows a pattern of taking stands on some social issues when it makes business sense to do so.

"Every day, in our stores, we see firsthand the benefits diversity and inclusion have on our associates, customers and communities we serve," McMillon said in a statement on Tuesday asking for a veto of the bill. That was seen as a major factor behind the governor's decision on Wednesday to ask lawmakers in Wal-Mart's home state for revisions.

Wal-Mart's action comes against the backdrop of other major companies taking stands on developing political and social issues, with mixed results.

General Electric Co CEO Jeff Immelt on Wednesday joined a growing chorus of executives expressing concerns about a similar bill seen as possibly discriminatory against gays in Indiana.

Starbucks Corp canceled a program in which baristas were invited to engage customers on conversations about race, making it a cautionary tale for companies looking to wade into potentially controversial issues.

Wal-Mart has been careful in how it tackles issues in the public domain and retains a reputation for conservatism that traces to its origins in a small Arkansas town.

For years it has resisted calls by labor groups to pay a "living wage" and its move in February to increase pay to at least $9 an hour was viewed by many analysts as driven by competition for workers in a tight labor market as much as social concerns. Advocates of the "living wage" want $15 per hour.

PROTECTING THE BUSINESS

One former Wal-Mart executive, who now consults for the company, saw parallels between McMillon's show of support for LGBT rights and a push a decade ago on sustainability under then-Chief Executive Lee Scott.

Scott told people to find ways to use less energy and cut waste but wanted new initiatives to be profitable, the former executive said. Ultimately, the stand on LGBT rights is about protecting the business, said the former executive, who declined to be quoted because of his continuing ties to Wal-Mart.

"It was the smart business thing to do," the consultant said, adding that McMillon's stance should help avoid the business boycotts now threatening Indiana. "But it was also the right thing to do for the associates culturally."

Standing by while its home state was labelled anti-gay could have hindered Wal-Mart’s ability to recruit executives as well as hurt its image generally, argued Deena Fidas, a director at the Human Rights Campaign, which rates companies on their policies toward lesbian, gay, bisexual and transgender workers.

"It comes down to the issue of economics here. No one wants the stain of discrimination on their headquarters state," she said. "In many ways their story is one of leading in some cases and in other cases following industry peers and the trends of the Fortune 500 broadly."

Wal-Mart made its first big step on LGBT policy in 2003 when it added sexual orientation to its equal employment policy. An internal support group, Walmart PRIDE (Promoting Respect, Inclusion, Diversity & Equity) was formed the following year.

But a few years later it pulled its support for the National Gay & Lesbian Chamber of Commerce after conservative groups threatened to boycott its stores, drawing criticism from LGBT groups and illustrating tension over the issue within the company.

CHANGING ATTITUDES

Wal-Mart's shift in stance in many ways reflects changing attitudes in the United States overall. A majority of Americans has supported same-sex marriage for several years, although a substantial minority still opposes it, according to Gallup polls.

While some shoppers have taken to social media to criticize Wal-Mart's stance on the Arkansas bill, many have voiced support and there has been no sign of protest or any other impact on Wal-Mart stores.

In 2011 Wal-Mart added gender identity to its nondiscrimination policy and in 2013 announced it would extend benefits to same-sex partners. On the back of those moves the retailer scored 90 out of 100 in the HRC's latest Corporate Equality Index.

"Wal-Mart has had a vision of where they want to take their LGBT policies over the last decade before we even got in the picture," said Jordan Garcia of the Northwest Arkansas Center for Equality, which was founded on a grant from Wal-Mart in 2006.

"It was just a matter of when was the right time and the right leadership in place."

(Editing by Peter Henderson, Clarence Fernandez and Matthew Lewis)

By Nathan Layne