From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 516A13858CDB; Fri, 26 May 2023 00:38:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 516A13858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685061522; bh=X3SFQWUhitB+Ya4i9/cvJ4E25BqQUOYhly9IhxGKe3Q=; h=From:To:Subject:Date:From; b=GR6xIlFgMSg+1phMPy3/UhBrqXdDoNoRJwRXRSjuWa7nQ8R5SNTtNz6g8GWj2dqxi YsyYTQR1hSKokLjE3w8ljrRppRjooKsTKd3fEArCt9vLk7VpVSo9k+5G2GnrqCze7f GhCeqpiH5dk1fGaYsC0KlBCvXB2uB4SEEakvmRt8= From: "benjsith at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109973] New: Wrong code for AVX2 since 13.1 by combining VPAND and VPTEST Date: Fri, 26 May 2023 00:38:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: benjsith 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109973 Bug ID: 109973 Summary: Wrong code for AVX2 since 13.1 by combining VPAND and VPTEST Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: benjsith at gmail dot com Target Milestone: --- The following code is a minimal repro of the issue, when compiled with `gcc= -O1 -mavx2`: #include int do_stuff(__m256i Y0, __m256i Y1, __m128i X2) { __m256i And01 =3D _mm256_and_si256(Y0, Y1); int TestResult =3D _mm256_testc_si256(And01, And01); return TestResult; } I have also attached the preprocessed version of that minimal repro 12.3 produces the following assembly vpand ymm0, ymm0, ymm1 ; <<<<< missing in 13.1 mov eax, 0 vptest ymm0, ymm0 setb al ret While 13.1 generates: mov eax, 0 vptest ymm0, ymm1 setb al ret Note that as of 13.1, the VPAND is removed, and just the VPTEST remains. However, this is incorrect because _mm256_testc_si256 returns the results of the Carry Flag, which is based on the bitwise AND of the second operand and= the bitwise NOT of the first operand, meaning these two can't be combined like = that for this intrinsic Here is a Godbolt link showing the issue with a full execution case: https://godbolt.org/z/x9or4WEWh This issue is present in 12.3 but not 13.1. A bisect shows that it was most likely introduced in a56c1641e9d25e46059168e811b4a2f185f07b6b I have confirmed that this issue is still present on the latest trunk, 8d2fa90a41567670d2dbd4918d19d21d9bec4a8f -O0 on trunk will also return the correct result For triage/priority purposes: this bug was not found in manually written co= de, but instead from a fuzzer meant to test SIMD codegen PS: This is my first bug on the GCC tracker, so if I've done anything wrong= let me know. I marked it as in "rtl-optimization" though I'm not sure if that's correct=