[llvm-dev] Question on ATOMIC_CMP_SWAP results being sign or zero extended

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 15 10:17:38 PDT 2016


Hi Simon,

On 15 March 2016 at 09:39, Simon Dardis via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Are the results of ATOMIC_CMP_SWAP_WITH_SUCCESS and ATOMIC_CMP_SWAP defined or expected to be zero-extended or sign-extended? Or is it just "do something sensible for your target"?

Interesting. We actually don't seem to do any of the extensions
required for a type-legalized SETCC (particularly truncating "desired"
properly), so it's probably buggy on existing targets too. The output
of

define {i32, i1} @foo(i32* %addr, i32 %l, i32 %r, i32 %new) {
  %desired = add i32 %l, %r
  %res = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
  ret {i32, i1} %res
}

looks very suspicious on PowerPC. It seems entirely reasonable that
which extension is used could be controlled by a callback to
ISelLowering.

Cheers.

Tim.


More information about the llvm-dev mailing list