[LLVMdev] RFC: add "cmpxchg weak" to LLVM IR

Tim Northover
2014-06-12T17:57:19Z

>> 1. All cmpxchg instructions now return { iN, i1 } where the first
>> value is what we got before (the loaded result), the second == 1 if an
>> exchange took place.
>
> Having to do extractvalue to get stuff out of these kinds of aggregates
> is... somewhat horrible... have you thought of any alternatives?

Well, sort of. There was that LL/SC thing from the other week, which
could be made the canonical form of a weak cmpxchg (perhaps with an
IRBuilder helper or something). But David's concerns about the
"cmpxchg weak" -> LL/SC transformation being much easier than the
reverse seem quite valid. I'm not sure even I want that any more.

But within a single instruction, we've got two values to produce. If
they're both part of the return then this is about the only option
(that I'm aware of, anyway). If one's part of an input then it'd
have
to be a pointer like in the C++ interface; that would be horrific for
CodeGen, it's just not what actually happens in any architecture I'm
aware of.

Did you have anything in mind?

Cheers.

Tim.