From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D06C43858D33; Tue, 14 Feb 2023 15:59:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D06C43858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676390379; bh=+tQnnaAt4CWETbZvko1XymCV6v2XVbnS1y19Jjv/o1Q=; h=From:To:Subject:Date:From; b=nqSA6gpL6VWxYa2xM9nxXF9uGa4GTmpzjJDajrjdqzyecFpiR+6TX5eqZPMqMomh6 TW6nvHh4znbp77dxaODrJwDbnEjfPsnmLgSX9VTibmgc53oIKBJJYc/nSGjFd4fYrv nauns2XZrI5o69iM/dUjOO19yhYHQWGf37DQ3sYE= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108787] New: [13 Regression] libsodium miscompilation on power9 starting with r13-2107 Date: Tue, 14 Feb 2023 15:59:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108787 Bug ID: 108787 Summary: [13 Regression] libsodium miscompilation on power9 starting with r13-2107 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- The following testcase is miscompiled with -mcpu=3Dpower9 -mtune=3Dpower9 s= tarting with r13-2107-gdefa08a33672d200edbdd7f87ed7afa442249261 . Doesn't reproduce wit= hout -fPIC though. /* { dg-do run { target int128 } } */ /* { dg-options "-O2" } */ /* { dg-additional-options "-fPIC" { target fpic } } */ typedef unsigned __int128 uint128_t; static inline unsigned long long foo (const unsigned char src[8]) { unsigned long long w; __builtin_memcpy (&w, src, sizeof w); return w; } typedef struct S { unsigned long long r[3], h[3]; unsigned char final; } S; __attribute__((noipa)) static void poly1305_blocks (S *st, const unsigned char *m, unsigned long long bytes) { const unsigned long long hibit =3D st->final ? 0ULL : (1ULL << 40); unsigned long long r0, r1, r2; unsigned long long s1, s2; unsigned long long h0, h1, h2; unsigned long long c; uint128_t d0, d1, d2, d; r0 =3D st->r[0]; r1 =3D st->r[1]; r2 =3D st->r[2]; h0 =3D st->h[0]; h1 =3D st->h[1]; h2 =3D st->h[2]; s1 =3D r1 * (5 << 2); s2 =3D r2 * (5 << 2); while (bytes >=3D 16) { unsigned long long t0, t1; t0 =3D foo (&m[0]); t1 =3D foo (&m[8]); h0 +=3D t0 & 0xfffffffffff; h1 +=3D ((t0 >> 44) | (t1 << 20)) & 0xfffffffffff; h2 +=3D (((t1 >> 24)) & 0x3ffffffffff) | hibit; d0 =3D ((uint128_t) h0 * r0); d =3D ((uint128_t) h1 * s2); d0 +=3D d; d =3D ((uint128_t) h2 * s1); d0 +=3D d; d1 =3D ((uint128_t) h0 * r1); d =3D ((uint128_t) h1 * r0); d1 +=3D d; d =3D ((uint128_t) h2 * s2); d1 +=3D d; d2 =3D ((uint128_t) h0 * r2); d =3D ((uint128_t) h1 * r1); d2 +=3D d; d =3D ((uint128_t) h2 * r0); d2 +=3D d; c =3D (unsigned long long) (d0 >> (44)); h0 =3D (unsigned long long) (d0) & 0xfffffffffff; d1 +=3D c; c =3D (unsigned long long) (d1 >> (44)); h1 =3D (unsigned long long) (d1) & 0xfffffffffff; d2 +=3D c; c =3D (unsigned long long) (d2 >> (42)); h2 =3D (unsigned long long) (d2) & 0x3ffffffffff; h0 +=3D c * 5; c =3D (h0 >> 44); h0 =3D h0 & 0xfffffffffff; h1 +=3D c; m +=3D 16; bytes -=3D 16; } st->h[0] =3D h0; st->h[1] =3D h1; st->h[2] =3D h2; } int main () { if (sizeof (unsigned long long) !=3D 8 || sizeof (uint128_t) !=3D 16) return 0; S st =3D { .r =3D { 0x42c052bac7bULL, 0x7ab6080f47bULL, 0x455e9a405ULL }, .h =3D { 0x3efe88da491ULL, 0xd10577b4a44ULL, 0x3efa677b3dbULL } = }; unsigned long long l[2] =3D { 0, 0x72ULL }; poly1305_blocks (&st, (unsigned char *) &l[0], sizeof (l)); if (st.h[0] !=3D 0xef4cd4260ULL || st.h[1] !=3D 0x5d0e836abb6ULL || st.h[= 2] !=3D 0x171e724427ULL) __builtin_abort (); return 0; }=