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

            Bug ID: 128705
           Summary: powerpc64: a halfword zero-extended to __int128 is
                    loaded as a doubleword
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shimizu2486 at gmail dot com
  Target Milestone: ---
            Target: powerpc64le-linux-gnu, powerpc64-linux-gnu

Live reproducer: https://godbolt.org/z/f4Mqnx5jx

$ cat t1.c
#include <stdio.h>

__attribute__((noipa)) unsigned __int128 f(unsigned short *p, unsigned __int128
d) {
  return p[1] / d;
}

int main(void) {
  unsigned short a[5] = {1, 2, 3, 4, 5};
  printf("%llx\n", (unsigned long long)f(a, 1));
}

The program should print 2.

$ powerpc64le-linux-gnu-gcc -mcpu=power10 -O1 -static t1.c -o t1 &&
qemu-ppc64le -cpu power10 ./t1
2                                   (correct)
$ powerpc64le-linux-gnu-gcc -mcpu=power10 -O2 -static t1.c -o t1 &&
qemu-ppc64le -cpu power10 ./t1
5000400030002                       (wrong)

  powerpc64le trunk (a2a11abf)     wrong
  powerpc64le 16.2.0               correct
  powerpc64le 15.3.0               correct
  powerpc64 trunk (a2a11abf)       wrong (2000300040005)
  powerpc64 16.2.0                 correct

-O0 and -O1 are correct; -O2, -O3 and -Os are wrong.
-fno-peephole2, -mcpu=power9 are correct and -mcpu=power11 is wrong.
unsigned char and unsigned int elements go wrong the same way.
x86-64 behaves correctly.

Reply via email to