public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/109973] New: Wrong code for AVX2 since 13.1 by combining VPAND and VPTEST
@ 2023-05-26  0:38 benjsith at gmail dot com
  2023-05-26  0:42 ` [Bug rtl-optimization/109973] " benjsith at gmail dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: benjsith at gmail dot com @ 2023-05-26  0:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109973

            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 <immintrin.h>

int do_stuff(__m256i Y0, __m256i Y1, __m128i X2) {
  __m256i And01 = _mm256_and_si256(Y0, Y1);
  int TestResult = _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 code,
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-07-20  7:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26  0:38 [Bug rtl-optimization/109973] New: Wrong code for AVX2 since 13.1 by combining VPAND and VPTEST benjsith at gmail dot com
2023-05-26  0:42 ` [Bug rtl-optimization/109973] " benjsith at gmail dot com
2023-05-26  0:47 ` [Bug target/109973] [13/14 Regression] " pinskia at gcc dot gnu.org
2023-05-26  6:31 ` [Bug target/109973] [13/14 Regression] Wrong code for AVX2 since 13.1 by combining VPAND and VPTEST since r13-2006-ga56c1641e9d25e rguenth at gcc dot gnu.org
2023-05-26  6:56 ` jakub at gcc dot gnu.org
2023-05-26 12:06 ` benjsith at gmail dot com
2023-05-29 18:24 ` roger at nextmovesoftware dot com
2023-05-30 13:44 ` cvs-commit at gcc dot gnu.org
2023-06-01 14:12 ` cvs-commit at gcc dot gnu.org
2023-06-03 18:01 ` benjsith at gmail dot com
2023-06-04 11:01 ` cvs-commit at gcc dot gnu.org
2023-06-22  6:44 ` cvs-commit at gcc dot gnu.org
2023-07-03 13:28 ` [Bug target/109973] [13 " roger at nextmovesoftware dot com
2023-07-03 13:43 ` jakub at gcc dot gnu.org
2023-07-20  7:28 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).