Bug 100108

Summary: [10 Regression] powerpc: recognize 32-bit CPU as POWER9 with -misel option
Product: gcc Reporter: Rin Okuyama <rin>
Component: targetAssignee: Segher Boessenkool <segher>
Status: RESOLVED FIXED    
Severity: normal CC: dje, jakub, rin, segher
Priority: P3    
Version: 10.3.0   
Target Milestone: 10.4   
Host: Target: powerpc
Build: Known to work: 9.3.0
Known to fail: 10.3.0 Last reconfirmed: 2021-04-19 00:00:00
Attachments: Fix for this regression
Proposed simpler patch

Description Rin Okuyama 2021-04-16 02:02:23 UTC
Created attachment 50609 [details]
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)
Comment 1 Andrew Pinski 2021-04-16 13:16:28 UTC
e500 support had been moved to the powerpcspe target; so assuming power9 for -misel is correct.

e500mc support is still there though.
Comment 2 Rin Okuyama 2021-04-16 13:50:17 UTC
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
Comment 3 Jakub Jelinek 2021-04-19 14:32:44 UTC
Indeed, several rs6000-cpus.def entries have MASK_ISEL:
RS6000_CPU ("8540", PROCESSOR_PPC8540, MASK_STRICT_ALIGN | MASK_ISEL)
RS6000_CPU ("8548", PROCESSOR_PPC8548, MASK_STRICT_ALIGN | MASK_ISEL)
RS6000_CPU ("e500mc", PROCESSOR_PPCE500MC, MASK_PPC_GFXOPT | MASK_ISEL)
RS6000_CPU ("e500mc64", PROCESSOR_PPCE500MC64,
            MASK_POWERPC64 | MASK_PPC_GFXOPT | MASK_ISEL)
RS6000_CPU ("e5500", PROCESSOR_PPCE5500,
            MASK_POWERPC64 | MASK_PPC_GFXOPT | MASK_ISEL)
RS6000_CPU ("e6500", PROCESSOR_PPCE6500, POWERPC_7400_MASK | MASK_POWERPC64
            | MASK_MFCRF | MASK_ISEL)


So perhaps we should consider MASK_ISEL as power9 thing only for flags which include power7-ish or later ISAs?
--- rs6000.c.jj4	2021-04-09 10:18:15.582266372 +0200
+++ rs6000.c	2021-04-19 16:30:07.033208577 +0200
@@ -5766,6 +5766,9 @@ rs6000_machine_from_flags (void)
 
   /* Disable the flags that should never influence the .machine selection.  */
   flags &= ~(OPTION_MASK_PPC_GFXOPT | OPTION_MASK_PPC_GPOPT);
+  if ((flags & (ISA_3_1_MASKS_SERVER
+		& ~(ISA_2_5_MASKS_SERVER | MASK_ISEL))) == 0)
+    flags &= ~MASK_ISEL;
 
   if ((flags & (ISA_3_1_MASKS_SERVER & ~ISA_3_0_MASKS_SERVER)) != 0)
     return "power10";
Comment 4 Segher Boessenkool 2021-04-19 14:52:30 UTC
(In reply to Andrew Pinski from comment #1)
> e500 support had been moved to the powerpcspe target; so assuming power9 for
> -misel is correct.
> 
> e500mc support is still there though.

There never *was* separate e500 support in GCC!
Comment 5 Segher Boessenkool 2021-04-19 14:59:22 UTC
Created attachment 50629 [details]
Proposed simpler patch

A simpler patch.  I'll commit this later today (if no one stops me).
Comment 6 Jakub Jelinek 2021-04-19 15:03:29 UTC
LGTM.
Comment 7 Rin Okuyama 2021-04-20 01:02:19 UTC
Thank you for discussion. The proposed patch works fine for me (except for missing ``;'' at the end of the line).
Comment 8 GCC Commits 2021-04-20 13:43:58 UTC
The master branch has been updated by Segher Boessenkool <segher@gcc.gnu.org>:

https://gcc.gnu.org/g:6156df483fa50a08f561b6c248819f2992aa380d

commit r12-9-g6156df483fa50a08f561b6c248819f2992aa380d
Author: Segher Boessenkool <segher@kernel.crashing.org>
Date:   Tue Apr 20 12:00:50 2021 +0000

    rs6000: Fix cpu selection w/ isel (PR100108)
    
    There are various non-IBM CPUs with isel as well, so it is easiest if we
    just don't consider that flag here (it is not needed).
    
    2021-04-20  Segher Boessenkool  <segher@kernel.crashing.org>
    
            PR target/100108
            * config/rs6000/rs6000.c (rs6000_machine_from_flags): Do not consider
            OPTION_MASK_ISEL.
Comment 9 GCC Commits 2021-04-20 13:55:25 UTC
The releases/gcc-11 branch has been updated by Segher Boessenkool <segher@gcc.gnu.org>:

https://gcc.gnu.org/g:8bd3b0c11cb08f63d2ca41a21596d16635626661

commit r11-8264-g8bd3b0c11cb08f63d2ca41a21596d16635626661
Author: Segher Boessenkool <segher@kernel.crashing.org>
Date:   Tue Apr 20 12:00:50 2021 +0000

    rs6000: Fix cpu selection w/ isel (PR100108)
    
    There are various non-IBM CPUs with isel as well, so it is easiest if we
    just don't consider that flag here (it is not needed).
    
    2021-04-20  Segher Boessenkool  <segher@kernel.crashing.org>
    
            PR target/100108
            * config/rs6000/rs6000.c (rs6000_machine_from_flags): Do not consider
            OPTION_MASK_ISEL.
    
    (cherry picked from commit 6156df483fa50a08f561b6c248819f2992aa380d)
Comment 10 Segher Boessenkool 2021-04-20 14:58:41 UTC
Fixed on trunk and 11.  Will do 10 in a week or so.
Comment 11 Rin Okuyama 2021-04-22 00:49:24 UTC
Segher, let me thank you again!
Comment 12 GCC Commits 2021-05-10 22:00:39 UTC
The releases/gcc-10 branch has been updated by Segher Boessenkool <segher@gcc.gnu.org>:

https://gcc.gnu.org/g:5f665c1ca452673e9812cd92b07bd31441c0ac5b

commit r10-9814-g5f665c1ca452673e9812cd92b07bd31441c0ac5b
Author: Segher Boessenkool <segher@kernel.crashing.org>
Date:   Tue Apr 20 12:00:50 2021 +0000

    rs6000: Fix cpu selection w/ isel (PR100108)
    
    There are various non-IBM CPUs with isel as well, so it is easiest if we
    just don't consider that flag here (it is not needed).
    
    2021-04-20  Segher Boessenkool  <segher@kernel.crashing.org>
    
            PR target/100108
            * config/rs6000/rs6000.c (rs6000_machine_from_flags): Do not consider
            OPTION_MASK_ISEL.
    
    (cherry picked from commit 6156df483fa50a08f561b6c248819f2992aa380d)
Comment 13 Segher Boessenkool 2021-05-10 22:01:29 UTC
Fixed on GCC 10 and later.  Closing.