i386: Fix wrong codegen for -mrelax-cmpxchg-loop
authorHongyu Wang <hongyu.wang@intel.com>
Thu, 18 Nov 2021 06:45:23 +0000 (14:45 +0800)
committerHongyu Wang <hongyu.wang@intel.com>
Thu, 18 Nov 2021 08:29:19 +0000 (16:29 +0800)
commit15f5e70cbb33b40c97325ef9d55557747a148d39
tree1df1020b51e959c0aa2de8fea18561d3a6161780
parent17da2c7425ea1f5bf417b954f444dbe1f1618a1c
i386: Fix wrong codegen for -mrelax-cmpxchg-loop

For -mrelax-cmpxchg-loop introduced by PR 103069/r12-5265, it would
produce infinite loop. The correct code should be

.L84:
        movl    (%rdi), %ecx
        movl    %eax, %edx
        orl     %esi, %edx
        cmpl    %eax, %ecx
        jne     .L82
        lock cmpxchgl   %edx, (%rdi)
        jne     .L84
movl    %r8d, %eax  <<< retval is missing in previous impl
ret
.L82:
        rep nop
        jmp     .L84

Adjust corresponding expander to fix such issue, and fix runtime test
so the problem would be exposed.

gcc/ChangeLog:

* config/i386/i386-expand.c (ix86_expand_atomic_fetch_op_loop):
Adjust generated cfg to avoid infinite loop.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr103069-2.c: Adjust.
gcc/config/i386/i386-expand.c
gcc/testsuite/gcc.target/i386/pr103069-2.c