Bug 70188 - [4.9/5/6 Regression] gcc 4.9+ miscompiles code on hppa
Summary: [4.9/5/6 Regression] gcc 4.9+ miscompiles code on hppa
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.4
: P4 normal
Target Milestone: 4.9.4
Assignee: Not yet assigned to anyone
URL: https://patchwork.kernel.org/patch/84...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-03-11 14:43 UTC by deller
Modified: 2016-04-06 16:06 UTC (History)
3 users (show)

See Also:
Host:
Target: hppa64-linux-gnu-gcc
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-03-12 00:00:00


Attachments
preprocessed source (171.09 KB, application/x-compressed-tar)
2016-03-11 14:46 UTC, deller
Details
blk-merge.c preprocessed source (184.89 KB, application/x-gzip)
2016-03-13 20:58 UTC, John David Anglin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description deller 2016-03-11 14:43:05 UTC
Linux kernels above 4.3 don't boot any longer when compiled with gcc-4.9 or gcc-5.
After some analysis, it seems gcc miscompiles the function blk_bio_segment_split() in block/blk-merge.c.  Compiling this function with -O0 or -O1 does produce a functional Linux kernel, but when compiled with -O2 the kernel crashes during SCSI detection.

I was able to extract the function from the kernel source and attached is a preprocessed file for easier analysis. It seems the variables bvprv and/or bvprvp get optimized out when compiled with -O2.

This command is used to compile the file:

hppa64-linux-gnu-gcc-4.9 -Wp,-MD,block/.blk-merge_part.o.d  -nostdinc -isystem /usr/lib/gcc/hppa64-linux-gnu/4.9/include -I/build/linux/linux-4.4.4/arch/parisc/include -Iarch/parisc/include/generated/uapi -Iarch/parisc/include/generated  -I/build/linux/linux-4.4.4/include -Iinclude -I/build/linux/linux-4.4.4/arch/parisc/include/uapi -Iarch/parisc/include/generated/uapi -I/build/linux/linux-4.4.4/include/uapi -Iinclude/generated/uapi -include /build/linux/linux-4.4.4/include/linux/kconfig.h  -I/build/linux/linux-4.4.4/block -Iblock -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -pipe -mno-space-regs -mdisable-fpregs -ffunction-sections -march=2.0 -mschedule=8000 -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DCC_HAVE_ASM_GOTO    -fno-cse-follow-jumps -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(blk_merge_part)"  -D"KBUILD_MODNAME=KBUILD_STR(blk_merge_part)" -c -o block/.tmp_blk-merge_part.o /build/linux/linux-4.4.4/block/blk-merge_part.c
Comment 1 deller 2016-03-11 14:46:03 UTC
Created attachment 37939 [details]
preprocessed source
Comment 2 John David Anglin 2016-03-11 14:51:34 UTC
Problem doesn't occur with Debian hppa64-linux-gnu-gcc-4.8.
Comment 3 John David Anglin 2016-03-12 17:14:45 UTC
Adding "-fno-ipa-sra" at -O2 results in same assembler code as -O1.  "-fipa-sra" appears to break the iteration in this function.  The problem is not with "bvprv and/or bvprvp".
Comment 4 John David Anglin 2016-03-12 17:49:51 UTC
Maybe related to <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65932>.
Comment 5 John David Anglin 2016-03-13 20:58:56 UTC
Created attachment 37952 [details]
blk-merge.c preprocessed source

I've added the preprocessed for blk-merge.c.  Although the wrong code appears to be in blk_bio_segment_split(), The -fno-ipa-sra option didn't fix the problem.  Further, the problem appears with blk-merge.c compiled at both -O1 and -O2.  Boot is successful when it is compiled at -O0.

Try to find 4.9 regression.  So far, range has been reduced to r220635 to r221480.
Comment 6 deller 2016-03-13 21:07:27 UTC
Hi Dave,

On 13.03.2016 21:58, danglin at gcc dot gnu.org wrote:
> Try to find 4.9 regression.  So far, range has been reduced to r220635 to r221480.

So, it compiles correctly with r220635 ?
Is that then a gcc-4.8 or gcc-4.9 ?

Helge
Comment 7 Jeffrey A. Law 2016-03-14 07:08:48 UTC
Unlikely related to 69532 -- the PA port is consistent WRT PROMOTE_MODE and friends IIRC.

I'm leaving as P3 until we have this better analyzed though.
Comment 8 John David Anglin 2016-03-15 01:25:13 UTC
Culprit is constraints.md hunk in r220681 (4.9 branch).  On hppa, it's
not possible to reload all memory operands to a base register.  So, we
can't use define_memory_constraint for the Q and T constraints.

Reverting fixes kernel build.
Comment 9 John David Anglin 2016-03-17 22:49:46 UTC
Author: danglin
Date: Thu Mar 17 22:49:15 2016
New Revision: 234308

URL: https://gcc.gnu.org/viewcvs?rev=234308&root=gcc&view=rev
Log:
	PR target/70188
	* config/pa/constraints.md: Revert 2015-02-13 change.  Use
	define_constraint for "Q" and "T" constraints.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/pa/constraints.md
Comment 10 John David Anglin 2016-03-17 22:56:10 UTC
Author: danglin
Date: Thu Mar 17 22:55:38 2016
New Revision: 234310

URL: https://gcc.gnu.org/viewcvs?rev=234310&root=gcc&view=rev
Log:
	PR target/70188
	* config/pa/constraints.md: Revert 2015-02-13 change.  Use
	define_constraint for "Q" and "T" constraints.


Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/config/pa/constraints.md
Comment 11 John David Anglin 2016-03-17 22:57:51 UTC
Author: danglin
Date: Thu Mar 17 22:57:19 2016
New Revision: 234311

URL: https://gcc.gnu.org/viewcvs?rev=234311&root=gcc&view=rev
Log:
	PR target/70188
	* config/pa/constraints.md: Revert 2015-02-13 change.  Use
	define_constraint for "Q" and "T" constraints.


Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/pa/constraints.md
Comment 12 John David Anglin 2016-03-17 23:40:46 UTC
64-bit Debian 4.4.4-2+b1 kernel booted successfully on c3750.