[cfe-commits] [llvm-commits] [PATCH] Teach atomicrmw nand to emit *a = ~(*a & b), not *a = ~*a & b
Chandler Carruth
chandlerc at google.com
Fri Apr 13 15:41:53 PDT 2012
Other than the hideously poor code in some of this it looks entirely
correct. LGTM, and *wow* thanks for fixing this.
Can you ensure that the LangRef has the correct spec?
Have you looked at ARM or other platforms? (not saying you have to, just
curious)
On Fri, Apr 13, 2012 at 11:26 PM, Richard Smith <richard at metafoo.co.uk>wrote:
> Hi,
>
> On Fri, Apr 13, 2012 at 1:41 PM, Chris Lattner <clattner at apple.com> wrote:
>
>> On Apr 13, 2012, at 1:20 PM, Richard Smith wrote:
>> > Clang lowers __atomic_fetch_nand(&p, 123, 5) to:
>> >
>> > %0 = atomicrmw nand i32* @p, i32 123 seq_cst
>> >
>> > ... which is documented as performing *x = ~(*x & y) operation, but
>> actually performs *x = ~*x & y (at least on x86):
>>
>> Sounds like a (bad!) codegen bug. It probably dates back to when we did
>> support __sync_fetch_and_nand. I think that GCC 4.4 is old enough that we
>> could add support for __sync_fetch_and_nand in, with the proper semantics
>> (and fix the codegen bug!)
>
>
> The attached patch fixes the codegen bug. With this,
>
> %18 = atomicrmw nand i32* %val2, i32 1401 monotonic
> store i32 %18, i32* %old
>
> generates:
>
> movl $1401, %edx # imm = 0x579
> .align 16, 0x90
> .LBB0_23: # %entry
> # =>This Inner Loop Header: Depth=1
> movl 28(%esp), %ecx
> andl %edx, %ecx
> notl %ecx
> movl %ecx, %eax
> lock
> cmpxchgl %ecx, 28(%esp)
> jne .LBB0_23
> # BB#24: # %entry
> movl %eax, 12(%esp)
>
> and:
>
> %19 = atomicrmw nand i64* %temp64, i64 17361641481138401520 monotonic
> store i64 %19, i64* %temp64
>
> generates:
>
> movl $-252645136, %ebp # imm = 0xFFFFFFFFF0F0F0F0
> movl (%esp), %eax
> movl 4(%esp), %edx
> .align 16, 0x90
> .LBB0_25: # %entry
> # =>This Inner Loop Header: Depth=1
> movl %eax, %esi
> movl %edx, %edi
> movl %esi, %ebx
> andl %ebp, %ebx
> movl %edi, %ecx
> andl %ebp, %ecx
> notl %ebx
> notl %ecx
> lock
> cmpxchg8b (%esp)
> jne .LBB0_25
> # BB#26: # %entry
> movl %edi, 4(%esp)
>
> -- Richard
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120413/db027f09/attachment.html>
More information about the cfe-commits
mailing list