Bug 108699 - gcc.c-torture/execute/builtin-bitops-1.c fails on power 9 BE
Summary: gcc.c-torture/execute/builtin-bitops-1.c fails on power 9 BE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Kewen Lin
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2023-02-07 15:01 UTC by seurer
Modified: 2023-06-02 04:42 UTC (History)
4 users (show)

See Also:
Host: powerpc64-linux-gnu
Target: powerpc64-linux-gnu
Build: powerpc64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2023-02-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description seurer 2023-02-07 15:01:13 UTC
This fails for 32 bits powerpc64 BE on a power 9 (only) and it fails for trunk and gcc 12, 11, and 10.

make  -k check-gcc RUNTESTFLAGS="--target_board=unix'{-m32}' execute.exp=gcc.c-torture/execute/builtin-bitops-1.c"
FAIL: gcc.c-torture/execute/builtin-bitops-1.c   -Os  execution test
# of expected passes		15
# of unexpected failures	1

spawn -ignore SIGHUP 
^M
PASS: gcc.c-torture/execute/builtin-bitops-1.c   -Os  (test for excess errors)
Setting LD_LIBRARY_PATH to :/home/seurer/gcc/git/build/gcc-test/gcc:/home/seurer/gcc/git/build/gcc-test/gcc/32::/home/seurer/gcc/git/build/gcc-test/gcc:/home/seurer/gcc/git/build/gcc-test/gcc/32:/home/seurer/gcc/git/build/gcc-test/./gmp/.libs:/home/seurer/gcc/git/build/gcc-test/./prev-gmp/.libs:/home/seurer/gcc/git/build/gcc-test/./mpfr/src/.libs:/home/seurer/gcc/git/build/gcc-test/./prev-mpfr/src/.libs:/home/seurer/gcc/git/build/gcc-test/./mpc/src/.libs:/home/seurer/gcc/git/build/gcc-test/./prev-mpc/src/.libs:/home/seurer/gcc/git/build/gcc-test/./isl/.libs:/home/seurer/gcc/git/build/gcc-test/./prev-isl/.libs
Execution timeout is: 300
spawn [open ...]^M
FAIL: gcc.c-torture/execute/builtin-bitops-1.c   -Os  execution test


(gdb) run
Starting program: /home/seurer/gcc/git/build/gcc-test/builtin-bitops-1.exe 
Program received signal SIGABRT, Aborted.
0x0fd737a0 in ?? () from /lib32/libc.so.6
(gdb) where
#0  0x0fd737a0 in ?? () from /lib32/libc.so.6
#1  0x0fd15424 in raise () from /lib32/libc.so.6
#2  0x0fcfa428 in abort () from /lib32/libc.so.6
#3  0x10000408 in main () at /home/seurer/gcc/git/gcc-test/gcc/testsuite/gcc.c-torture/execute/builtin-bitops-1.c:182


There are a bunch of aborts in this test but the reported line # must be off.
Comment 1 Kewen Lin 2023-02-14 12:12:54 UTC
Confirmed.

This is due to one latent bug. When specifying -Os, it doesn't try to use SImode parity any more, but tries to use wider mode TImode parity instead, it resulted in the wrong result.

The current vector parity (including TImode) support is wrong:

;; Vector parity
(define_insn "*p9v_parity<mode>2"
  [(set (match_operand:VParity 0 "register_operand" "=v")
        (parity:VParity (match_operand:VParity 1 "register_operand" "v")))]
  "TARGET_P9_VECTOR"
  "vprtyb<wd> %0,%1"
  [(set_attr "type" "vecsimple")])

The vprtyb[dwq] is for byte parity, it doesn't match the RTL parity semantic directly.
Comment 2 Segher Boessenkool 2023-02-14 17:39:35 UTC
Right, it needs a vpopcntb or similar first.
Comment 3 Kewen Lin 2023-02-15 02:34:59 UTC
One more test case fail with abort on both LE & BE (with -Ofast -mcpu=power9):

----

#define N 16

unsigned long long vals[N];
unsigned int res[N];
unsigned int expects[N] = {0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};

unsigned long long inputs[N]
  = {0x0000000000000000ULL, 0x0000000000000001ULL, 0x8000000000000000ULL,
     0x0000000000000002ULL, 0x4000000000000000ULL, 0x0000000100000000ULL,
     0x0000000080000000ULL, 0xa5a5a5a5a5a5a5a5ULL, 0x5a5a5a5a5a5a5a5aULL,
     0xcafecafe00000000ULL, 0x0000cafecafe0000ULL, 0x00000000cafecafeULL,
     0x8070600000000000ULL, 0xffffffffffffffffULL};

__attribute__ ((noipa)) void
init ()
{
  for (int i = 0; i < N; i++)
    vals[i] = inputs[i];
}

__attribute__ ((noipa)) void
do_parity ()
{
  for (int i = 0; i < N; i++)
    res[i] = __builtin_parityll (vals[i]);
}

int
main (void)
{
  init ();
  do_parity ();
  for (int i = 0; i < N; i++)
    if (res[i] != expects[i])
      __builtin_abort();

  return 0;
}

----
Comment 4 GCC Commits 2023-04-04 05:13:37 UTC
The master branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:cdd2d6643f7fef40e335a7027edfea7276cde608

commit r13-6993-gcdd2d6643f7fef40e335a7027edfea7276cde608
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Mon Apr 3 21:47:44 2023 -0500

    rs6000: Fix vector parity support [PR108699]
    
    The failures on the original failed case builtin-bitops-1.c
    and the associated test case pr108699.c here show that the
    current support of parity vector mode is wrong on Power.
    The hardware insns vprtyb[wdq] which operate on the least
    significant bit of each byte per element, they doesn't match
    what RTL opcode parity needs, but the current implementation
    expands it with them wrongly.
    
    This patch is to fix the handling with one more insn vpopcntb.
    
            PR target/108699
    
    gcc/ChangeLog:
    
            * config/rs6000/altivec.md (*p9v_parity<mode>2): Rename to ...
            (rs6000_vprtyb<mode>2): ... this.
            * config/rs6000/rs6000-builtins.def (VPRTYBD): Replace parityv2di2 with
            rs6000_vprtybv2di2.
            (VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2.
            (VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2.
            * config/rs6000/vector.md (parity<mode>2 with VEC_IP): Expand with
            popcountv16qi2 and the corresponding rs6000_vprtyb<mode>2.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb
            to distinguish parity byte from parity.
            * gcc.target/powerpc/pr108699.c: New test.
Comment 5 GCC Commits 2023-04-17 09:06:45 UTC
The releases/gcc-12 branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:de8f86e151d29c6c2ebb224b5587284714cd6cfa

commit r12-9406-gde8f86e151d29c6c2ebb224b5587284714cd6cfa
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Mon Apr 3 21:47:44 2023 -0500

    rs6000: Fix vector parity support [PR108699]
    
    The failures on the original failed case builtin-bitops-1.c
    and the associated test case pr108699.c here show that the
    current support of parity vector mode is wrong on Power.
    The hardware insns vprtyb[wdq] which operate on the least
    significant bit of each byte per element, they doesn't match
    what RTL opcode parity needs, but the current implementation
    expands it with them wrongly.
    
    This patch is to fix the handling with one more insn vpopcntb.
    
            PR target/108699
    
    gcc/ChangeLog:
    
            * config/rs6000/altivec.md (*p9v_parity<mode>2): Rename to ...
            (rs6000_vprtyb<mode>2): ... this.
            * config/rs6000/rs6000-builtins.def (VPRTYBD): Replace parityv2di2 with
            rs6000_vprtybv2di2.
            (VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2.
            (VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2.
            * config/rs6000/vector.md (parity<mode>2 with VEC_IP): Expand with
            popcountv16qi2 and the corresponding rs6000_vprtyb<mode>2.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb
            to distinguish parity byte from parity.
            * gcc.target/powerpc/pr108699.c: New test.
    
    (cherry picked from commit cdd2d6643f7fef40e335a7027edfea7276cde608)
Comment 6 GCC Commits 2023-04-17 09:08:09 UTC
The releases/gcc-11 branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:6872f055d7d4fd36b804bdd9b5a8a128b01aacbc

commit r11-10628-g6872f055d7d4fd36b804bdd9b5a8a128b01aacbc
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Sun Apr 16 22:31:01 2023 -0500

    rs6000: Fix vector parity support [PR108699]
    
    The failures on the original failed case builtin-bitops-1.c
    and the associated test case pr108699.c here show that the
    current support of parity vector mode is wrong on Power.
    The hardware insns vprtyb[wdq] which operate on the least
    significant bit of each byte per element, they doesn't match
    what RTL opcode parity needs, but the current implementation
    expands it with them wrongly.
    
    This patch is to fix the handling with one more insn vpopcntb.
    
            PR target/108699
    
    gcc/ChangeLog:
    
            * config/rs6000/altivec.md (*p9v_parity<mode>2): Rename to ...
            (rs6000_vprtyb<mode>2): ... this.
            * config/rs6000/rs6000-builtin.def (VPRTYBD): Replace parityv2di2 with
            rs6000_vprtybv2di2.
            (VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2.
            (VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2.
            * config/rs6000/vector.md (parity<mode>2 with VEC_IP): Expand with
            popcountv16qi2 and the corresponding rs6000_vprtyb<mode>2.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb
            to distinguish parity byte from parity.
            * gcc.target/powerpc/pr108699.c: New test.
    
    (cherry picked from commit cdd2d6643f7fef40e335a7027edfea7276cde608)
Comment 7 GCC Commits 2023-04-17 09:09:10 UTC
The releases/gcc-10 branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:d88e488ec9321e44291fcaf2a3b14333f64aac01

commit r10-11291-gd88e488ec9321e44291fcaf2a3b14333f64aac01
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Mon Apr 3 21:47:44 2023 -0500

    rs6000: Fix vector parity support [PR108699]
    
    The failures on the original failed case builtin-bitops-1.c
    and the associated test case pr108699.c here show that the
    current support of parity vector mode is wrong on Power.
    The hardware insns vprtyb[wdq] which operate on the least
    significant bit of each byte per element, they doesn't match
    what RTL opcode parity needs, but the current implementation
    expands it with them wrongly.
    
    This patch is to fix the handling with one more insn vpopcntb.
    
            PR target/108699
    
    gcc/ChangeLog:
    
            * config/rs6000/altivec.md (*p9v_parity<mode>2): Rename to ...
            (rs6000_vprtyb<mode>2): ... this.
            * config/rs6000/rs6000-builtin.def (VPRTYBD): Replace parityv2di2 with
            rs6000_vprtybv2di2.
            (VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2.
            (VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2.
            * config/rs6000/vector.md (parity<mode>2 with VEC_IP): Expand with
            popcountv16qi2 and the corresponding rs6000_vprtyb<mode>2.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb
            to distinguish parity byte from parity.
            * gcc.target/powerpc/pr108699.c: New test.
    
    (cherry picked from commit cdd2d6643f7fef40e335a7027edfea7276cde608)
Comment 8 Peter Bergner 2023-06-02 04:15:41 UTC
Can this be marked as FIXED or is there more to do?
Comment 9 Kewen Lin 2023-06-02 04:42:25 UTC
(In reply to Peter Bergner from comment #8)
> Can this be marked as FIXED or is there more to do?

Yeah, the issue should be fixed everywhere, thanks for reminding!