From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9A7A83853D7F; Wed, 23 Nov 2022 15:04:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A7A83853D7F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669215880; bh=ooCxqpleXomf7/H2CVwYf0KzKXY7nRj7WW9JYFCQ5G0=; h=From:To:Subject:Date:From; b=f3fj+QprydxiDnbVXnhP+QZ/nQAeHpuJj2Iq7uiMLSH/vpGk9Gn8hHAGFYuFFyvWG 9hKBS+nKq6r9bq3T5cd6MH2GzGgeQHalGb/fD44i85Fj71Z3o/738A/H39bL1FOaFB DzSsaUj3VabB1Jc+qTQ8sS3TrBT0w7Rq8JaXUYyE= From: "czx211355007 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107836] New: x86_64 inline functions -O2/-O3 optimization error Date: Wed, 23 Nov 2022 15:04:39 +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: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: czx211355007 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 cf_gcctarget 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107836 Bug ID: 107836 Summary: x86_64 inline functions -O2/-O3 optimization error Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: czx211355007 at gmail dot com Target Milestone: --- Target: x86_64-linux-gnu Created attachment 53952 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53952&action=3Dedit full assembly for function "matrix_mul" When compiling the following two functions with -O2 or -O3 options, the assembly code generated is wrong. int dot_product(short* a, short* b, int len){ int result; asm("pandn %%mm5,%%mm5;"::);=20=20=20 for(int i=3D0; i < len; i +=3D 4){ asm( "movq %0,%%mm0;" "movq %1,%%mm1;" "pmaddwd %%mm1,%%mm0;" "paddd %%mm0,%%mm5;"=20=20=20=20=20=20=20=20=20=20 :=20=20 : "m" (a[i]), "m" (b[i]) ); } asm("movq %%mm5, %%mm0;" "psrlq $32,%%mm5;" "paddd %%mm0, %%mm5;" "movd %%mm5,%0;" "emms" :"=3Dr" (result) :); return result; } } void matrix_mul(int d, short a[d][d], short b[d][d], int c[d][d]){ for(int i=3D0;i