From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4E67D3877034; Mon, 27 Sep 2021 00:52:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E67D3877034 From: "gabravier at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102494] New: Failure to optimize out vector reduction properly especially when using OpenMP Date: Mon, 27 Sep 2021 00:52:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gabravier at gmail 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 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: Mon, 27 Sep 2021 00:52:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102494 Bug ID: 102494 Summary: Failure to optimize out vector reduction properly especially when using OpenMP Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- #include #include typedef int8_t simde_int8x8_t __attribute__((__vector_size__(8))); int16_t simde_vaddlv_s8(simde_int8x8_t a) { int16_t r =3D 0; #pragma omp simd reduction(+:r) for (size_t i =3D 0 ; i < (sizeof(a) / sizeof(a[0])) ; i++) { r +=3D a[i]; } return r; } Compiled with -O3 -fopenmp-simd, this is the output on AMD64: simde_vaddlv_s8(signed char __vector(8)): pxor xmm1, xmm1 movdqa xmm2, xmm0 pcmpgtb xmm1, xmm0 punpcklbw xmm0, xmm1 punpcklbw xmm2, xmm1 pshufd xmm0, xmm0, 78 movq QWORD PTR [rsp-24], xmm2 movq QWORD PTR [rsp-16], xmm0 movdqa xmm0, XMMWORD PTR [rsp-24] psrldq xmm0, 8 paddw xmm0, XMMWORD PTR [rsp-24] movdqa xmm1, xmm0 psrldq xmm1, 4 paddw xmm0, xmm1 movdqa xmm1, xmm0 psrldq xmm1, 2 paddw xmm0, xmm1 pextrw eax, xmm0, 0 ret This is what Clang manages: simde_vaddlv_s8(signed char __vector(8)): punpcklbw xmm0, xmm0 # xmm0 =3D xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7] psraw xmm0, 8 pshufd xmm1, xmm0, 238 # xmm1 =3D xmm0[2,3,2,3] paddw xmm1, xmm0 pshufd xmm0, xmm1, 85 # xmm0 =3D xmm1[1,1,1,1] paddw xmm0, xmm1 movdqa xmm1, xmm0 psrld xmm1, 16 paddw xmm1, xmm0 movd eax, xmm1 ret Weirdly enough, removing the `#pragma omp simd reduction(+r)` slightly impr= oves GCC's output to this: simde_vaddlv_s8(signed char __vector(8)): pxor xmm1, xmm1 movdqa xmm2, xmm0 pcmpgtb xmm1, xmm0 punpcklbw xmm0, xmm1 punpcklbw xmm2, xmm1 pshufd xmm0, xmm0, 78 paddw xmm0, xmm2 pextrw edx, xmm0, 1 pextrw eax, xmm0, 0 add eax, edx pextrw edx, xmm0, 2 add eax, edx pextrw edx, xmm0, 3 add eax, edx ret=