Bug 43871 - -mcpu=power4 -mtune=cell emits power7/cell-only opcodes
Summary: -mcpu=power4 -mtune=cell emits power7/cell-only opcodes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Segher Boessenkool
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-04-23 19:01 UTC by marcus
Modified: 2018-01-16 16:51 UTC (History)
8 users (show)

See Also:
Host: powerpc-unknown-linux-gnu
Target: powerpc-unknown-linux-gnu
Build: powerpc-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2010-05-19 11:38:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description marcus 2010-04-23 19:01:26 UTC
my kernel does not boot anymore on a ppc970 (powermac g5) due to an illegal instruction caused by gcc 4.5

research showed that the DI bswap64 operation is optimized to ldbrx even on power4, but causes an sigill there.

gcc -m64 -c -O2 -mcpu=power4 -mtune=cell gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-3.c ; objdump -d optimize-bswapdi-3.o
0000000000000000 <.swap64_load>:
   0:   7c 00 1c 28     .long 0x7c001c28
   4:   7c 03 03 78     mr      r3,r0
   8:   4e 80 00 20     blr


while:

gcc -m64 -c -O2 -mcpu=power4 gcc/testsuite/gcc.target/powerpc/optimize-bswapdi-3.c ; objdump -d optimize-bswapdi-3.o
0000000000000000 <.swap64_load>:
   0:   39 20 00 04     li      r9,4
   4:   7c 00 1c 2c     lwbrx   r0,0,r3
   8:   7d 69 1c 2c     lwbrx   r11,r9,r3
   c:   79 6a 07 c6     rldicr  r10,r11,32,31
  10:   7d 4a 03 78     or      r10,r10,r0
  14:   7d 43 53 78     mr      r3,r10
  18:   4e 80 00 20     blr


-mcpu=power4 -mtune=cell should not start to emit opcodes invalid on power4.

I think the bswap64 emitter logic in config/rs6000/rs6000.md is incorrect
Comment 1 Andrew Pinski 2010-04-23 19:04:29 UTC
This was my fault to some extend; when I added =cell support I asked about if we should emit the cell instructions for -mtune= and the answer was that using -mtune=cell is most likely not going to be used.  In fact -mtune=cell most likely produce much slower code on most other processors because of the non use of the dot instructions (and other stuff).
Comment 2 marcus 2010-04-23 19:12:00 UTC
well, the kernel now does easier ... 

in arch/powerpc/Makefile:

ifeq ($(CONFIG_TUNE_CELL),y)
        KBUILD_CFLAGS += $(call cc-option,-mtune=cell)
endif
Comment 3 Richard Biener 2010-05-19 11:38:26 UTC
Confirmed.  Adding spu maintainers to CC.
Comment 4 Segher Boessenkool 2015-11-22 11:57:35 UTC
Still happens.  rs6000_cpu is set based on the -mtune= setting instead
of based on the -mcpu setting.  I'll take it.
Comment 5 Segher Boessenkool 2017-12-02 01:24:23 UTC
Author: segher
Date: Sat Dec  2 01:23:41 2017
New Revision: 255349

URL: https://gcc.gnu.org/viewcvs?rev=255349&root=gcc&view=rev
Log:
rs6000: Set rs6000_cpu correctly (PR43871)

We set rs6000_cpu based on tune_index, but it should be cpu_index.
This patch fixes it.


	PR target/43871
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Set
	rs6000_cpu based on cpu_index, not tune_index.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
Comment 6 Segher Boessenkool 2017-12-04 09:19:58 UTC
Author: segher
Date: Mon Dec  4 09:19:27 2017
New Revision: 255376

URL: https://gcc.gnu.org/viewcvs?rev=255376&root=gcc&view=rev
Log:

	PR bootstrap/83265
	Revert
	2017-12-01  Segher Boessenkool  <segher@kernel.crashing.org>

	PR target/43871
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Set
	rs6000_cpu based on cpu_index, not tune_index.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
Comment 7 Segher Boessenkool 2017-12-07 09:37:00 UTC
Author: segher
Date: Thu Dec  7 09:36:28 2017
New Revision: 255464

URL: https://gcc.gnu.org/viewcvs?rev=255464&root=gcc&view=rev
Log:
rs6000: Initialise rs6000_cpu correctly (PR43871)

Finally, set rs6000_cpu based not on -mtune=, but only -mcpu= and the
defaults.


	PR target/43871
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Set
	rs6000_cpu to the given -mcpu=, or to the default processor.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
Comment 8 Segher Boessenkool 2018-01-16 16:51:48 UTC
I would prefer not to backport this since it is quite involved.  Please
reopen if you have a good reason to want it on 7 or 6.