gcc 4.9.0-alpha20140406 segfaults when compiling the following code for target powerpc-e500v2-linux-gnuspe w/ optimization levels -O1 and above: int d7; static int ca(int l3) { for (d7 = 0; d7 < 1; ++d7) ; return l3; } int c9(void) { int yj; return ca(((yj != 1) & 65535U) > d7); } % powerpc-e500v2-linux-gnuspe-gcc -O1 -c 62931f03.c 62931f03.c: In function 'c9': 62931f03.c:16:1: internal compiler error: in validate_condition_mode, at config/rs6000/rs6000.c:15657
Another one: int kf(int a2, unsigned int dc) { int t3; int b1[2]; for (t3 = 0; t3 < 2; ++t3) b1[t3] = 2; return ((t3 > a2) >= b1[0]) < dc; }
(In reply to Arseny Solokha from comment #1) > Another one: > > int > kf(int a2, unsigned int dc) > { > int t3; > int b1[2]; > for (t3 = 0; t3 < 2; ++t3) > b1[t3] = 2; > return ((t3 > a2) >= b1[0]) < dc; > } Interestingly enough, it fails only w/ -O1.
void ds(void) { unsigned int t5; unsigned int re; int yn; int *o2; int *s0 = &yn; for (re = 0; re < 2; ++re) if (0 != t5) *o2 = (*s0 ^= 1) | (re = ((t5 < yn) >= (t5 > yn))); } fails in config/rs6000/rs6000.c:15654 (4.9.0 20140406) or config/rs6000/rs6000.c:15658 (4.10.0 20140411).
The state of things is currently as follows: 1. Snippets from comment 0 and comment 1 cannot be reproduced anymore w/ gcc 5.3.0 and 6.0.0-alpha20160110. 2. Snippet from comment 3 can be further reduced to unsigned int vz, tr, c, fr; void gi(void) { if (vz < 1) vz = ((fr < tr) >= (fr > tr)); } and fails w/ 4.8.5, 4.9.3, 5.3.0 at -Os, -O2, -O3, and -Ofast. 3. The following snippet fails w/ 5.3.0 and 6.0.0-alpha20160110 at -O1, -O2, -O3, -Ofast, and -Og: unsigned int ou; int jv(void) { unsigned int rg; return rg < ou; }
Confirmed. Can be seen on other powerpc targets with -mno-mfcrf -misel.
It's a combine bug. I am testing a patch.
Not a regression, postponed to GCC 7, last patch is at https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01303.html .
Segher, could you, please, finally decide on the future of the patch?
Thanks for reminding me Arseny.
Segher, can you update on the status of this PR, as the stage 1 apparently approaches to its end?
It's on my radar. All bugs can be fixed during stage3.
Hi! We just recently started seeing this issue in Debian, however, only for the powerpc-linux-gnuspe targets, i.e. e500v2 (Debian architecture: powerpcspe) [1]: g++ -c -g -O2 -fdebug-prefix-map=/<<BUILDDIR>>/qt4-x11-4.8.7+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++98 -I/usr/include/freetype2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/powerpc-linux-gnuspe/glib-2.0/include -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DELF_INTERPRETER=\"/lib/ld.so.1\" -DQLIBRARYINFO_EPOCROOT -DQT_USE_ICU -DHB_EXPORT=Q_CORE_EXPORT -DQT_NO_DEBUG -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include -I../../include/QtCore -I.rcc/release-shared -Iglobal -I../../tools/shared -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared -o .obj/release-shared/qtextboundaryfinder.o tools/qtextboundaryfinder.cpp tools/qtextboundaryfinder.cpp: In member function 'bool QTextBoundaryFinder::isAtBoundary() const': tools/qtextboundaryfinder.cpp:444:1: internal compiler error: in validate_condition_mode, at config/rs6000/rs6000.c:17958 } ^ 0x109c5aab validate_condition_mode(rtx_code, machine_mode) ../../src/gcc/config/rs6000/rs6000.c:17957 0x10b438df branch_comparison_operator(rtx_def*, machine_mode) ../../src/gcc/config/rs6000/predicates.md:1125 0x10b43b13 branch_positive_comparison_operator(rtx_def*, machine_mode) ../../src/gcc/config/rs6000/predicates.md:1204 0x10b5bad7 recog_72 ../../src/gcc/config/rs6000/altivec.md:643 0x10bb7f3b recog_for_combine_1 ../../src/gcc/combine.c:10945 0x10bbd4ff recog_for_combine ../../src/gcc/combine.c:11142 0x10bcb0c7 try_combine ../../src/gcc/combine.c:3503 0x10bcec7f combine_instructions ../../src/gcc/combine.c:1475 0x10bcec7f rest_of_handle_combine ../../src/gcc/combine.c:14356 0x10bcec7f execute ../../src/gcc/combine.c:14399 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions. g++ -c -g -O2 -fdebug-prefix-map=/<<BUILDDIR>>/qt4-x11-4.8.7+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++98 -I/usr/include/freetype2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/powerpc-linux-gnuspe/glib-2.0/include -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DELF_INTERPRETER=\"/lib/ld.so.1\" -DQLIBRARYINFO_EPOCROOT -DQT_USE_ICU -DHB_EXPORT=Q_CORE_EXPORT -DQT_NO_DEBUG -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include -I../../include/QtCore -I.rcc/release-shared -Iglobal -I../../tools/shared -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared -o .obj/release-shared/qtimeline.o tools/qtimeline.cpp g++ -c -g -O2 -fdebug-prefix-map=/<<BUILDDIR>>/qt4-x11-4.8.7+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=gnu++98 -I/usr/include/freetype2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/powerpc-linux-gnuspe/glib-2.0/include -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DELF_INTERPRETER=\"/lib/ld.so.1\" -DQLIBRARYINFO_EPOCROOT -DQT_USE_ICU -DHB_EXPORT=Q_CORE_EXPORT -DQT_NO_DEBUG -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include -I../../include/QtCore -I.rcc/release-shared -Iglobal -I../../tools/shared -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared -o .obj/release-shared/qvector.o tools/qvector.cpp Preprocessed source stored into /tmp/ccg5tpbm.out file, please attach this to your bugreport. I'm attaching the pre-processed source in case that might be useful. Odd that despite this bug being so old, it just surfaced on Debian powerpcspe recently. Thanks, Adrian > [1] https://buildd.debian.org/status/fetch.php?pkg=qt4-x11&arch=powerpcspe&ver=4%3A4.8.7%2Bdfsg-9&stamp=1476330034
Created attachment 39807 [details] Pre-processed source for tools/qtextboundaryfinder.cpp
I cannot get any of the testcases to fail with current trunk (but they do fail with GCC 6). Combine always merges the compare into the if_then_else pattern, and there are no such patterns in rs6000 (this could be done with a cmp+isel define_insn_and_split, and is probably a good idea, but we do not have that currently).
(In reply to Segher Boessenkool from comment #14) > I cannot get any of the testcases to fail with current trunk (but > they do fail with GCC 6). Combine always merges the compare into > the if_then_else pattern, and there are no such patterns in rs6000 > (this could be done with a cmp+isel define_insn_and_split, and is > probably a good idea, but we do not have that currently). OK, I'll post another one or two the next week. This is still reproducible on the trunk, but the actual code pattern causing the ICE seems to be a moving target.
Also still reproducible in Debian. LibreOffice just failed to build with the same problem [1]: S=/<<PKGBUILDDIR>> && I=$S/instdir && W=$S/workdir && mkdir -p $W/CxxObject/tools/source/generic/ $W/Dep/CxxObject/tools/source/generic/ && cd /<<PKGBUILDDIR>> && powerpc-linux-gnuspe-g++ -DBOOST_ERROR_CODE_HEADER_ONLY -DBOOST_SYSTEM_NO_DEPRECATED -DCPPU_ENV=gcc3 -DLINUX -DNDEBUG -DOPTIMIZE -DOSL_DEBUG_LEVEL=0 -DPOWERPC -DPPC -DUNIX -DUNX -D_FORTIFY_SOURCE=2 -D_PTHREADS -D_REENTRANT -Wdate-time -Wdate-time -D_FORTIFY_SOURCE=2 -DTOOLS_DLLIMPLEMENTATION -DSYSTEM_ZLIB -DHAVE_GCC_VISIBILITY_FEATURE -fvisibility=hidden -Wall -Wno-missing-braces -Wnon-virtual-dtor -Wendif-labels -Wextra -Wundef -Wunused-macros -fmessage-length=0 -fno-common -pipe -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshift-overflow=2 -Wunused-const-variable=1 -fvisibility-inlines-hidden -fPIC -Wshadow -Woverloaded-virtual -std=gnu++14 -g1 -DEXCEPTIONS_ON -fexceptions -fno-enforce-eh-specs -g1 -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -DLIBO_INTERNAL_ONLY -c $S/tools/source/generic/config.cxx -o $W/CxxObject/tools/source/generic/config.o -MMD -MT $W/CxxObject/tools/source/generic/config.o -MP -MF $W/Dep/CxxObject/tools/source/generic/config.d_ -I$S/tools/source/generic/ -I$S/tools/inc -I$S/include -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux -I$S/config_host -I$W/UnoApiHeadersTarget/udkapi/normal -I$W/UnoApiHeadersTarget/offapi/normal -I/usr/include && mv $W/Dep/CxxObject/tools/source/generic/config.d_ $W/Dep/CxxObject/tools/source/generic/config.d [build CXX] tools/source/generic/fract.cxx /<<PKGBUILDDIR>>/tools/source/generic/color.cxx: In member function 'bool Color::IsBright() const': /<<PKGBUILDDIR>>/tools/source/generic/color.cxx:112:1: internal compiler error: in validate_condition_mode, at config/rs6000/rs6000.c:18014 } ^ > [1] https://buildd.debian.org/status/fetch.php?pkg=libreoffice&arch=powerpcspe&ver=1%3A5.2.6-2&stamp=1490096724&raw=0
(In reply to Arseny Solokha from comment #15) > (In reply to Segher Boessenkool from comment #14) > > I cannot get any of the testcases to fail with current trunk (but > > they do fail with GCC 6). Combine always merges the compare into > > the if_then_else pattern, and there are no such patterns in rs6000 > > (this could be done with a cmp+isel define_insn_and_split, and is > > probably a good idea, but we do not have that currently). > > OK, I'll post another one or two the next week. This is still reproducible > on the trunk, but the actual code pattern causing the ICE seems to be a > moving target. int no; void gn (int d3) { while (no != 0) { if ((no > d3) > (no < d3)) ++no; while (d3 != 0) { } } } % powerpc-e300c3-linux-gnu-gcc-7.0.0-alpha20170326 -misel -Os -w -c qb3j6i03.c qb3j6i03.c: In function 'gn': qb3j6i03.c:15:1: internal compiler error: in validate_condition_mode, at config/rs6000/rs6000.c:20752 } ^ 0x2b53add47a3 validate_condition_mode(rtx_code, machine_mode) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/rs6000.c:20751 0x2b53b0171a7 branch_comparison_operator(rtx_def*, machine_mode) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/predicates.md:1243 0x2b53b01731b scc_rev_comparison_operator(rtx_def*, machine_mode) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/predicates.md:1300 0x2b53b0362d4 recog_10 /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/rs6000.md:344 0x2b53b0362d4 recog_11 /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/altivec.md:224 0x2b53b0362d4 recog_12 /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/rs6000.md:5090 0x2b53b0703e5 recog_137 /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/config/rs6000/altivec.md:1760 0x2b53b09ff2b recog_for_combine_1 /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:11145 0x2b53b0a6aed recog_for_combine /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:11401 0x2b53b0b2601 try_combine /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:4033 0x2b53b0b8ea0 combine_instructions /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:1372 0x2b53b0b8ea0 rest_of_handle_combine /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:14650 0x2b53b0b8ea0 execute /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-7.0.0_alpha20170326/work/gcc-7-20170326/gcc/combine.c:14695 The same for powerpc-e500v2-linux-gnuspe. As before, toggling -fPIC may be necessary as well.
Okay, this I can reproduce (no -fPIC needed, not even -m32). Thanks!
Yes, r246294 powerpc64le-linux-gcc -O1 -misel ICEs on the last testcase. An earlier compiler I had laying around, 7.0.0 20160616, does not.
(In reply to Alan Modra from comment #19) > Yes, r246294 powerpc64le-linux-gcc -O1 -misel ICEs on the last testcase. An > earlier compiler I had laying around, 7.0.0 20160616, does not. Here's a simplified version, then (-misel -Os): int lx (int oi, int mb) { return (oi < mb) < (mb < oi); } Note that this snippet as well as one from comment 17 both have comparison patterns similar to those from snippets in comment 3 and comment 4.
You don't even need -Os for this last testcase, only -misel.
The combination that makes it die is: Trying 18, 17 -> 19: Successfully matched this instruction: (set (reg:CC 176) (reg:CC 164)) Where insn 18 is (set (reg:SI 174) (gt:SI (reg:CC 164) (const_int 0 [0]))) and insn 17 is (set (reg:SI 173) (lt:SI (reg:CC 164) (const_int 0 [0]))) and insn 19 is (insn 19 18 22 2 (set (reg:CCUNS 176) (compare:CCUNS (reg:SI 173) (reg:SI 174))) "60818-19.c":4 772 {*cmpsi_unsigned} (expr_list:REG_DEAD (reg:SI 174) (expr_list:REG_DEAD (reg:SI 173) (nil)))) the combined insn should not simply copy the CC (it needs to swap the greater-than and smaller-than results), and it needs to return a CCUNS anyway. Where did this come from...
I have a patch for the problem in comments 17 and 19 (which is different from the problems in earlier comments, only some of which i can reproduce).
Author: segher Date: Tue Apr 4 00:10:02 2017 New Revision: 246666 URL: https://gcc.gnu.org/viewcvs?rev=246666&root=gcc&view=rev Log: simplify-rtx: Fix compare of comparisons (PR60818) The function simplify_binary_operation_1 has code that does /* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags). */ but this transformation is only valid if "flags" has the same machine mode as the outer compare. This fixes it. PR rtl-optimization/60818 * simplify-rtx.c (simplify_binary_operation_1): Do not replace a compare of comparisons with the thing compared if this results in a different machine mode. gcc/testsuite/ PR rtl-optimization/60818 * gcc.c-torture/compile/pr60818.c: New testcase. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr60818.c Modified: trunk/gcc/ChangeLog trunk/gcc/simplify-rtx.c trunk/gcc/testsuite/ChangeLog
Hi Segher! Your patch fixes the issue for me. I had issues building ghc on powerpcspe. With gcc-6 it failed in the expected way, with gcc-7, it went past the problematic source code file. Would it be possible that your backport your fix to the gcc-6 branch so we can use it in the current Debian release? Thanks, Adrian
GCC 7.1 has been released.
(In reply to Jakub Jelinek from comment #26) > GCC 7.1 has been released. At least for me, the bug has been fixed with Segher's patch, so I'm not sure if pushing the milestone to 7.2 makes sense.
Author: segher Date: Tue Jun 27 17:11:01 2017 New Revision: 249700 URL: https://gcc.gnu.org/viewcvs?rev=249700&root=gcc&view=rev Log: Backports from trunk: 2016-08-15 Segher Boessenkool <segher@kernel.crashing.org> PR rtl-optimization/73650 * lra-constraints.c (simple_move_p): If the insn is multiple_sets it is not a simple move. 2017-01-20 Segher Boessenkool <segher@kernel.crashing.org> PR target/61729 PR target/77850 * config/rs6000/rs6000.c (rs6000_gimplify_va_arg): Adjust address to read from, for big endian. 2017-04-04 Segher Boessenkool <segher@kernel.crashing.org> PR rtl-optimization/60818 * simplify-rtx.c (simplify_binary_operation_1): Do not replace a compare of comparisons with the thing compared if this results in a different machine mode. 2017-04-12 Segher Boessenkool <segher@kernel.crashing.org> PR target/80382 * config/rs6000/sync.md (atomic_load<mode>, atomic_store<mode): Test for quad_address_p for TImode, instead of just not indexed_address. 2017-04-19 Segher Boessenkool <segher@kernel.crashing.org> PR rtl-optimization/80429 * ira.c (split_live_ranges_for_shrink_wrap): Don't split regs that are only used in debug insns. 2017-05-17 Segher Boessenkool <segher@kernel.crashing.org> PR middle-end/80692 * real.c (do_compare): Give decimal_do_compare preference over comparing just the signs. 2017-05-31 Segher Boessenkool <segher@kernel.crashing.org> PR target/80618 * config/rs6000/vector.md (*vector_uneq<mode>): Write the nor in the splitter result in the canonical way. 2017-06-09 Segher Boessenkool <segher@kernel.crashing.org> PR target/80966 * config/rs6000/rs6000.c (rs6000_emit_allocate_stack): Assert that gen_add3_insn did not fail. * config/rs6000/rs6000.md (add<mode>3): If asked to add a constant to r0, construct that number in a temporary reg and add that reg to r0. If asked to put the result in r0 as well, fail. 2017-06-23 Segher Boessenkool <segher@kernel.crashing.org> PR middle-end/80902 * builtins.c (expand_builtin_atomic_fetch_op): If emitting code after a call, force the call to not be a tail call. gcc/testsuite/ Backports from trunk: 2017-04-04 Segher Boessenkool <segher@kernel.crashing.org> PR rtl-optimization/60818 * gcc.c-torture/compile/pr60818.c: New testcase. 2017-05-17 Segher Boessenkool <segher@kernel.crashing.org> PR middle-end/80692 * gcc.c-torture/execute/pr80692.c: New testcase. 2017-06-09 Segher Boessenkool <segher@kernel.crashing.org> PR target/80966 * gcc.target/powerpc/stack-limit.c: New testcase. Added: branches/gcc-6-branch/gcc/testsuite/gcc.c-torture/compile/pr60818.c branches/gcc-6-branch/gcc/testsuite/gcc.c-torture/execute/pr80692.c branches/gcc-6-branch/gcc/testsuite/gcc.target/powerpc/stack-limit.c Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/builtins.c branches/gcc-6-branch/gcc/config/rs6000/rs6000.c branches/gcc-6-branch/gcc/config/rs6000/rs6000.md branches/gcc-6-branch/gcc/config/rs6000/sync.md branches/gcc-6-branch/gcc/config/rs6000/vector.md branches/gcc-6-branch/gcc/ira.c branches/gcc-6-branch/gcc/lra-constraints.c branches/gcc-6-branch/gcc/real.c branches/gcc-6-branch/gcc/simplify-rtx.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
Is there anything left to do here? Or can this PR be closed.
(In reply to Segher Boessenkool from comment #29) > Is there anything left to do here? Or can this PR be closed. As both LibreOffice and GHC now build without issues on Debian powerpcspe with gcc-7 as the default compiler, I think it's safe to assume that the bug has been fixed. I think it did still occur with gcc-6 though although I'm not sure anymore. Either way, gcc-7 works correctly.
Okay, closing then (the patch has been backported to 6, too). Thanks!