[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-17 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #16 from Rin Okuyama  ---
The fix has been cherry-picked for NetBSD:
https://mail-index.netbsd.org/source-changes/2023/07/18/msg146078.html

Let me thank you again, Oleg!

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-09 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #10 from Rin Okuyama  ---
(In reply to Oleg Endo from comment #9)
> Sorry for being late for 2 years with this.
...
> Unfortunately GCC 10.5 has just been released recently and that was the last 
> version 10.
> So the patch will be included from GCC version 11.

No problem at all! We will probably ship GCC 10.5 with your fix for NetBSD 10.
And we will switch to GCC 12 for NetBSD-current soon.

> I will commit the patch to all open GCC versions.

I'm looking forward to it :)

I'm really excited to know that we have active GCC developer working on SH!

Thanks,
rin

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2023-07-09 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #8 from Rin Okuyama  ---
(In reply to Oleg Endo from comment #7)

Hi Oleg. Thank you very much for your great work!

I've tested your patch with GCC 10.4.0 in this weekend, and it perfectly
worked:
- testcase attached to comment #0 compiled correctly
- full regression tests on NetBSD/shle-current built by patched GCC
successfully completed without any regression (compared with system built by
GCC with that peephole optimization removed)
- some 3rd party softwares (including perl 5.36.0, ruby 3.10.10, zsh 5.9, ...)
self-built on shle host by GCC of same code base

Let me thank you again, Oleg!

rin

[Bug target/100107] [10/11/12/13 Regression] powerpc: redundant .machine directive clobbers CPU flags to assembler

2022-07-24 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100107

Rin Okuyama  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #2 from Rin Okuyama  ---
The problem has been fixed differently for GCC 10.4:
- master:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=77eccbf39ed55297802bb66dff5f62507a7239e3
- gcc-10:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6142d65f4f528067f31e86bb97c07a661f2d66e7

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2021-07-21 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #6 from Rin Okuyama  ---
(In reply to Rin Okuyama from comment #3)
> If that peephole is removed, GCC 10.3 generates working codes.
> 
> NetBSD/shle built by this compiler works fine as far as I can see.
> I'm carrying out full regression tests of NetBSD on this system.
> (It takes about a day to finish.)

It took more time due to minor troubles for my side, but it finished.
Fallout from this bug is fixed, whereas no new regressions are observed!

Thanks,
rin

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2021-07-18 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #5 from Rin Okuyama  ---
Thank you for your kind attention! I look forward to hearing from you.

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2021-07-18 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #3 from Rin Okuyama  ---
Thank you very much for your analysis!

If that peephole is removed, GCC 10.3 generates working codes.

NetBSD/shle built by this compiler works fine as far as I can see.
I'm carrying out full regression tests of NetBSD on this system.
(It takes about a day to finish.)

Is there a better fix than mechanically removing that peephole?

Thanks,
rin

[Bug target/101469] wrong code with "-O2 -fPIE" for SH

2021-07-17 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

--- Comment #1 from Rin Okuyama  ---
I've confirmed that the problem also occurs for sh3-none-elf:


$ sh3-none-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/pkg/cross-sh3-none-elf/bin/sh3-none-elf-gcc
COLLECT_LTO_WRAPPER=/usr/pkg/cross-sh3-none-elf/libexec/gcc/sh3-none-elf/10.3.0/lto-wrapper
Target: sh3-none-elf
Configured with:
/build/pkgsrc/cross/sh3-none-elf-gcc/work.x86_64/gcc-10.3.0/configure
--target=sh3-none-elf --enable-languages=c,c++ --with-newlib --disable-nls
--disable-libstdcxx-pch --prefix=/usr/pkg/cross-sh3-none-elf
--build=x86_64--netbsd --host=x86_64--netbsd
--infodir=/usr/pkg/cross-sh3-none-elf/info
--mandir=/usr/pkg/cross-sh3-none-elf/man
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (GCC)


So, this is not NetBSD-specific.

Also, for shle--netbsdelf, GCC 7.5 and 5.5 has the same problem; this is
not a recent regression.

Thanks,
rin

[Bug c/101469] New: wrong code with "-O2 -fPIE" for SH

2021-07-16 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101469

Bug ID: 101469
   Summary: wrong code with "-O2 -fPIE" for SH
   Product: gcc
   Version: 10.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: rin at NetBSD dot org
CC: rin at NetBSD dot org
  Target Milestone: ---
Target: shle--netbsdelf

This Bug is for GCC 10.3 for shle:


$ shle--netbsdelf-gcc -v
Using built-in specs.
COLLECT_GCC=/build/gcc10/tools/bin/shle--netbsdelf-gcc
COLLECT_LTO_WRAPPER=/build/gcc10/tools/libexec/gcc/shle--netbsdelf/10.3.0/lto-wrapper
Target: shle--netbsdelf
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=shle--netbsdelf --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/support/send-pr.html
--with-pkgversion='NetBSD nb1 20210411' --with-system-zlib --without-isl
--enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-default-libstdcxx-abi=new
--with-sysroot=/build/gcc10/dest/landisk --with-mpc=/build/gcc10/tools
--with-mpfr=/build/gcc10/tools --with-gmp=/build/gcc10/tools --disable-nls
--disable-multilib --program-transform-name='s,^,shle--netbsdelf-,'
--enable-languages='c c++ objc' --prefix=/build/gcc10/tools
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (NetBSD nb1 20210411)


GCC miscompile this code with "-O2 -fPIE":


typedef struct {
int pad[16];
int i;
int *p;
} struct_t;

struct_t *sp;

void *ptr(void);

void func(void) {
sp = ptr();
sp->p = &sp->i;
}


The following is objdump with comments:


 :
   0:   mov.l   r12,@-r15
   2:   mova24 ,r0
   4:   mov.l   24 ,r12
   6:   sts.l   pr,@-r15
   8:   add r0,r12  ! r12 = .got
   a:   mov.l   28 ,r1
   c:   bsrfr1  ! r0 = ptr()
   e:   nop
  10:   mov.l   2c ,r1
  12:   mov r0,r2   ! r2 = r0
  14:   mov r12,r0
  16:   mov.l   r2,@(r0,r1) ! @(.got, 2c) = sp = r2
  18:   add #64,r2  ! r2 = &sp->i
  1a:   mov.l   r2,@(4,r12) ! XXX
  1c:   lds.l   @r15+,pr
  1e:   rts
  20:   mov.l   @r15+,r12
  22:   nop
  24:   .word 0x
  26:   .word 0x
  28:   sett
  2a:   .word 0x
  2c:   .word 0x


The problem is marked by XXX in comment; if this line were


  1a:   mov.l   r2,@(4,r2)


it would make sense, i.e.,


  @(4, &sp->i) = sp->p = r2 = &sp->i


However, unfortunately, GCC somehow mistakes r12 (= .got) with r2.
As a result, sp->p is not correctly set, and .got gets corrupted.

Note that generated code is almost same for "-Os -fPIE". And the
problem occurs also for GCC 9.3.

[Bug target/100108] [10 Regression] powerpc: recognize 32-bit CPU as POWER9 with -misel option

2021-04-21 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100108

--- Comment #11 from Rin Okuyama  ---
Segher, let me thank you again!

[Bug target/100108] [10/11 Regression] powerpc: recognize 32-bit CPU as POWER9 with -misel option

2021-04-19 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100108

--- Comment #7 from Rin Okuyama  ---
Thank you for discussion. The proposed patch works fine for me (except for
missing ``;'' at the end of the line).

[Bug target/100108] [10/11 Regression] powerpc: recognize 32-bit CPU as POWER9 with -misel option

2021-04-16 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100108

--- Comment #2 from Rin Okuyama  ---
e500mc also supports isel. See its reference manual (Sec. 3.4.5.3):

https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf

or source code of binutils/gas:

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gas/config/tc-ppc.c;h=c719b408b0eb59357f6d7e7022a9d041e181c318;hb=HEAD#l3973

[Bug target/100108] New: [10 Regression] powerpc: recognize 32-bit CPU as POWER9 with -misel option

2021-04-15 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100108

Bug ID: 100108
   Summary: [10 Regression] powerpc: recognize 32-bit CPU as
POWER9 with -misel option
   Product: gcc
   Version: 10.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: rin at NetBSD dot org
  Target Milestone: ---

Created attachment 50609
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50609&action=edit
Fix for this regression

GCC10 wrongly recognizes CPU as POWER9 if -misel is specified, even when
it is configured for 32-bit processors:

% cat test.c
int main(void)
{
return 0;
}
% gcc10 -misel -S test.c -o test10.S
% gcc9  -misel -S test.c -o test9.S
% diff -u test9.S test10.S
--- test.9  2021-04-16 10:53:47.116917225 +0900
+++ test.10 2021-04-16 10:53:38.075282430 +0900
@@ -1,5 +1,5 @@
.file   "test.c"
-   .machine ppc
+   .machine power9
.section".text"
.align 2
.globl main
...(snip)...

This is because rs6000_machine_from_flags() assumes ISEL instructions
are supported only by POWER9 and successors. However, ISEL is also
implemented for 32-bit processors like e500.

Please apply the attached patch to fix the problem.



% gcc10 -v
Using built-in specs.
COLLECT_GCC=/build/tools.broken/bin/powerpc--netbsd-gcc
COLLECT_LTO_WRAPPER=/build/tools.broken/libexec/gcc/powerpc--netbsd/10.3.0/lto-wrapper
Target: powerpc--netbsd
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=powerpc--netbsd --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/support/send-pr.html
--with-pkgversion='NetBSD nb1 20210411' --with-system-zlib --without-isl
--enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-default-libstdcxx-abi=new
--with-sysroot=/build/dest/evbppc-powerpc --with-mpc=/build/tools.broken
--with-mpfr=/build/tools.broken --with-gmp=/build/tools.broken --disable-nls
--disable-multilib --program-transform-name='s,^,powerpc--netbsd-,'
--enable-languages='c c++ objc' --prefix=/build/tools.broken
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (NetBSD nb1 20210411)



% gcc9 -v
Using built-in specs.
COLLECT_GCC=/build/tools.9/bin/powerpc--netbsd-gcc
COLLECT_LTO_WRAPPER=/build/tools.9/libexec/gcc/powerpc--netbsd/9.3.0/lto-wrapper
Target: powerpc--netbsd
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc.old/dist/configure
--target=powerpc--netbsd --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/support/send-pr.html
--with-pkgversion='NetBSD nb1 20200907' --with-system-zlib --without-isl
--enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-default-libstdcxx-abi=new
--with-sysroot=/build/dest/evbppc-powerpc --with-mpc=/build/tools.9
--with-mpfr=/build/tools.9 --with-gmp=/build/tools.9 --disable-nls
--disable-multilib --program-transform-name='s,^,powerpc--netbsd-,'
--enable-languages='c c++ objc' --prefix=/build/tools.9
Thread model: posix
gcc version 9.3.0 (NetBSD nb1 20200907)

[Bug target/100107] New: [10 Regression] powerpc: redundant .machine directive clobbers CPU flags to assembler

2021-04-15 Thread rin at NetBSD dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100107

Bug ID: 100107
   Summary: [10 Regression] powerpc: redundant .machine directive
clobbers CPU flags to assembler
   Product: gcc
   Version: 10.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: rin at NetBSD dot org
  Target Milestone: ---

Created attachment 50608
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50608&action=edit
Fix for this regression

GCC10 miscompiles inline assembler codes for 403/405 processors:

% cat mfpid.c
unsigned mfpid(void)
{
unsigned pid;
__asm volatile("mfpid %0" : "=r"(pid));
return pid;
}
% gcc10 -m403 -c mfpid.c -o mfpid10.o && objdump -D403 mfpid10.o > mfpid10.dump
% gcc9  -m403 -c mfpid.c -o mfpid9.o  && objdump -D403 mfpid9.o  > mfpid9.dump
% diff -u mfpid9.dump mfpid10.dump
...(snip)...
-   c:  7d 31 ea a6 mfpid   r9
+   c:  7d 30 0a a6 mfspr   r9,48
...(snip)...

This is because redundant .machine directive, introduced by commit
2d94f7dea9c73ef3c116a0ddc722724578a860fe:

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2d94f7dea9c73ef3c116a0ddc722724578a860fe

clobbers CPU flags passed to assembler (-m403 in this case). Actually, diff
b/w .S files generated by GCC9 and 10 reads:

% diff -u mfpid9.S mfpid10.S
--- mfpid9.S2021-04-16 10:21:47.688171347 +0900
+++ mfpid10.S   2021-04-16 10:21:37.262150628 +0900
@@ -1,4 +1,5 @@
.file   "mfpid.c"
+   .machine ppc
.section".text"
.align 2
.globl mfpid
...(snip)...

By reverting that commit with attached patch, this file can be successfully
compiled again with GCC10.



% gcc10 -v
Using built-in specs.
COLLECT_GCC=/build/tools.broken/bin/powerpc--netbsd-gcc
COLLECT_LTO_WRAPPER=/build/tools.broken/libexec/gcc/powerpc--netbsd/10.3.0/lto-wrapper
Target: powerpc--netbsd
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=powerpc--netbsd --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/support/send-pr.html
--with-pkgversion='NetBSD nb1 20210411' --with-system-zlib --without-isl
--enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-default-libstdcxx-abi=new
--with-sysroot=/build/dest/evbppc-powerpc --with-mpc=/build/tools.broken
--with-mpfr=/build/tools.broken --with-gmp=/build/tools.broken --disable-nls
--disable-multilib --program-transform-name='s,^,powerpc--netbsd-,'
--enable-languages='c c++ objc' --prefix=/build/tools.broken
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (NetBSD nb1 20210411)



% gcc9 -v
Using built-in specs.
COLLECT_GCC=/build/tools.9/bin/powerpc--netbsd-gcc
COLLECT_LTO_WRAPPER=/build/tools.9/libexec/gcc/powerpc--netbsd/9.3.0/lto-wrapper
Target: powerpc--netbsd
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc.old/dist/configure
--target=powerpc--netbsd --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/support/send-pr.html
--with-pkgversion='NetBSD nb1 20200907' --with-system-zlib --without-isl
--enable-__cxa_atexit --enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-default-libstdcxx-abi=new
--with-sysroot=/build/dest/evbppc-powerpc --with-mpc=/build/tools.9
--with-mpfr=/build/tools.9 --with-gmp=/build/tools.9 --disable-nls
--disable-multilib --program-transform-name='s,^,powerpc--netbsd-,'
--enable-languages='c c++ objc' --prefix=/build/tools.9
Thread model: posix
gcc version 9.3.0 (NetBSD nb1 20200907)