User account creation filtered due to spam.

Bug 39999 - [4.4 Regression] gcc 4.4.0 compiles in infinite loop
Summary: [4.4 Regression] gcc 4.4.0 compiles in infinite loop
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.1
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-05-01 22:43 UTC by Jack Howarth
Modified: 2009-05-18 10:14 UTC (History)
4 users (show)

See Also:
Host: *-apple-darwin*
Target: *-apple-darwin*
Build: *-apple-darwin*
Known to work: 4.3.3 4.5.0
Known to fail: 4.4.0
Last reconfirmed: 2009-05-06 13:52:20


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2009-05-01 22:43:15 UTC
The following code...

#include <stdlib.h>
extern int *MMAPMON (int m, int *A);
extern void MMAPREM (int m, int *A, int *B);


int *MMAPGCD(p,A,B)
      int p,*A,*B;
{
      int *A1,*A2,*t,*C,m,n;


      if (((A[-1]) == 0 && (A[0]) == 0)) {
  C = MMAPMON(p,B);
  goto Return; }
      if (((B[-1]) == 0 && (B[0]) == 0)) {
  C = MMAPMON(p,A);
  goto Return; }


      m = (A[-1]);
      n = (B[-1]);
      if (m >= n) {
  A1 = MMAPMON(p,A);
  A2 = MMAPMON(p,B); }
      else {
  A1 = MMAPMON(p,B);
  A2 = MMAPMON(p,A); }
      do {
  MMAPREM(p,A1,A2);
  t = A1;
  A1 = A2;
  A2 = t; }
      while (!((A2[-1]) == 0 && (A2[0]) == 0));
      C = MMAPMON(p,A1);


      free(((A1)-1));
      free(((A2)-1));


Return:
      return(C);
}

hangs the gcc 4.4.0 and gcc-4_4-branch gcc compiler at -O2 when compiled with...

gcc-4 -c foo.c -O2 -Wall -Wextra -Wstrict-prototypes -Wstrict- aliasing=2

The problem is observed on i686-apple-darwin9, x86_64-apple-darwin10 and x86_64-redhat-linux. On x86_64-apple-darwin10, sampling during the hang shows...

Sampling process 30978 for 1 seconds with 1 millisecond of run time between samp
les
Sampling completed, processing symbols...
Analysis of sampling cc1 (pid 30978) every 1 millisecond
Call graph:
    852 Thread_2d07
      852 start
        852 toplev_main
          852 c_write_global_declarations
            852 cgraph_optimize
              852 cgraph_expand_function
                852 tree_rest_of_compilation
                  852 execute_pass_list
                    852 execute_pass_list
                      852 execute_one_pass
                        852 do_pre
                          852 execute_pre
                            850 compute_antic
                              359 phi_translate_set
                                88 sorted_array_from_bitmap_set
                                  76 sorted_array_from_bitmap_set
                                  6 bitmap_bit_p
                                    6 bitmap_bit_p
                                  6 vec_heap_o_reserve_1
                                    6 xrealloc
                                      4 xrealloc
                                      2 malloc
                                        2 malloc_zone_malloc
                                          2 szone_malloc
                                            2 szone_malloc
                                58 bitmap_insert_into_set_1
                                  36 htab_find_slot_with_hash
                                    17 vn_nary_op_eq
                                      11 types_compatible_p
                                        8 useless_type_conversion_p
                                          4 get_alias_set
                                            4 get_alias_set
                                          4 useless_type_conversion_p
                                        3 types_compatible_p
                                      3 expressions_equal_p
                                        3 expressions_equal_p
                                      3 vn_nary_op_eq
                                    15 htab_find_slot_with_hash
                                    4 pre_expr_eq
                                      4 pre_expr_eq
                                  7 bitmap_set_bit
                                    4 bitmap_set_bit
                                    2 bitmap_element_link
                                      2 bitmap_element_link
                                    1 bitmap_element_allocate
                                      1 bitmap_element_allocate
                                  6 bitmap_insert_into_set_1
                                  4 iterative_hash_hashval_t
                                    4 iterative_hash_hashval_t
                                  2 get_expr_value_id
                                    2 get_expr_value_id
                                  2 htab_find_slot
                                    2 pre_expr_hash
                                      2 pre_expr_hash
                                  1 value_id_constant_p
                                    1 bitmap_bit_p
                                      1 bitmap_bit_p
                                54 phi_translate_1
                                  35 htab_find_slot_with_hash
                                    16 htab_find_slot_with_hash
                                    11 vn_nary_op_eq
                                      8 types_compatible_p
                                        6 useless_type_conversion_p
                                          4 useless_type_conversion_p
                                          2 get_alias_set
                                            2 get_alias_set
                                        2 types_compatible_p
                                      2 vn_nary_op_eq
                                      1 expressions_equal_p
                                        1 expressions_equal_p
                                    7 pre_expr_eq
                                      7 pre_expr_eq
                                    1 expr_pred_trans_eq
                                      1 expr_pred_trans_eq
                                  10 get_expr_value_id
                                    8 get_expr_value_id
                                    2 VN_INFO
                                      2 VN_INFO
                                  6 phi_translate_1
                                  1 expr_pred_trans_eq
                                    1 expr_pred_trans_eq
                                  1 pre_expr_hash
                                    1 pre_expr_hash
                                  1 value_id_constant_p
                                    1 bitmap_bit_p
                                      1 bitmap_bit_p
                                42 htab_find_slot_with_hash
                                  20 htab_find_slot_with_hash
                                  17 vn_nary_op_eq
                                    12 types_compatible_p
                                      9 useless_type_conversion_p
                                        6 useless_type_conversion_p
                                        3 get_alias_set
                                          3 get_alias_set
                                      3 types_compatible_p
                                    3 vn_nary_op_eq
                                    2 expressions_equal_p
                                      2 expressions_equal_p
                                  3 expr_pred_trans_eq
                                    3 expr_pred_trans_eq
                                  2 pre_expr_eq
                                    2 pre_expr_eq
                                27 xmalloc
                                  23 malloc
                                    21 malloc_zone_malloc
                                      18 szone_malloc
                                        10 tiny_malloc_from_free_list
                                          10 tiny_malloc_from_free_list
                                        8 szone_malloc
                                      3 malloc_zone_malloc
                                    2 malloc
                                  4 xmalloc
                                22 bitmap_value_insert_into_set
                                  13 bitmap_set_contains_value
                                    6 bitmap_set_contains_value
                                    4 bitmap_bit_p
                                      4 bitmap_bit_p
                                    3 value_id_constant_p
                                      2 value_id_constant_p
                                      1 bitmap_bit_p
                                        1 bitmap_bit_p
                                  4 get_expr_value_id
                                    2 VN_INFO
                                      2 VN_INFO
                                    2 get_expr_value_id
                                  3 bitmap_value_insert_into_set
                                  2 value_id_constant_p
                                    1 bitmap_bit_p
                                      1 bitmap_bit_p
                                    1 value_id_constant_p
                                22 szone_free
                                  22 szone_free
                                13 iterative_hash_hashval_t
                                  13 iterative_hash_hashval_t
                                7 phi_translate_set
                                5 free
                                  5 free
                                5 phi_translate
                                  3 phi_translate
                                  2 bitmap_clear
                                    2 bitmap_clear
                                4 pre_expr_hash
                                  4 pre_expr_hash
                                3 malloc_zone_free
                                  3 malloc_zone_free
                                2 bitmap_bit_p
                                  2 bitmap_bit_p
                                2 bitmap_set_bit
                                  1 bitmap_element_allocate
                                    1 bitmap_element_allocate
                                  1 bitmap_set_bit
                                2 dyld_stub_malloc
                                  2 dyld_stub_malloc
                                1 expr_pred_trans_eq
                                  1 expr_pred_trans_eq
                                1 htab_find_slot
                                  1 htab_find_slot
                                1 vec_heap_o_reserve_1
                                  1 vec_heap_o_reserve_1
                              110 sorted_array_from_bitmap_set
                                84 sorted_array_from_bitmap_set
                                18 vec_heap_o_reserve_1
                                  16 xrealloc
                                    12 malloc
                                      11 malloc_zone_malloc
                                        10 szone_malloc
                                          5 szone_malloc
                                          5 tiny_malloc_from_free_list
                                            5 tiny_malloc_from_free_list
                                        1 malloc_zone_malloc
                                      1 malloc
                                    4 realloc
                                      4 malloc_zone_realloc
                                        3 szone_realloc
                                          2 __memcpy
                                            2 __memcpy
                                          1 szone_malloc
                                            1 szone_malloc
                                        1 memcpy
                                          1 memcpy
                                  1 dyld_stub_malloc
                                    1 dyld_stub_malloc
                                  1 vec_heap_o_reserve_1
                                8 bitmap_bit_p
                                  8 bitmap_bit_p
                              76 bitmap_set_subtract
                                23 bitmap_set_new
                                  12 bitmap_set_new
                                  6 bitmap_obstack_alloc_stat
                                    6 bitmap_obstack_alloc_stat
                                  5 pool_alloc
                                    4 pool_alloc
                                    1 xmalloc
                                      1 malloc
                                        1 malloc_zone_malloc
                                          1 szone_malloc
                                            1 tiny_malloc_from_region_no_lock
                                              1 allocate_pages
                                                1 __mmap
                                                  1 __mmap
                                22 bitmap_set_subtract
                                12 bitmap_and_compl
                                  10 bitmap_and_compl
                                  2 bitmap_elt_insert_after
                                    2 bitmap_elt_insert_after
                                10 get_expr_value_id
                                  6 get_expr_value_id
                                  4 VN_INFO
                                    4 VN_INFO
                                9 bitmap_set_bit
                                  6 bitmap_set_bit
                                  2 bitmap_element_allocate
                                    2 bitmap_element_allocate
                                  1 bitmap_element_link
                                    1 bitmap_element_link
                              65 bitmap_insert_into_set_1
                                36 htab_find_slot_with_hash
                                  20 vn_nary_op_eq
                                    16 types_compatible_p
                                      13 useless_type_conversion_p
                                        9 get_alias_set
                                          9 get_alias_set
                                        4 useless_type_conversion_p
                                      3 types_compatible_p
                                    4 vn_nary_op_eq
                                  11 htab_find_slot_with_hash
                                  5 pre_expr_eq
                                    5 pre_expr_eq
                                8 bitmap_set_bit
                                  6 bitmap_set_bit
                                  1 bitmap_element_allocate
                                    1 bitmap_element_allocate
                                  1 bitmap_element_link
                                    1 bitmap_element_link
                                5 bitmap_insert_into_set_1
                                5 get_expr_value_id
                                  4 get_expr_value_id
                                  1 VN_INFO
                                    1 VN_INFO
                                5 htab_find_slot
                                  2 htab_find_slot
                                  2 pre_expr_hash
                                    2 pre_expr_hash
                                  1 iterative_hash_hashval_t
                                    1 iterative_hash_hashval_t
                                3 iterative_hash_hashval_t
                                  3 iterative_hash_hashval_t
                                3 value_id_constant_p
                                  2 value_id_constant_p
                                  1 bitmap_bit_p
                                    1 bitmap_bit_p
                              56 compute_antic
                              42 valid_in_sets
                                15 valid_in_sets
                                10 htab_find_slot_with_hash
                                  9 htab_find_slot_with_hash
                                  1 pre_expr_eq
                                    1 pre_expr_eq
                                7 bitmap_set_contains_value
                                  5 bitmap_set_contains_value
                                  1 bitmap_bit_p
                                    1 bitmap_bit_p
                                  1 value_id_constant_p
                                    1 value_id_constant_p
                                5 iterative_hash_hashval_t
                                  5 iterative_hash_hashval_t
                                3 bitmap_bit_p
                                  3 bitmap_bit_p
                                2 htab_find_slot
                                  2 iterative_hash_hashval_t
                                    2 iterative_hash_hashval_t
                              27 bitmap_value_insert_into_set
                                10 bitmap_set_contains_value
                                  6 bitmap_set_contains_value
                                  2 bitmap_bit_p
                                    2 bitmap_bit_p
                                  2 value_id_constant_p
                                    2 bitmap_bit_p
                                      2 bitmap_bit_p
                                7 get_expr_value_id
                                  7 get_expr_value_id
                                6 bitmap_value_insert_into_set
                                2 value_id_constant_p
                                  2 bitmap_bit_p
                                    2 bitmap_bit_p
                                1 VN_INFO
                                  1 VN_INFO
                                1 bitmap_bit_p
                                  1 bitmap_bit_p
                              25 szone_free
                                17 szone_free
                                8 tiny_free_list_add_ptr
                                  8 tiny_free_list_add_ptr
                              21 iterative_hash_hashval_t
                                21 iterative_hash_hashval_t
                              16 bitmap_set_free
                                12 bitmap_obstack_free
                                  10 bitmap_elt_clear_from
                                    10 bitmap_elt_clear_from
                                  2 bitmap_obstack_free
                                4 bitmap_set_free
                              14 bitmap_set_new
                                7 bitmap_set_new
                                5 bitmap_obstack_alloc_stat
                                  5 bitmap_obstack_alloc_stat
                                2 pool_alloc
                                  2 pool_alloc
                              10 bitmap_set_and
                                8 bitmap_set_and
                                1 bitmap_bit_p
                                  1 bitmap_bit_p
                                1 bitmap_copy
                                  1 bitmap_copy
                              9 bitmap_set_bit
                                6 bitmap_set_bit
                                2 bitmap_element_link
                                  2 bitmap_element_link
                                1 bitmap_element_allocate
                                  1 bitmap_element_allocate
                              7 bitmap_remove_from_set
                                4 bitmap_clear_bit
                                  4 bitmap_clear_bit
                                2 bitmap_remove_from_set
                                1 get_expr_value_id
                                  1 get_expr_value_id
                              5 free
                                5 free
                              2 bitmap_copy
                                2 bitmap_copy
                              2 vec_heap_o_reserve_1
                                2 xrealloc
                                  2 malloc
                                    1 malloc
                                    1 malloc_zone_malloc
                                      1 szone_malloc
                                        1 szone_malloc
                              1 bitmap_equal_p
                                1 bitmap_equal_p
                              1 dyld_stub_malloc_zone_free
                                1 dyld_stub_malloc_zone_free
                              1 malloc_zone_free
                                1 malloc_zone_free
                              1 vec_heap_p_reserve
                                1 vec_heap_p_reserve
                            1 bitmap_insert_into_set_1
                              1 bitmap_insert_into_set_1
                            1 dyld_stub_free
                              1 dyld_stub_free

Total number in stack (recursive counted multiple, when >=5):
        16       bitmap_bit_p
        8       value_id_constant_p
        7       get_expr_value_id
        7       iterative_hash_hashval_t
        6       szone_malloc
        5       VN_INFO
        5       bitmap_element_allocate
        5       bitmap_set_bit
        5       htab_find_slot_with_hash
        5       malloc
        5       malloc_zone_malloc
        5       pre_expr_eq

Sort by top of stack, same collapsed (when >= 5):
        sorted_array_from_bitmap_set        160
        htab_find_slot_with_hash        71
        compute_antic        56
        iterative_hash_hashval_t        49
        szone_free        39
        bitmap_bit_p        37
        get_expr_value_id        30
        bitmap_set_bit        23
        bitmap_set_subtract        22
        bitmap_set_new        19
        pre_expr_eq        19
        get_alias_set        18
        useless_type_conversion_p        18
        bitmap_set_contains_value        17
        szone_malloc        17
        tiny_malloc_from_free_list        15
        valid_in_sets        15
        bitmap_insert_into_set_1        12
        vn_nary_op_eq        12
        bitmap_obstack_alloc_stat        11
        types_compatible_p        11
        VN_INFO        10
        bitmap_and_compl        10
        bitmap_elt_clear_from        10
        free        10
        bitmap_value_insert_into_set        9
        pre_expr_hash        9
        bitmap_set_and        8
        tiny_free_list_add_ptr        8
        phi_translate_set        7
        bitmap_element_allocate        6
        bitmap_element_link        6
        expr_pred_trans_eq        6
        expressions_equal_p        6
        phi_translate_1        6
        pool_alloc        6
        value_id_constant_p        6
Sample analysis of process 30978 written to file /dev/stdout
Comment 1 Andrew Pinski 2009-05-01 22:49:26 UTC
So GCC hangs and not the compiled code?
Comment 2 Jack Howarth 2009-05-01 23:00:28 UTC
On Linux and Darwin, it seems to be constantly allocating memory and never finishes the compilation (at least over 10+ minutes). The example code compiles instantly at -O1. I've not discovered any -O2 switches that can be disabled which would eliminate the problem.
Comment 3 Richard Biener 2009-05-02 10:19:57 UTC
Confirmed.  I hit

#ifdef ENABLE_CHECKING
      /* Theoretically possible, but *highly* unlikely.  */
      gcc_assert (num_iterations < 500);
#endif

on trunk.

We seem to oscillate

....
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A1_1,-4} (0026), {pointer_plus_expr,A2_2,-4} (0046) }
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A2_2,-4} (0025), {pointer_plus_expr,A2_2,-4} (0046) }
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A1_1,-4} (0026), {pointer_plus_expr,A2_2,-4} (0046) }
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A2_2,-4} (0025), {pointer_plus_expr,A2_2,-4} (0046) }
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A1_1,-4} (0026), {pointer_plus_expr,A2_2,-4} (0046) }
ANTIC_IN[12] := { A1_1 (0001), A2_2 (0002), {pointer_plus_expr,A2_2,-4} (0025), {pointer_plus_expr,A2_2,-4} (0046) }

Maybe we get confused by the degenerate PHIs

<bb 22>:

<bb 14>:
  # A1_17 = PHI <A1_1(22)>
  # A2_18 = PHI <A2_2(22)>
  C_29 = MMAPMON (p_8(D), A2_18);
  D.1783_30 = A2_18 + -4;
  free (D.1783_30);
  D.1784_31 = A1_17 + -4;
Comment 4 Richard Biener 2009-05-06 13:24:40 UTC
Reduced testcase:

void foo(void *);
void
MMAPGCD (int *A1, int *A2)
{
  int *t; 

  do
    {
      t = A1;
      A1 = A2;
      A2 = t;
    }
  while (A2[-1]);

  foo (A1-1);
  foo (A2-1);
}   

if you make foo take int * the issue goes away.
Comment 5 Richard Biener 2009-05-06 13:52:20 UTC
Ok, I know what happens.
Comment 6 Richard Biener 2009-05-15 13:10:11 UTC
Subject: Bug 39999

Author: rguenth
Date: Fri May 15 13:09:53 2009
New Revision: 147573

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147573
Log:
2009-05-15  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/39999
	* gimple.h (gimple_expr_type): Use the expression type looking
	through useless conversions.
	* tree-ssa-sccvn.c (vn_nary_op_lookup_stmt): Use gimple_expr_type.
	(vn_nary_op_insert_stmt): Likewise.
	(simplify_binary_expression): Likewise.

	* gcc.c-torture/compile/pr39999.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr39999.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-sccvn.c

Comment 7 Richard Biener 2009-05-15 13:10:17 UTC
Fixed on the trunk.
Comment 8 Jack Howarth 2009-05-15 13:37:57 UTC
Will this fix be backported for gcc 4.4.1?
Comment 9 rguenther@suse.de 2009-05-15 13:47:42 UTC
Subject: Re:  [4.4 Regression] gcc 4.4.0 compiles
 in infinite loop

On Fri, 15 May 2009, howarth at nitro dot med dot uc dot edu wrote:

> ------- Comment #8 from howarth at nitro dot med dot uc dot edu  2009-05-15 13:37 -------
> Will this fix be backported for gcc 4.4.1?

Yes, I will wait a few days to spot problems though.

Richard.
Comment 10 Richard Biener 2009-05-18 10:13:55 UTC
Subject: Bug 39999

Author: rguenth
Date: Mon May 18 10:13:43 2009
New Revision: 147657

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147657
Log:
2009-05-18  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/39999
	* gimple.h (gimple_expr_type): Use the expression type looking
	through useless conversions.
	* tree-ssa-sccvn.c (vn_nary_op_lookup_stmt): Use gimple_expr_type.
	(vn_nary_op_insert_stmt): Likewise.
	(simplify_binary_expression): Likewise.

	* gcc.c-torture/compile/pr39999.c: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr39999.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/gimple.h
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/tree-ssa-sccvn.c

Comment 11 Richard Biener 2009-05-18 10:14:15 UTC
Fixed.