Bug 71020 - [6 Regression] SSA corruption: Unable to coalesce ssa_names 2 and 13 which are marked as MUST COALESCE.
Summary: [6 Regression] SSA corruption: Unable to coalesce ssa_names 2 and 13 which ar...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.1.1
: P2 normal
Target Milestone: 7.0
Assignee: Richard Sandiford
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2016-05-09 11:28 UTC by Peter De Wachter
Modified: 2018-10-26 10:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.3.0, 7.0
Known to fail:
Last reconfirmed: 2016-05-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter De Wachter 2016-05-09 11:28:03 UTC
This function triggers an internal compiler error. Reduced using C-Reduce from a source file from FMSLogo.

$ cat ssa2.c
binary() {
  double b = get();
  _setjmp();
  b = sqrt(b);
  err_logo();
}

$ gcc-6 -O -w -c ssa2.c

Unable to coalesce ssa_names 2 and 13 which are marked as MUST COALESCE.
b_2(ab) and  b_13(ab)
ssa2.c: In function ‘binary’:
ssa2.c:1:1: internal compiler error: SSA corruption
 binary() {
 ^~~~~~
0xa90f9c fail_abnormal_edge_coalesce
	../../src/gcc/tree-ssa-coalesce.c:1010
0xa90f9c coalesce_partitions
	../../src/gcc/tree-ssa-coalesce.c:1411
0xa90f9c coalesce_ssa_name()
	../../src/gcc/tree-ssa-coalesce.c:1895
0xa4798f remove_ssa_form
	../../src/gcc/tree-outof-ssa.c:978
0xa4798f rewrite_out_of_ssa(ssaexpand*)
	../../src/gcc/tree-outof-ssa.c:1202
0x69b2e0 execute
	../../src/gcc/cfgexpand.c:6136
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.

$ gcc-6 -v
Using built-in specs.
COLLECT_GCC=gcc-6
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.1.1-1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.1.1 20160430 (Debian 6.1.1-1)
Comment 1 Richard Biener 2016-05-09 11:47:08 UTC
Confirmed.
Comment 2 Richard Biener 2016-05-09 11:57:37 UTC
  b_13(ab) = SQRT (b_1(ab));
  DCE_COND_LB.2_15 = b_1(ab);
  if (DCE_COND_LB.2_15 u>= 0.0)

introduced by cdce.  Likely triggered by Richards changes.  We have

  <bb 4>:
  # b_1(ab) = PHI <b_9(3), b_2(ab)(5)>
  _setjmp ();
  b_13(ab) = sqrt (b_1(ab));
  err_logo ();
  goto <bb 6>;

where one way to fix this is push b_1(ab) to a non-abnormal temporary
before the call and re-use that.  Or simply give up for example
via checking for abnormal SSA call arguments in an appropriate place.
Comment 3 Richard Sandiford 2016-05-14 17:49:16 UTC
Working on a fix
Comment 4 Richard Sandiford 2016-05-18 14:02:03 UTC
Author: rsandifo
Date: Wed May 18 14:01:31 2016
New Revision: 236393

URL: https://gcc.gnu.org/viewcvs?rev=236393&root=gcc&view=rev
Log:
To: gcc-patches@gcc.gnu.org
Subject: PR 71020: Handle abnormal PHIs in tree-call-cdce.c
From: Richard Sandiford <richard.sandiford@arm.com>
Gcc: private.sent
--text follows this line--
The PR is about a case where tree-call-cdce.c causes two abnormal
PHIs for the same variable to be live at the same time, leading to
a coalescing failure.  It seemed like getting rid of these kinds of
input would be generally useful, so I added a utility to tree-dfa.c.

Tested on x86_64-linux-gnu.

gcc/
	PR middle-end/71020
	* tree-dfa.h (replace_abnormal_ssa_names): Declare.
	* tree-dfa.c (replace_abnormal_ssa_names): New function.
	* tree-call-cdce.c: Include tree-dfa.h.
	(can_guard_call_p): New function, extracted from...
	(can_use_internal_fn): ...here.
	(shrink_wrap_one_built_in_call_with_conds): Remove failure path
	and return void.
	(shrink_wrap_one_built_in_call): Likewise.
	(use_internal_fn): Likewise.
	(shrink_wrap_conditional_dead_built_in_calls): Update accordingly
	and return void.  Call replace_abnormal_ssa_names.
	(pass_call_cdce::execute): Check can_guard_call_p during the
	initial walk.  Assume shrink_wrap_conditional_dead_built_in_calls
	will always change something.

gcc/testsuite/
	* gcc.dg/torture/pr71020.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr71020.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-call-cdce.c
    trunk/gcc/tree-dfa.c
    trunk/gcc/tree-dfa.h
Comment 5 Andrew Pinski 2016-07-04 06:49:17 UTC
Fixed on the trunk so far.
Comment 6 Richard Biener 2016-08-22 08:08:32 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 7 Richard Biener 2016-08-22 08:09:25 UTC
GCC 6.2 is being released, adjusting target milestone.
Comment 8 Jakub Jelinek 2016-12-21 10:54:45 UTC
GCC 6.3 is being released, adjusting target milestone.
Comment 9 Richard Biener 2017-07-04 08:42:50 UTC
GCC 6.4 is being released, adjusting target milestone.
Comment 10 Eric Gallager 2018-10-12 11:28:59 UTC
(In reply to rsandifo@gcc.gnu.org from comment #4)
> Author: rsandifo
> Date: Wed May 18 14:01:31 2016
> New Revision: 236393
> 
> URL: https://gcc.gnu.org/viewcvs?rev=236393&root=gcc&view=rev
> Log:
> To: gcc-patches@gcc.gnu.org
> Subject: PR 71020: Handle abnormal PHIs in tree-call-cdce.c
> From: Richard Sandiford <richard.sandiford@arm.com>
> Gcc: private.sent
> --text follows this line--
> The PR is about a case where tree-call-cdce.c causes two abnormal
> PHIs for the same variable to be live at the same time, leading to
> a coalescing failure.  It seemed like getting rid of these kinds of
> input would be generally useful, so I added a utility to tree-dfa.c.
> 
> Tested on x86_64-linux-gnu.
> 
> gcc/
> 	PR middle-end/71020
> 	* tree-dfa.h (replace_abnormal_ssa_names): Declare.
> 	* tree-dfa.c (replace_abnormal_ssa_names): New function.
> 	* tree-call-cdce.c: Include tree-dfa.h.
> 	(can_guard_call_p): New function, extracted from...
> 	(can_use_internal_fn): ...here.
> 	(shrink_wrap_one_built_in_call_with_conds): Remove failure path
> 	and return void.
> 	(shrink_wrap_one_built_in_call): Likewise.
> 	(use_internal_fn): Likewise.
> 	(shrink_wrap_conditional_dead_built_in_calls): Update accordingly
> 	and return void.  Call replace_abnormal_ssa_names.
> 	(pass_call_cdce::execute): Check can_guard_call_p during the
> 	initial walk.  Assume shrink_wrap_conditional_dead_built_in_calls
> 	will always change something.
> 
> gcc/testsuite/
> 	* gcc.dg/torture/pr71020.c: New test.
> 
> Added:
>     trunk/gcc/testsuite/gcc.dg/torture/pr71020.c
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/testsuite/ChangeLog
>     trunk/gcc/tree-call-cdce.c
>     trunk/gcc/tree-dfa.c
>     trunk/gcc/tree-dfa.h

Last chance to backport this to 6-branch
Comment 11 Jakub Jelinek 2018-10-26 10:50:44 UTC
GCC 6 branch is being closed, fixed in 7.x.