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.S    2021-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)

Reply via email to