Bug 57517 - [4.7 Regression] internal compiler error: in eliminate_temp_copies, at tree-predcom.c:1913
Summary: [4.7 Regression] internal compiler error: in eliminate_temp_copies, at tree-p...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.1
: P2 normal
Target Milestone: 4.7.4
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-03 17:25 UTC by Steve Decker
Modified: 2014-03-18 08:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.4.7, 4.8.3, 4.9.0
Known to fail: 4.5.4, 4.6.4, 4.7.2, 4.8.0, 4.8.2, 4.9.0
Last reconfirmed: 2013-10-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Decker 2013-06-03 17:25:34 UTC
The following code compiles at O2, but not O3.

~/test > gfortran481 -O3 -c module_diffusion_em.f90
module_diffusion_em.f90: In function ‘cal_helicity’:
module_diffusion_em.f90:1:0: internal compiler error: in eliminate_temp_copies, at tree-predcom.c:1913
 SUBROUTINE cal_helicity (uh, ph, phb, ht, ims, ime, jms, jme, kms, kme,  &
 ^
0xc81b7a eliminate_temp_copies
	../../gcc-4.8.1/gcc/tree-predcom.c:1913
0xc81b7a tree_predictive_commoning_loop
	../../gcc-4.8.1/gcc/tree-predcom.c:2519
0xc82277 tree_predictive_commoning()
	../../gcc-4.8.1/gcc/tree-predcom.c:2554
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

~/test > cat module_diffusion_em.f90
SUBROUTINE cal_helicity (uh, ph, phb, ht, ims, ime, jms, jme, kms, kme,  &
     its, ite, jts, jte, kts, kte)
  INTEGER, INTENT( IN ) :: ims, ime, jms, jme, kms, kme,  &
       its, ite, jts, jte, kts, kte
  REAL, DIMENSION( ims:ime , jms:jme ), INTENT( IN ) :: ht
  REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( IN ) :: ph, phb
  REAL, DIMENSION( ims:ime, jms:jme ), INTENT( INOUT ) :: uh
  INTEGER :: i, j, k, ktf, i_start, i_end, j_start, j_end
  REAL :: zl, zu
  REAL, DIMENSION( its-2:ite+2, kts:kte, jts-2:jte+2 ) :: wavg, rvort
  real, parameter :: g = 9.81
  DO j = j_start, j_end
     DO k = kts, ktf
        DO i = i_start, i_end
           zu =  (( ph(i ,k+1,j ) + phb(i ,k+1,j ) ) / g - ht(i ,j ) ) + &
                (( ph(i-1,k+1,j ) + phb(i-1,k+1,j ) ) / g - ht(i-1,j ) ) + &
                (( ph(i ,k+1,j-1) + phb(i ,k+1,j-1) ) / g - ht(i ,j-1) )
           IF ( zl .GE. 2000. .AND. zu .LE. 5000. ) THEN
              IF ( wavg(i,k,j) .GT. 0. .AND. wavg(i,k+1,j) .GT. 0. ) THEN
                 uh(i,j) = uh(i,j) + ( wavg(i,k,j) * rvort(i,k,j) + &
                      wavg(i,k+1,j) * rvort(i,k+1,j) )  * ( zu - zl )
              ENDIF
           ENDIF
        END DO
     END DO
  END DO
END SUBROUTINE cal_helicity

~/test > gfortran481 -v
Using built-in specs.
COLLECT_GCC=/home/decker/local/gcc481/bin/gfortran481
COLLECT_LTO_WRAPPER=/home/decker/local/gcc481/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.1/configure --prefix=/home/decker/local/gcc481 --program-suffix=481 --enable-languages=c,c++,fortran --with-gmp=/home/decker/local --with-mpfr=/home/decker/local --with-mpc=/home/decker/local --with-isl=/home/decker/local --with-cloog=/home/decker/local
Thread model: posix
gcc version 4.8.1 (GCC)
Comment 1 Richard Biener 2013-10-30 12:50:05 UTC
Confirmed.

> ./f951  -quiet t.f90 -O3  
t.f90: In function 'cal_helicity':
t.f90:1:0: error: definition in block 9 does not dominate use in block 35
 SUBROUTINE cal_helicity (uh, ph, phb, ht, ims, ime, jms, jme, kms, kme,  &
 ^
for SSA_NAME: D_lsm0.70_121 in statement:
D_lsm0.70_120 = PHI <_314(33), D_lsm0.70_121(35)>
PHI argument
D_lsm0.70_121
for PHI node
D_lsm0.70_120 = PHI <_314(33), D_lsm0.70_121(35)>
t.f90:1:0: internal compiler error: verify_ssa failed
0xe45652 verify_ssa(bool)
        /space/rguenther/src/svn/trunk/gcc/tree-ssa.c:1194
0xd9b5f8 verify_loop_closed_ssa(bool)
        /space/rguenther/src/svn/trunk/gcc/tree-ssa-loop-manip.c:590
0xd9bcd9 gimple_duplicate_loop_to_header_edge(loop*, edge_def*, unsigned int, simple_bitmap_def*, edge_def*, vec<edge_def*, va_heap, vl_ptr>*, int)
        /space/rguenther/src/svn/trunk/gcc/tree-ssa-loop-manip.c:761
0xd9cd38 tree_transform_and_unroll_loop(loop*, unsigned int, edge_def*, tree_niter_desc*, void (*)(loop*, void*), void*)
        /space/rguenther/src/svn/trunk/gcc/tree-ssa-loop-manip.c:1179
0xcf0bc6 tree_predictive_commoning_loop
        /space/rguenther/src/svn/trunk/gcc/tree-predcom.c:2520

gone latent on the trunk for me, still broken on the 4.8 branch.

I will have a look.
Comment 2 Richard Biener 2013-11-18 14:39:38 UTC
Ok, so we are having a combined chain where the combination is in a
conditional path.

Reduced testcase:

SUBROUTINE cal_helicity (uh, ph, phb, wavg, ims, ime, its, ite)
  INTEGER, INTENT( IN ) :: ims, ime, its, ite
  REAL, DIMENSION( ims:ime), INTENT( IN ) :: ph, phb, wavg
  REAL, DIMENSION( ims:ime), INTENT( INOUT ) :: uh
  INTEGER :: i
  REAL :: zu
  DO i = its, ite
    zu =  (ph(i ) + phb(i)) + (ph(i-1) + phb(i-1))
    IF (wavg(i) .GT. 0) THEN
      uh(i) = uh(i) + zu 
    ENDIF
  END DO
END SUBROUTINE cal_helicity

which again fails on trunk as well.
Comment 3 Richard Biener 2013-11-18 15:04:14 UTC
We also fail to sink the loads (because appearantly we don't want to do that, eh),
which in the end causes this havoc (not-always-executed combination).

C testcase:

int x[1024], y[1024], z[1024], w[1024];
void foo (void)
{
  int i;
  for (i = 1; i < 1024; ++i)
    {
      int a = x[i];
      int b = y[i];
      int c = x[i-1];
      int d = y[i-1];
      if (w[i])
        z[i] = (a + b) + (c + d);
    }
}

Fixed by for example the simple

Index: gcc/tree-predcom.c
===================================================================
--- gcc/tree-predcom.c  (revision 204948)
+++ gcc/tree-predcom.c  (working copy)
@@ -2068,7 +2068,11 @@ combinable_refs_p (dref r1, dref r2,
 
   stmt = find_common_use_stmt (&name1, &name2);
 
-  if (!stmt)
+  if (!stmt
+      /* A simple post-dominance check - make sure the combination
+         is executed under the same condition as the references.  */
+      || (gimple_bb (stmt) != gimple_bb (r1->stmt)
+         && gimple_bb (stmt) != gimple_bb (r2->stmt)))
     return false;
 
   acode = gimple_assign_rhs_code (stmt);


Zdenek?
Comment 4 Richard Biener 2013-11-19 09:21:10 UTC
Author: rguenth
Date: Tue Nov 19 09:21:07 2013
New Revision: 205010

URL: http://gcc.gnu.org/viewcvs?rev=205010&root=gcc&view=rev
Log:
2013-11-19  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/57517
	* tree-predcom.c (combinable_refs_p): Verify the combination
	is always executed when the refs are.

	* gfortran.fortran-torture/compile/pr57517.f90: New testcase.
	* gcc.dg/torture/pr57517.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr57517.c
    trunk/gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-predcom.c
Comment 5 Richard Biener 2013-11-19 09:23:54 UTC
Author: rguenth
Date: Tue Nov 19 09:23:52 2013
New Revision: 205012

URL: http://gcc.gnu.org/viewcvs?rev=205012&root=gcc&view=rev
Log:
2013-11-19  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/57517
	* tree-predcom.c (combinable_refs_p): Verify the combination
	is always executed when the refs are.

	* gfortran.fortran-torture/compile/pr57517.f90: New testcase.
	* gcc.dg/torture/pr57517.c: Likewise.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr57517.c
    branches/gcc-4_8-branch/gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-predcom.c
Comment 6 Richard Biener 2013-11-19 09:25:17 UTC
Fixed for trunk and 4.8.3 for now.
Comment 7 Richard Biener 2014-03-18 08:46:53 UTC
Author: rguenth
Date: Tue Mar 18 08:46:21 2014
New Revision: 208632

URL: http://gcc.gnu.org/viewcvs?rev=208632&root=gcc&view=rev
Log:
2014-03-18  Richard Biener  <rguenther@suse.de>
 
	Backport from mainline
	2013-08-27  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/57521
	* tree-if-conv.c (if_convertible_bb_p): Verify that at least
	one edge is non-critical.
	(find_phi_replacement_condition): Make sure to use a non-critical
	edge.  Cleanup and remove old bug workarounds.
	(bb_postdominates_preds): Remove.
	(if_convertible_loop_p_1): Do not compute post-dominators.
	(combine_blocks): Do not free post-dominators.
	(main_tree_if_conversion): Likewise.

	* gcc.dg/torture/pr57521.c: New testcase.

	2013-09-03  Richard Biener  <rguenther@suse.de>

	PR middle-end/57656
	* fold-const.c (negate_expr_p): Fix division case.
	(negate_expr): Likewise.

	* gcc.dg/torture/pr57656.c: New testcase.

	2013-11-19  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/57517
	* tree-predcom.c (combinable_refs_p): Verify the combination
	is always executed when the refs are.

	* gfortran.fortran-torture/compile/pr57517.f90: New testcase.
	* gcc.dg/torture/pr57517.c: Likewise.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/torture/pr57517.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/torture/pr57521.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/torture/pr57656.c
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.fortran-torture/compile/pr57517.f90
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/fold-const.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/tree-if-conv.c
    branches/gcc-4_7-branch/gcc/tree-predcom.c
Comment 8 Richard Biener 2014-03-18 08:47:56 UTC
Fixed.