From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CBC3B3857357; Thu, 23 Jun 2022 23:13:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBC3B3857357 From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106069] New: wrong code with -O -fno-tree-forwprop -maltivec on ppc64le Date: Thu, 23 Jun 2022 23:13: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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek 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 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: Thu, 23 Jun 2022 23:13:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106069 Bug ID: 106069 Summary: wrong code with -O -fno-tree-forwprop -maltivec on ppc64le Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: mpolacek at gcc dot gnu.org Target Milestone: --- The following test crashes at runtime since r12-4496-g0910c516a3d72a. $ ./cc1plus.r12-4495 -quiet -O -fno-tree-forwprop -maltivec q.C; g++ q.s; ./a.out $ ./cc1plus.r12-4496 -quiet -O -fno-tree-forwprop -maltivec q.C; g++ q.s; ./a.out=20 Aborted Target: powerpc64le-unknown-linux-gnu Configured with: /home/polacek/src/gcc/configure --enable-languages=3Dc,c++ --enable-checking=3Dyes -with-system-zlib --disable-bootstrap --disable-lib= vtv --disable-libitm --disable-libsanitizer gcc version 13.0.0 20220622 (experimental) (GCC) extern "C" void *memcpy(void *, const void *, unsigned long); typedef __attribute__((altivec(vector__))) unsigned native_simd_type; union { native_simd_type V; int R[4]; } store_le_vec; struct S { S() =3D default; S(unsigned B0) { native_simd_type val{B0}; m_simd =3D val; } void store_le(unsigned char out[]) { store_le_vec.V =3D m_simd; unsigned int x0 =3D store_le_vec.R[0]; memcpy(out, &x0, 1); } S rotl(unsigned int r) { native_simd_type rot{r}; return __builtin_vec_rl(m_simd, rot); } void operator+=3D(S other) { m_simd =3D __builtin_vec_add(m_simd, other.m_simd); } void operator^=3D(S other) { m_simd =3D __builtin_vec_xor(m_simd, other.m_simd); } static void transpose(S &B0, S B1, S B2, S B3) { native_simd_type T0 =3D __builtin_vec_mergeh(B0.m_simd, B2.m_simd); native_simd_type T1 =3D __builtin_vec_mergeh(B1.m_simd, B3.m_simd); native_simd_type T2 =3D __builtin_vec_mergel(B0.m_simd, B2.m_simd); native_simd_type T3 =3D __builtin_vec_mergel(B1.m_simd, B3.m_simd); B0 =3D __builtin_vec_mergeh(T0, T1); B3 =3D __builtin_vec_mergel(T2, T3); } S(native_simd_type x) : m_simd(x) {} native_simd_type m_simd; }; void foo (unsigned char output[], unsigned state[]) { S R00 =3D state[0]; S R01 =3D state[0]; S R02 =3D state[2]; S R03 =3D state[0]; S R05 =3D state[5]; S R06 =3D state[6]; S R07 =3D state[7]; S R08 =3D state[8]; S R09 =3D state[9]; S R10 =3D state[10]; S R11 =3D state[11]; S R12 =3D state[12]; S R13 =3D state[13]; S R14 =3D state[4]; S R15 =3D state[15]; for (int r =3D 0; r !=3D 10; ++r) { R09 +=3D R13; R11 +=3D R15; R05 ^=3D R09; R06 ^=3D R10; R07 ^=3D R11; R07 =3D R07.rotl(7); R00 +=3D R05; R01 +=3D R06; R02 +=3D R07; R15 ^=3D R00; R12 ^=3D R01; R13 ^=3D R02; R00 +=3D R05; R01 +=3D R06; R02 +=3D R07; R15 ^=3D R00; R12 =3D R12.rotl(8); R13 =3D R13.rotl(8); R10 +=3D R15; R11 +=3D R12; R08 +=3D R13; R09 +=3D R14; R05 ^=3D R10; R06 ^=3D R11; R07 ^=3D R08; R05 =3D R05.rotl(7); R06 =3D R06.rotl(7); R07 =3D R07.rotl(7); } R00 +=3D state[0]; S::transpose(R00, R01, R02, R03); R00.store_le(output); } unsigned char res[1]; unsigned main_state[]{1634760805, 60878, 2036477234, 6, 0, 825562964, 1471091955, 1346092787, 506976774, 4197066702, 518848283, 118491664, 0, 0, 0, 0}; int main () { foo (res, main_state); if (res[0] !=3D 152) __builtin_abort(); }=