From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 66246385842A; Wed, 2 Feb 2022 19:30:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66246385842A From: "ckk at kvr dot at" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/104353] New: ppc64le: Apparent reliance on undefined behavior of xvcvdpsxws Date: Wed, 02 Feb 2022 19:30:28 +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: ckk at kvr dot at 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_file_loc 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: Wed, 02 Feb 2022 19:30:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104353 Bug ID: 104353 Summary: ppc64le: Apparent reliance on undefined behavior of xvcvdpsxws Product: gcc Version: 11.2.0 URL: https://github.com/numpy/numpy/issues/20964#issuecomme nt-1027865665 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ckk at kvr dot at Target Milestone: --- Created attachment 52331 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52331&action=3Dedit Minimal test case for reproduction I ran into a strange numpy error on ppc64le that only occurred inside a ppc= 64le QEMU instance. In short, casting arrays of i doubles 1.0 to ints 1 worked as expected on native hardware, but produced the following bogus results when running inside a VM: i =3D 1: 1 i =3D 2: 1 1 i =3D 3: 1 1 1 i =3D 4: 0 0 0 0 i =3D 5: 0 0 0 0 1 i =3D 6: 0 0 0 0 1 1 i =3D 7: 0 0 0 0 1 1 1 i =3D 8: 0 0 0 0 0 0 0 0 i =3D 9: 0 0 0 0 0 0 0 0 1 ... Guided by the numpy folks, a SIMD issue was suspected, and I managed to cre= ate a minimal test case (attached here) with which this could be reproduced. It only occurs with -O3. I then filed an issue with QEMU, where the issue was quickly rejected. This= led to further analysis by the numpy folks. There, it was discovered that GCC is apparently relying on undefined behavior of the xvcvdpsxws instruction, whi= ch happened to work on native hardware because it happen to exhibit that behav= ior. I'm only summarizing here; there's a great analysis in detail, and a much better test case, on the GitHub issue, which I have linked in the URL as I'd prefer not to reproduce the author's work here.=