Bug 36967 - [4.4 Regression] segfault in is_gimple_real_type with -fpredictive-commoning -ffast-math
Summary: [4.4 Regression] segfault in is_gimple_real_type with -fpredictive-commoning ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2008-07-29 21:00 UTC by Janis Johnson
Modified: 2008-07-30 16:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-07-30 14:46:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Janis Johnson 2008-07-29 21:00:52 UTC
After the merge of the tuples branch GCC segfaults on a Fortran benchmark with lots of calculations involving three-dimensional arrays in nested loops.  This testcase reproduces the problem when compiled on powerpc-linux with "-O2 -ffast-math -fpredictive-commoning":

      subroutine foo(x,y,n)
      integer n
      real*8 y(n,n,n),x(n,n,n)
      integer k, j, i
      do k = 2, n-1
        do j = 2, n-1
          do I = 2, n-1
            y(i,j,k) = y(i,j,k)
     +        + (x(i-1,j-1,k)
     +           +  x(i,j-1,k-1)
     +           +  x(i,j+1,k-1)
     +           +  x(i,j+1,k+1)
     +           +  x(i+1,j,k+1))
     +        + (x(i-1,j-1,k-1)
     +           +  x(i+1,j-1,k-1)
     +           +  x(i-1,j+1,k-1)
     +           +  x(i+1,j+1,k-1)
     +           +  x(i-1,j+1,k+1)
     +           +  x(i+1,j+1,k+1))
          enddo
        enddo
      enddo
      return

Here's some of the stack trace:

#0  0x103a60f0 in is_gimple_reg_type (type=0x0)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/gimple.c:2867
#1  0x103a66e8 in is_gimple_val (t=0xf7f152c0)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/gimple.c:2968
#2  0x103a0408 in gimple_assign_copy_p (gs=0xf7eeca40)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/gimple.c:1848
#3  0x106357a4 in remove_stmt (stmt=0xf7ee4880)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-predcom.c:1709
#4  0x10635910 in execute_pred_commoning_chain (loop=0xf7ee6e70, 
    chain=0x10f1edf0, tmp_vars=0x10ef45dc)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-predcom.c:1756
#5  0x10635ce0 in execute_pred_commoning (loop=0xf7ee6e70, chains=0x10f1ef50, 
    tmp_vars=0x10ef45dc)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-predcom.c:1821
#6  0x10636078 in execute_pred_commoning_cbck (loop=0xf7ee6e70, 
    data=0xff8afc30)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-predcom.c:1886
#7  0x107057ec in tree_transform_and_unroll_loop (loop=0xf7ee6e70, factor=2, 
    exit=0xf7ef0600, desc=0xff8afbf8, 
    transform=0x10636024 <execute_pred_commoning_cbck>, data=0xff8afc30)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-ssa-loop-manip.c:1014
#8  0x106398b8 in tree_predictive_commoning_loop (loop=0xf7ee6e70)
    at /home/janis/gcc_trunk_anonsvn/gcc/gcc/tree-predcom.c:2617

Notice that the pointer passed to is_gimple_reg_type is NULL; it's not expecting that.
Comment 1 Andrew Pinski 2008-07-29 21:11:17 UTC
Happens on i386-darwin also.  Note here is a free form testcase (I could not get the fixed form working):
     subroutine foo(x,y,n)
     integer n
     real*8 y(n,n,n),x(n,n,n)
     integer k, j, i
     do k = 2, n-1
       do j = 2, n-1
         do I = 2, n-1
           y(i,j,k) = y(i,j,k) &
&            + (x(i-1,j-1,k) &
&               +  x(i,j-1,k-1) &
&               +  x(i,j+1,k-1) &
&               +  x(i,j+1,k+1) &
&               +  x(i+1,j,k+1)) &
&            + (x(i-1,j-1,k-1) &
&               +  x(i+1,j-1,k-1) &
&               +  x(i-1,j+1,k-1) &
&               +  x(i+1,j+1,k-1) &
&               +  x(i-1,j+1,k+1) &
&               +  x(i+1,j+1,k+1))
         enddo
       enddo
     enddo
end
Comment 2 Richard Biener 2008-07-30 14:46:11 UTC
well...

(gdb) call debug_tree (t)
 <ssa_name 0x7ffff75338c0 nothrow var <var_decl 0x7ffff752faa0 prephitmp.162>def_stmt 

    version 447 in-free-list>

we release the SSA_NAME with remove_phi_node (&psi, true); before then
examining its uses ...

We forget to do so for the other stmts we remove.

An easy way out is to fix the tuplification.
Comment 3 Richard Biener 2008-07-30 15:45:31 UTC
Subject: Bug 36967

Author: rguenth
Date: Wed Jul 30 15:43:42 2008
New Revision: 138318

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138318
Log:
2008-07-30  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/36967
	* tree-predcom.c (remove_stmt): Use gimple_assign_ssa_name_copy_p.
	Release defs of statements we remove.

	* gfortran.dg/pr36967.f: New testcase.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr36967.f
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-predcom.c

Comment 4 Richard Biener 2008-07-30 16:04:12 UTC
Fixed.