public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "satzeni at nvidia dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/94366] New: OpenMP Parallel Reduction with "&&" operator does not compute correct result Date: Fri, 27 Mar 2020 18:27:58 +0000 [thread overview] Message-ID: <bug-94366-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94366 Bug ID: 94366 Summary: OpenMP Parallel Reduction with "&&" operator does not compute correct result Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: satzeni at nvidia dot com Target Milestone: --- Created attachment 48137 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48137&action=edit reproducer Consider this program: #include <assert.h> #include <omp.h> #include <stdio.h> static int expect = 1; static int result; int main() { int a = 2; /* or any another even number */ #pragma omp parallel reduction(&& : a) { a = a && 1; } result = a ? 1 : 0; assert(result == 1); } Compiler and run with: $ gcc -fopenmp test.c $ OMP_NUM_THREADS=2 ./a.out GCC is not correctly computing the logical-and reduction on variable "a". Inside the parallel region "a" value is 1, but right after the parallel region is 0 failing the assertion. The correct result should be 1 as the initial value is 2 and the logical-and between 2 && 1 should be non zero. Looking at the assembly code, GCC is using a bitwise “and” instruction to perform the “&&” operation: <main._omp_fn.0+26> mov (%rbx),%edx <main._omp_fn.0+28> jmp 0x400782 <main._omp_fn.0+34> <main._omp_fn.0+30> xchg %ax,%ax <main._omp_fn.0+32> mov %eax,%edx <main._omp_fn.0+34> mov %edx,%ecx <main._omp_fn.0+36> mov %edx,%eax <main._omp_fn.0+38> and $0x1,%ecx <main._omp_fn.0+41> lock cmpxchg %ecx,(%rbx) However the the value of “a” is not reduced to “1” before it is passed to the parallel region. <main+15> movl $0x2,(%rsp) <main+22> callq 0x4005c0 <GOMP_parallel_start@plt>
next reply other threads:[~2020-03-27 18:27 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-27 18:27 satzeni at nvidia dot com [this message] 2021-06-30 7:55 ` [Bug c/94366] " pal0009 at uah dot edu 2021-06-30 10:33 ` [Bug middle-end/94366] " jakub at gcc dot gnu.org 2021-07-01 7:00 ` cvs-commit at gcc dot gnu.org 2021-07-01 7:54 ` jakub at gcc dot gnu.org 2021-07-18 23:29 ` cvs-commit at gcc dot gnu.org 2022-05-10 8:19 ` cvs-commit at gcc dot gnu.org 2022-05-11 6:21 ` cvs-commit at gcc dot gnu.org 2022-05-11 6:33 ` jakub at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94366-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).