Bug 36129 - [4.3 Regression] ICE with -fprofile-use
Summary: [4.3 Regression] ICE with -fprofile-use
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch
Depends on:
Blocks: 29975
  Show dependency treegraph
 
Reported: 2008-05-05 10:30 UTC by Joost VandeVondele
Modified: 2008-05-11 18:56 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-05-09 14:17:16


Attachments
files (.f .gcda .mod) needed to reproduce the ICE and a README (131.47 KB, application/x-compressed-tar)
2008-05-06 09:29 UTC, Joost VandeVondele
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2008-05-05 10:30:29 UTC
current CP2K CVS fails to compile with [trunk revision 134945]

/data03/vondele/clean/cp2k/src/../src/atomic_kind_types.F: In function ‘read_atomic_kind’:
/data03/vondele/clean/cp2k/src/../src/atomic_kind_types.F:1158: error: Dead histogram
IOR value ior:0.
__builtin_memset (&element_symbol[2]{lb: 1 sz: 1}, 32, 1);

/data03/vondele/clean/cp2k/src/../src/atomic_kind_types.F:1158: internal compiler error: verify_h                                         istograms failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

when compiled with command line:

gfortran -c -fprofile-use -O3 -ffast-math -funroll-loops -ftree-vectorize -march=native -ffree-form -D__GFORTRAN -D__FFTSG  -D__COMPILE_ARCH="\"Linux-x86-64-gfortran\"" -D__COMPILE_DATE="\"Mon May  5 12:27:17 CEST 2008\"" -D__COMPILE_HOST="\"pcihopt3\"" -D__COMPILE_LASTCVS="\"/qs_integrate_potential.F/1.136/Fri May  2 13:45:49 2008//\"" /data03/vondele/clean/cp2k/src/../src/atomic_kind_types.F

what is the best way to get this to a reasonable testcase?
Comment 1 Joost VandeVondele 2008-05-05 12:29:04 UTC
at least a back trace, but I guess that is not very useful:

#0  internal_error (gmsgid=0xc34369 "verify_histograms failed") at /data03/vondele/gcc_trunk/gcc/gcc/diagnostic.c:594
#1  0x00000000008c949d in verify_histograms () at /data03/vondele/gcc_trunk/gcc/gcc/value-prof.c:393
#2  0x0000000000701aab in verify_stmts () at /data03/vondele/gcc_trunk/gcc/gcc/tree-cfg.c:4411
#3  0x00000000008531a9 in verify_ssa (check_modified_stmt=1 '\001') at /data03/vondele/gcc_trunk/gcc/gcc/tree-ssa.c:732
#4  0x000000000067886d in execute_function_todo (data=<value optimized out>) at /data03/vondele/gcc_trunk/gcc/gcc/passes.c:970
#5  0x0000000000678a4f in execute_todo (flags=3919132792) at /data03/vondele/gcc_trunk/gcc/gcc/passes.c:996
#6  0x0000000000678de1 in execute_one_pass (pass=0xf09780) at /data03/vondele/gcc_trunk/gcc/gcc/passes.c:1276
#7  0x0000000000678fc5 in execute_pass_list (pass=0xf09780) at /data03/vondele/gcc_trunk/gcc/gcc/passes.c:1304
#8  0x0000000000678fdd in execute_pass_list (pass=0xf090c0) at /data03/vondele/gcc_trunk/gcc/gcc/passes.c:1305
#9  0x0000000000763d26 in tree_rest_of_compilation (fndecl=0x2b40e9c56c30) at /data03/vondele/gcc_trunk/gcc/gcc/tree-optimize.c:420
#10 0x0000000000916f82 in cgraph_expand_function (node=0x2b40e9d83000) at /data03/vondele/gcc_trunk/gcc/gcc/cgraphunit.c:1157
#11 0x0000000000919934 in cgraph_optimize () at /data03/vondele/gcc_trunk/gcc/gcc/cgraphunit.c:1220
#12 0x0000000000483855 in gfc_be_parse_file (set_yydebug=<value optimized out>) at /data03/vondele/gcc_trunk/gcc/gcc/fortran/f95-lang.c:262
Comment 2 Joost VandeVondele 2008-05-05 13:11:35 UTC
also happens if profiles are generated/used at -O2 instead of -O3
Comment 3 Joost VandeVondele 2008-05-06 09:29:27 UTC
Created attachment 15585 [details]
files (.f .gcda .mod) needed to reproduce the ICE and a README

attached the files needed to trigger the verify_histograms ICE, plus a README with the exact command used to do so
Comment 4 Joost VandeVondele 2008-05-06 12:08:39 UTC
older gcc versions (tested 4.2.3 and 4.3.0) seem to work fine
Comment 5 Uroš Bizjak 2008-05-09 09:12:20 UTC
Probably duplicate of or at least related to PR35215 ?
Comment 6 Uroš Bizjak 2008-05-09 11:13:08 UTC
Something interesting:

In atomic_kind_types.F.085t.copyprop3, we have:

<bb 76>:
  D.2711_888 = *atomic_kind_38(D);
  D.2731_889 = &D.2711_888->element_symbol[1]{lb: 1 sz: 1};
  __builtin_memcpy (&element_symbol[1]{lb: 1 sz: 1}, D.2731_889, 1);
  __builtin_memset (&element_symbol[2]{lb: 1 sz: 1}, 32, 1);IOR value ior:0.
Average value sum:0 times:0.

  goto <bb 78>;

and in atomic_kind_types.F.086.fab, we have:

<bb 75>:
  D.2711_885 = *atomic_kind_38(D);
  D.2731_886 = &D.2711_885->element_symbol[1]{lb: 1 sz: 1};
  __builtin_memmove (&element_symbol[1]{lb: 1 sz: 1}, D.2731_886, 2);
  goto <bb 78>;


As can be seen, "__builtin_memset (&element_symbol[2]{lb: 1 sz: 1}, 32, 1)" expression that troubles us just vanished, apparently leaving dead histogram behind.
Comment 7 Uroš Bizjak 2008-05-09 11:18:19 UTC
-fdump-tree-fab-details:

;; Function read_atomic_kind (__atomic_kind_types_MOD_read_atomic_kind)

Simplified
  __builtin_memset (&element_symbol[2]{lb: 1 sz: 1}, 32, 1);
to
  (void) 0;
Comment 8 Uroš Bizjak 2008-05-09 11:48:17 UTC
Patch in testing:

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 135108)
+++ tree-ssa-ccp.c	(working copy)
@@ -2916,6 +2916,9 @@ execute_fold_all_builtins (void)
 		continue;
 	      }
 
+	  if (result)
+	    gimple_remove_stmt_histograms (cfun, *stmtp);
+
 	  if (dump_file && (dump_flags & TDF_DETAILS))
 	    {
 	      fprintf (dump_file, "Simplified\n  ");
Comment 9 Uroš Bizjak 2008-05-09 11:50:19 UTC
*** Bug 35215 has been marked as a duplicate of this bug. ***
Comment 10 Uroš Bizjak 2008-05-09 11:54:27 UTC
The same problem is on 4.3 branch, as confirmed by the dupe.
Comment 11 Uroš Bizjak 2008-05-09 14:17:15 UTC
Patch at http://gcc.gnu.org/ml/gcc-patches/2008-05/msg00562.html.
Comment 12 uros 2008-05-09 18:21:52 UTC
Subject: Bug 36129

Author: uros
Date: Fri May  9 18:21:05 2008
New Revision: 135123

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135123
Log:
        PR tree-optimization/36129
        * tree-ssa-cpp.c: Include value-prof.h.
        (execute_fold_all_builtins): Call gimple_remove_stmt_histograms if
        built-in function was folded to a constant.
        * Makefile.in (tree-ssa-cpp.c): Depend on value-prof.h


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/tree-ssa-ccp.c

Comment 13 Uroš Bizjak 2008-05-09 18:25:30 UTC
Fixed for 4.4, patch needs to be backported to 4.3 branch.
Comment 14 Joost VandeVondele 2008-05-10 08:46:25 UTC
(In reply to comment #13)
> Fixed for 4.4, patch needs to be backported to 4.3 branch.
> 

thanks for the patch, testing it, I ran into another ICE (PR36198) before reaching the crucial point.
Comment 15 uros 2008-05-11 18:54:59 UTC
Subject: Bug 36129

Author: uros
Date: Sun May 11 18:54:15 2008
New Revision: 135180

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135180
Log:
        Backport from mainline:
        2008-05-09  Uros Bizjak  <ubizjak@gmail.com>

        PR tree-optimization/36129
        * tree-ssa-ccp.c: Include value-prof.h.
        (execute_fold_all_builtins): Call gimple_remove_stmt_histograms if
        built-in function was folded to a constant.
        * Makefile.in (tree-ssa-ccp.c): Depend on value-prof.h


Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/Makefile.in
    branches/gcc-4_3-branch/gcc/tree-ssa-ccp.c

Comment 16 Uroš Bizjak 2008-05-11 18:56:41 UTC
Fixed.