Bug 91269 - [9/10 regression] unaligned floating-point register with -mcpu=niagara4 -fcall-used-g6
Summary: [9/10 regression] unaligned floating-point register with -mcpu=niagara4 -fcal...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 9.1.0
: P3 normal
Target Milestone: 9.3
Assignee: Eric Botcazou
URL:
Keywords: assemble-failure
Depends on:
Blocks:
 
Reported: 2019-07-26 22:59 UTC by Sergei Trofimovich
Modified: 2023-07-22 03:00 UTC (History)
2 users (show)

See Also:
Host:
Target: sparc64-unknown-linux-gnu
Build:
Known to work: 7.4.0, 8.3.0
Known to fail: 10.0, 9.1.0, 9.2.0
Last reconfirmed: 2019-09-17 00:00:00


Attachments
bug.c (478 bytes, text/plain)
2019-07-26 22:59 UTC, Sergei Trofimovich
Details
bug-lz4-8.3.0.c (1.03 KB, text/x-csrc)
2019-09-21 08:29 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2019-07-26 22:59:26 UTC
Original failure happens when glibc is built as:
    ../glibc/configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=sparc64-unknown-linux-gnu CFLAGS="-O2 -mcpu=niagara4 -pipe" && make
Single file iso-2022-jp-3.c fails to build as:
    sparc64-unknown-linux-gnu-gcc iso-2022-jp-3.c -c -std=gnu11 -fgnu89-inline  -O2 -mcpu=niagara4 -pipe -Wall -Wwrite-strings -Wundef -Werror -fmerge-all-constants -frounding-math -fno-stack-protector -Wstrict-prototypes -Wold-style-definition -fmath-errno -fcall-used-g6 -Wa,-Av9a -mvis  -fPIC      -U_FORTIFY_SOURCE   -I../include -I/home/slyfox/dev/git/glibc-build-sparc64/iconvdata  -I/home/slyfox/dev/git/glibc-build-sparc64  -I../sysdeps/unix/sysv/linux/sparc/sparc64  -I../sysdeps/unix/sysv/linux/wordsize-64  -I../sysdeps/unix/sysv/linux/sparc  -I../sysdeps/sparc/nptl  -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux  -I../sysdeps/nptl  -I../sysdeps/pthread  -I../sysdeps/gnu  -I../sysdeps/unix/inet  -I../sysdeps/unix/sysv  -I../sysdeps/unix  -I../sysdeps/posix  -I../sysdeps/sparc/sparc64/fpu/multiarch  -I../sysdeps/sparc/sparc64/fpu  -I../sysdeps/sparc/sparc64/multiarch  -I../sysdeps/sparc/sparc64  -I../sysdeps/wordsize-64  -I../sysdeps/ieee754/ldbl-128  -I../sysdeps/ieee754/dbl-64/wordsize-64  -I../sysdeps/ieee754/dbl-64  -I../sysdeps/ieee754/flt-32  -I../sysdeps/sparc/fpu  -I../sysdeps/sparc  -I../sysdeps/ieee754  -I../sysdeps/generic  -I.. -I../libio -I.   -D_LIBC_REENTRANT -include /home/slyfox/dev/git/glibc-build-sparc64/libc-modules.h -DMODULE_NAME=iconvdata -include ../include/libc-symbols.h  -DPIC -DSHARED     -DTOP_NAMESPACE=glibc -o /home/slyfox/dev/git/glibc-build-sparc64/iconvdata/iso-2022-jp-3.os -MD -MP -MF /home/slyfox/dev/git/glibc-build-sparc64/iconvdata/iso-2022-jp-3.os.dt -MT /home/slyfox/dev/git/glibc-build-sparc64/iconvdata/iso-2022-jp-3.os
{standard input}: Assembler messages:
{standard input}:2619: Error: Illegal operands

Attached self-contained reproducer fails in a similar way:

OK:
$ sparc64-unknown-linux-gnu-gcc -O2 -fno-stack-protector -fcall-used-g6 -mcpu=niagara3 -c bug.c -o bug.o
bug.c: In function 'c':
bug.c:13:8: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   13 |     cp = b[k];
      |        ^

Bad:
$ sparc64-unknown-linux-gnu-gcc -O2 -fno-stack-protector -fcall-used-g6 -mcpu=niagara4 -c bug.c -o bug.o
bug.c: In function 'c':
bug.c:13:8: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   13 |     cp = b[k];
      |        ^
/tmp/ccohisfz.s: Assembler messages:
/tmp/ccohisfz.s:145: Error: Illegal operands

$ sparc64-unknown-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/sparc64-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/sparc64-unknown-linux-gnu/9.1.0/lto-wrapper
Target: sparc64-unknown-linux-gnu
Configured with: /tmp/portage-tmpdir/portage/cross-sparc64-unknown-linux-gnu/gcc-9.1.0-r1/work/gcc-9.1.0/configure --host=x86_64-pc-linux-gnu --target=sparc64-unknown-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/sparc64-unknown-linux-gnu/gcc-bin/9.1.0 --includedir=/usr/lib/gcc/sparc64-unknown-linux-gnu/9.1.0/include --datadir=/usr/share/gcc-data/sparc64-unknown-linux-gnu/9.1.0 --mandir=/usr/share/gcc-data/sparc64-unknown-linux-gnu/9.1.0/man --infodir=/usr/share/gcc-data/sparc64-unknown-linux-gnu/9.1.0/info --with-gxx-include-dir=/usr/lib/gcc/sparc64-unknown-linux-gnu/9.1.0/include/g++-v9 --with-python-dir=/share/gcc-data/sparc64-unknown-linux-gnu/9.1.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.1.0-r1 p1.1' --disable-esp --enable-libstdcxx-time --with-build-config=bootstrap-lto --enable-poison-system-directories --with-sysroot=/usr/sparc64-unknown-linux-gnu --disable-bootstrap --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-systemtap --enable-vtable-verify --enable-lto --without-isl --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 9.1.0 (Gentoo 9.1.0-r1 p1.1)
Comment 1 Sergei Trofimovich 2019-07-26 22:59:48 UTC
Created attachment 46630 [details]
bug.c
Comment 2 Sergei Trofimovich 2019-07-26 23:01:45 UTC
$ sparc64-unknown-linux-gnu-gcc -O2 -fno-stack-protector -fcall-used-g6 -mcpu=niagara4 -c bug.c -o bug.o

bug.c: In function 'c':
bug.c:13:8: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   13 |     cp = b[k];
      |        ^
/tmp/cc0K0Ide.s: Assembler messages:
/tmp/cc0K0Ide.s:145: Error: Illegal operands
Comment 3 Sergei Trofimovich 2019-07-26 23:10:18 UTC
$ sparc64-unknown-linux-gnu-gcc -S -O2 -fno-stack-protector -fcall-used-g6 -mcpu=niagara4 -c bug.c -o bug.S
bug.c: In function 'c':
bug.c:13:8: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   13 |     cp = b[k];
      |        ^

$ sparc64-unknown-linux-gnu-gcc -c -O2 -fno-stack-protector -fcall-used-g6 -mcpu=niagara4 -c bug.S -o bug.o
bug.c: Assembler messages:
bug.c:145: Error: Illegal operands

$ nl -bt bug.S | grep -C3 145
   142          cwbe    %g0, %g0, .L5
   143  .L40:
   144          mov     %i0, %o0
   145          std     %f9, [%fp+1999]
   146          stx     %g4, [%fp+2007]
   147          stx     %o2, [%fp+2015]
   148          call    u, 0

Commenting out line '145          std     %f9, [%fp+1999]' does not make error disappear. Line numbers are probably skewed.
Comment 4 Sergei Trofimovich 2019-07-26 23:16:13 UTC
> Commenting out line '145          std     %f9, [%fp+1999]' does not make
> error disappear. Line numbers are probably skewed.

Oh, it's because I used ';' as a comment. Commenting out with '#' makes the error go away.

Perhaps 1999 is too large an offset for 'std'.
Comment 5 Matt Turner 2019-07-26 23:51:50 UTC
With -mcpu=niagara4 and *without* -fcall-used-g6 it compiles fine.
Comment 6 Matt Turner 2019-07-27 01:24:15 UTC
(In reply to Matt Turner from comment #5)
> With -mcpu=niagara4 and *without* -fcall-used-g6 it compiles fine.

Also doesn't occur with -O1 or -mno-lra.
Comment 7 Matt Turner 2019-07-27 01:26:49 UTC
(In reply to Sergei Trofimovich from comment #4)
> > Commenting out line '145          std     %f9, [%fp+1999]' does not make
> > error disappear. Line numbers are probably skewed.
>
> Perhaps 1999 is too large an offset for 'std'.

Sergei noticed that 'std' must take an even numbered register, so s/f9/f8/ on that line causes it to assemble.
Comment 8 Sergei Trofimovich 2019-07-28 16:50:21 UTC
Extra info: -fPIE is also needed to reproduce on on vanilla gcc from git.
Thus the reproducer is:

  $ gcc/xgcc -Bgcc -O2 -fcall-used-g6 -fPIE -mcpu=niagara4 -c bug.c -o bug.o

bug.c: In function 'c':
bug.c:13:8: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   13 |     cp = b[k];
      |        ^
/tmp/ccaJlRBg.s: Assembler messages:
/tmp/ccaJlRBg.s:145: Error: Illegal operands



  $ gcc/xgcc -Bgcc -v

Reading specs from gcc/specs
COLLECT_GCC=gcc/xgcc
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: sparc64-unknown-linux-gnu
Configured with: ../gcc/configure --target=sparc64-unknown-linux-gnu --with-sysroot=/usr/sparc64-unknown-linux-gnu --enable-languages=c --disable-bootstrap --prefix=/home/slyfox/dev/git/gcc-sparc64/../gcc-sparc64-installed --disable-multilib cross_compiling=yes
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.0 20190728 (experimental) (GCC)
Comment 9 Sergei Trofimovich 2019-09-16 22:52:38 UTC
Still happens on
    gcc version 10.0.0 20190916 (experimental) (GCC)
How can I peek at the stage where registers are assigned to std instruction? I suspect it needs special annotation WRT paired FPU registers.
Comment 10 Eric Botcazou 2019-09-17 15:47:04 UTC
I can reproduce.
Comment 11 Eric Botcazou 2019-09-17 15:48:16 UTC
Investigating.
Comment 12 Eric Botcazou 2019-09-20 09:43:11 UTC
Author: ebotcazou
Date: Fri Sep 20 09:42:40 2019
New Revision: 275994

URL: https://gcc.gnu.org/viewcvs?rev=275994&root=gcc&view=rev
Log:
	PR target/91269
	* config/sparc/sparc.h (HARD_REGNO_CALLER_SAVE_MODE): Define.

Added:
    trunk/gcc/testsuite/gcc.dg/pr91269.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sparc/sparc.h
    trunk/gcc/testsuite/ChangeLog
Comment 13 Eric Botcazou 2019-09-20 09:46:18 UTC
Author: ebotcazou
Date: Fri Sep 20 09:45:26 2019
New Revision: 275995

URL: https://gcc.gnu.org/viewcvs?rev=275995&root=gcc&view=rev
Log:
	PR target/91269
	* config/sparc/sparc.h (HARD_REGNO_CALLER_SAVE_MODE): Define.

Added:
    branches/gcc-9-branch/gcc/testsuite/gcc.dg/pr91269.c
      - copied unchanged from r275994, trunk/gcc/testsuite/gcc.dg/pr91269.c
Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/config/sparc/sparc.h
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
Comment 14 Eric Botcazou 2019-09-20 09:48:44 UTC
This should compile again.
Comment 15 Matt Turner 2019-09-20 22:57:43 UTC
I believe the Known to work field is wrong and gcc-8.3.0 has this bug as well. Can we have this backported to the gcc-8 branch?

Thank you!

(FWIW, we also discovered that lz4-1.8.3 fails to build on 64-bit sparc due to tihs bug as well)
Comment 16 Eric Botcazou 2019-09-21 07:38:13 UTC
> I believe the Known to work field is wrong and gcc-8.3.0 has this bug as
> well.

No, the field is correct and you're wrong.
Comment 17 Sergei Trofimovich 2019-09-21 08:29:13 UTC
Created attachment 46906 [details]
bug-lz4-8.3.0.c

Here is a bug-lz4-8.3.0.c that exposes suspiciously similar failure on sparc64 gcc-8.3.0 on lz4-1.8.3 package:

  $ LANG=C sparc64-unknown-linux-gnu-gcc-8.3.0 -O2 -pipe -mcpu=niagara4 -fPIC -c bug-lz4-8.3.0.c -o bug-lz4-8.3.0.o

  {standard input}: Assembler messages:
  {standard input}:365: Error: Illegal operands
Comment 18 Eric Botcazou 2019-09-21 09:20:23 UTC
> Here is a bug-lz4-8.3.0.c that exposes suspiciously similar failure on
> sparc64 gcc-8.3.0 on lz4-1.8.3 package:

Please open a new PR with the appropriate information, this one is closed.
Comment 19 Sergei Trofimovich 2019-09-21 11:40:04 UTC
(In reply to Eric Botcazou from comment #18)
> > Here is a bug-lz4-8.3.0.c that exposes suspiciously similar failure on
> > sparc64 gcc-8.3.0 on lz4-1.8.3 package:
> 
> Please open a new PR with the appropriate information, this one is closed.

Sounds good. Filed bug #91854.
Comment 20 Eric Botcazou 2019-10-01 08:10:48 UTC
Author: ebotcazou
Date: Tue Oct  1 08:10:17 2019
New Revision: 276390

URL: https://gcc.gnu.org/viewcvs?rev=276390&root=gcc&view=rev
Log:
	PR target/91854
	Backport from mainline
	2019-09-20  Eric Botcazou  <ebotcazou@adacore.com>

	PR target/91269
	* config/sparc/sparc.h (HARD_REGNO_CALLER_SAVE_MODE): Define.

Added:
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/pr91854.c
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/config/sparc/sparc.h
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 21 Matt Turner 2019-10-01 20:05:42 UTC
(In reply to Eric Botcazou from comment #16)
> > I believe the Known to work field is wrong and gcc-8.3.0 has this bug as
> > well.
> 
> No, the field is correct and you're wrong.

Funny how the fix for the gcc-8.3.0 branch was a backport of this patch!

Have some manners next time.
Comment 22 Eric Botcazou 2019-10-01 21:41:01 UTC
> Funny how the fix for the gcc-8.3.0 branch was a backport of this patch!

Nothing funny though, just an analysis of the behavior of the GCC 8 compiler with a testcase that triggers a failure; the original testcase linked to here didn't.
We cannot make changes on a release branch without a testcase, that's the rule.

> Have some manners next time.

Lecturing people doesn't make you right...