From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 657AC385E009; Fri, 27 Mar 2020 18:27:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 657AC385E009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585333678; bh=pE2Rk9OgnN4JThQf4TxnSPp2jWA2p4zIfAOmekwnS+M=; h=From:To:Subject:Date:From; b=UaNNtZ00BX/FcIb3R6DfTZeK2yF2IGR/mFDF8SBn2ja210p1hw7uNA5yZTpvltRbZ uQPf/mVC7g2vLZSGFaOcmjFA0EVSw51TdCIk6IDof1LZYmDoKnaWochHw7lAamPNRI i5C5ZI7FuhJXpbVEBzdS98lYzVvpG2fuTW9RtFzI= From: "satzeni at nvidia dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: satzeni at nvidia dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Mar 2020 18:27:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94366 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=3D48137&action=3Dedit reproducer Consider this program: #include #include #include static int expect =3D 1; static int result; int main() { int a =3D 2; /* or any another even number */ #pragma omp parallel reduction(&& : a) { a =3D a && 1; } result =3D a ? 1 : 0; assert(result =3D=3D 1); } Compiler and run with: $ gcc -fopenmp test.c $ OMP_NUM_THREADS=3D2 ./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 reg= ion is 0 failing the assertion. The correct result should be 1 as the initial v= alue is 2 and the logical-and between 2 && 1 should be non zero. Looking at the assembly code, GCC is using a bitwise =E2=80=9Cand=E2=80=9D = instruction to perform the =E2=80=9C&&=E2=80=9D operation: mov (%rbx),%edx jmp 0x400782 xchg %ax,%ax mov %eax,%edx mov %edx,%ecx mov %edx,%eax and $0x1,%ecx lock cmpxchg %ecx,(%rbx) However the the value of =E2=80=9Ca=E2=80=9D is not reduced to =E2=80=9C1= =E2=80=9D before it is passed to the parallel region. movl $0x2,(%rsp) callq 0x4005c0 =