[llvm-bugs] [Bug 31614] possible bad code generation

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 12 16:32:28 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31614

Hans Wennborg <hans at chromium.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |ahmed.bougacha at gmail.com
         Resolution|---                         |FIXED

--- Comment #2 from Hans Wennborg <hans at chromium.org> ---
(In reply to comment #1)
> Hans, this looks like PR31367
> (https://llvm.org/bugs/show_bug.cgi?id=31367#c8). What do you think?

Yes, that's exactly it. The bug was introduced in r265636, i.e. llvm 3.9.

My best idea for working around it would be doing the fetch_add operation in a
noinline function :-/

My fix in r291630, which will be in llvm 4, affects the repro like this:

@@ -19,12 +19,13 @@
 _Z13test_functionv:                     # @_Z13test_functionv
        .cfi_startproc
 # BB#0:                                 # %entry
+       movl    $1, %eax
+       lock            xaddq   %rax, foo(%rip)
        testq   %rax, %rax
        setns   %al
-       lock            incq    foo(%rip)
        movl    $value_a, %ecx
        movl    $value_b, %edx
-       cmovgq  %rcx, %rdx
+       cmovnsq %rcx, %rdx
        cmpl    $100, (%rdx)
        je      .LBB1_3
 # BB#1:
@@ -37,11 +38,12 @@
        movl    $foo+16, %eax
        cmovneq %rcx, %rax
        lock            incq    (%rax)
+       movl    $1, %eax
+       lock            xaddq   %rax, foo(%rip)
        testq   %rax, %rax
        setns   %al
-       lock            incq    foo(%rip)
        movl    $value_b, %esi
-       cmovgq  %rdx, %rsi
+       cmovnsq %rdx, %rsi
        cmpl    $100, (%rsi)
        jne     .LBB1_2
 .LBB1_3:                                # %if.end.thread

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170113/17519999/attachment.html>


More information about the llvm-bugs mailing list