This is an archive of the discontinued LLVM Phabricator instance.

X86: elide comparisons after cmpxchg instructions.
AbandonedPublic

Authored by t.p.northover on Jun 10 2014, 3:05 AM.

Details

Reviewers
None
Summary

The C++ and C semantics of the compare_and_swap operations actually require us to return a boolean "success" value. In LLVM terms this means a second comparison of the output of "cmpxchg" against the input desired value.

However, x86's "cmpxchg" instruction sets all flags for the comparison formed, so we can skip any secondary comparison. (N.b. this isn't true for cmpxchg8b/16b, which only set ZF -- I'm hoping to deal with them in a separate patch later).

A bit of refactoring was needed, but there should be no actual changes to the LowerCMP_SWAP function.

OK to commit?

Cheers.

Tim.

Diff Detail

Event Timeline

t.p.northover retitled this revision from to X86: elide comparisons after cmpxchg instructions..
t.p.northover updated this object.
t.p.northover edited the test plan for this revision. (Show Details)
t.p.northover added a subscriber: Unknown Object (MLST).

I've found an issue with PHIs using this patch causing an assertion failure, so it looks like it's not quite ready for review after all. I'll fix it and update.

Cheers.

Tim.

The problem was X86ISD::BRCOND getting a stale chain after the original, unlowered cmpxchg had been replaced. I thought the correct value could be reliably inferred from the "Cmp", but that's not actually true in general so we need to save the chain slightly later in the function.

t.p.northover abandoned this revision.Jun 12 2014, 12:09 AM

I'm abandoning this for now. It's occurred to me that the solution could look very different after weak cmpxchg is implemented. Wish I'd thought of that before I spent a couple of days working on this approach. Oh well.

Tim.